You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm making a website with HTML5 ajax navigation (dynamically changing page url and just replacing body content).
Therefore is the need to dynamically unload previous page styles and load new page styles.
Here is a working piece of code I'm using on my website.
It would be nice if you included something like this in your Less.js, so that we wouldn't need to hack into it again when newer versions are released.
I'm not making a pull request since this code extensively uses jQuery and I doubt that you'd like jQuery in your repo.
You may just rewrite this code the way you like it and include in the distribution.
/** Less custom changes begin */window.Less={}varLess=window.LessLess.id=function(link){link=encodeURI(link)link=link.replace(/\?.*$/,'')returnget_sheet_id('',link)}functionget_sheet_id(title,href){return'less:'+(title||extractId(href))}Less.unload_style=function(link){varhead=$('head')head.find('style[id="'+Less.id(link)+'"]').remove()head.find('link[href="'+link+'"]').remove()}Less.load_style=function(link,callback){varstyle_element=$('head').find('link[href="'+link+'"]')// loadStyleSheet(sheet, callback, reload, remaining)// callback(error, root, data, sheet, { local: false, lastModified: lastModified, remaining: remaining });varinternal_callback=function(error,parsed_document,data,sheet,info){if(parsed_document)createCSS(parsed_document.toCSS(),sheet,info.lastModified)callback()}loadStyleSheet(style_element[0],internal_callback,false,0)}/** Less custom changes end */
Btw, should not we close this then? (Assuming Less is not a stylesheets manipulation library it's barely to include methods like above, and #2233 fixes this considering you load/unload stylesheets by whatever suitable methods externally (e.g. using jQuery)).
Activity
levithomason commentedon Oct 16, 2014
Fixed in #2233. Please move any further conversation to that PR.
Fixes less#713, less#771, less#1161
seven-phases-max commentedon Oct 22, 2014
Btw, should not we close this then? (Assuming Less is not a stylesheets manipulation library it's barely to include methods like above, and #2233 fixes this considering you load/unload stylesheets by whatever suitable methods externally (e.g. using jQuery)).
levithomason commentedon Oct 22, 2014
Agree, this is solved.