syntax-highlighting
Version:
Syntax Highlighting Colorschemes for many applications
3 lines (2 loc) • 3.1 kB
JavaScript
(function($){$.scoped=function(){if("scoped"in document.createElement("style"))return;var styleSettable=true;try{document.createElement("div").style.setProperty("opacity",0,"")}catch(error){styleSettable=false}scopedReset();backupBlocks();var $style=$("style");$style.each(function(index){var $this=$(this);if(isScoped($this)){$this.addClass("this_is_"+index);$this.parent().find("style").each(function(){$(this).addClass("depends_on_"+index)})}});$style.each(function(){var $this=$(this);if(isScoped($this)){emptyBlocks($this);var holdingArea=[];var $parent=$this.parent(),$all=$parent.find("*");$all.add($parent).each(function(){$(this).css("cssText","");if(this.nodeName!=="STYLE")holdingArea.push(getStylesText(this))});$all.add($parent).each(function(){var this_style,n;if(this.nodeName!=="STYLE"){if(!$(this).data("originalInline"))$(this).data("originalInline",$(this).attr("style"));this_style=holdingArea.shift();if(typeof this_style==="string")$(this).css("cssText",this_style);else if(styleSettable)for(n in this_style){if(n!=="content"||this_style[n]!=="none")try{this.style.setProperty(n,this_style[n])}catch(err){}}else for(n in this_style)try{if(this&&this.style&&n&&this_style[n]&&n!==""&&this_style[n]!=="")this.style[n]=this_style[n]}catch(err){}}});fillBlocks()}});$("style").each(function(i,e){if(isScoped(e))try{e.innerHTML=""}catch(error){$(e).attr("disabled","disabled")}});function isScoped(styleBlock){return $(styleBlock).attr("scoped")!==undefined}function backupBlocks(){$("style").each(function(i,e){if(isScoped(e)){var $e=$(e);$e.data("original-style",$e.html())}})}function emptyBlocks(currentBlock){$("style").each(function(i,e){if(isScoped(e))if(!currentBlock.hasClass("depends_on_"+i))try{e.innerHTML=""}catch(error){$(e).attr("disabled","disabled")}})}function fillBlocks(){$("style").each(function(i,e){var $e=$(e);if(isScoped(e))try{e.innerHTML=$e.data("original-style")}catch(error){$(this).removeAttr("disabled")}})}function getStylesText(element){var temp,styles,n,key;if(element.currentStyle){sleep(50);return element.currentStyle}temp=
document.defaultView.getComputedStyle(element,null);styles="";for(n in temp)if(parseInt(n,10)){key=camelize(temp[n]);if(temp[key]!==undefined)styles+=temp[n]+":"+temp[key]+";\n"}return styles}function scopedReset(){var $style=$("style");$style.each(function(i,styleBlock){var $styleBlock=$(styleBlock);var $parent=$(this).parent(),$all=$parent.find("*");$all.add($parent).each(function(){var $this=$(this);if(this.nodeName!=="STYLE")if($this.data("scopedprocessed")){$this.attr("style",$this.data("originalInline")||"");$this.data("scopedprocessed",true)}});if($styleBlock.attr("scoped")!==undefined){try{if($styleBlock.data("scopedprocessed"))this.innerHTML=$styleBlock.data("original-style")}catch(error){$styleBlock.removeAttr("disabled")}$styleBlock.data("scopedprocessed",true)}})}function camelize(string){return string.replace(/-+(.)?/g,function(match,chr){return chr?chr.toUpperCase():""})}function sleep(ms){var dt=new Date;dt.setTime(dt.getTime()+ms);while((new Date).getTime()<dt.getTime())$.noop()}}})(jQuery);