From: Tim Wood Date: Mon, 17 Oct 2011 23:47:19 +0000 (-0700) Subject: Adding syntax highlighting to the docs. X-Git-Tag: 1.0.1~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc711fe1f5176c091929ef534a6d2830bf2ca03f;p=thirdparty%2Fmoment.git Adding syntax highlighting to the docs. --- diff --git a/build.js b/build.js index 1e1bce9c3..614858f0d 100755 --- a/build.js +++ b/build.js @@ -162,4 +162,16 @@ function hint(source, name) { gzip(source, function(err, data) { console.log('size : ./moment.js ' + source.length + ' b (' + data.length + ' b)'); }); +})(); + + +/********************************************* + Docs +*********************************************/ + + +(function(){ + var snippet = fs.readFileSync('./docs/snippet.js', 'utf8'); + var docs = fs.readFileSync('./docs/docs.js', 'utf8'); + minifyToFile(snippet + docs, 'docs/docs'); })(); \ No newline at end of file diff --git a/docs/docs.js b/docs/docs.js new file mode 100755 index 000000000..e866f3605 --- /dev/null +++ b/docs/docs.js @@ -0,0 +1 @@ +$("pre").snippet("javascript", {style:"typical",showNum:false}); \ No newline at end of file diff --git a/docs/docs.min.js b/docs/docs.min.js new file mode 100644 index 000000000..81612b6a7 --- /dev/null +++ b/docs/docs.min.js @@ -0,0 +1 @@ +function snippetPopup(a){top.consoleRef=window.open("","myconsole","width=600,height=300,left=50,top=50,menubar=0,toolbar=0,location=0,status=0,scrollbars=1,resizable=1"),top.consoleRef.document.writeln("Snippet :: Code View :: "+location.href+""+''+"
"+a+"
"+""),top.consoleRef.document.close()}function sh_isEmailAddress(a){return/^mailto:/.test(a)?!1:a.indexOf("@")!==-1}function sh_setHref(a,b,c){var d=c.substring(a[b-2].pos,a[b-1].pos);d.length>=2&&d.charAt(0)==="<"&&d.charAt(d.length-1)===">"&&(d=d.substr(1,d.length-2)),sh_isEmailAddress(d)&&(d="mailto:"+d),a[b-2].node.href=d}function sh_konquerorExec(a){var b=[""];return b.index=a.length,b.input=a,b}function sh_highlightString(a,b){if(/Konqueror/.test(navigator.userAgent)&&!b.konquered){for(var c=0;cv&&m(t.substring(v,B.index),null);var G=y[C],H=G[1],I;if(H instanceof Array)for(var J=0;J0){var d=c.split(" ");for(var e=0;e0&&b.push(d[e])}return b}function sh_addClass(a,b){var c=sh_getClasses(a);for(var d=0;d element with class="'+g+'", but no such language exists');continue}break}}}(function(a){window.log=function(){log.history=log.history||[],log.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments))},a.fn.snippet=function(b,c){typeof b=="object"&&(c=b),typeof b=="string"&&(b=b.toLowerCase());var d={style:"random",showNum:!0,transparent:!1,collapse:!1,menu:!0,showMsg:"Expand Code",hideMsg:"Collapse Code",clipboard:"",startCollapsed:!0,startText:!1,box:"",boxColor:"",boxFill:""},e=["acid","berries-dark","berries-light","bipolar","blacknblue","bright","contrast","darkblue","darkness","desert","dull","easter","emacs","golden","greenlcd","ide-anjuta","ide-codewarrior","ide-devcpp","ide-eclipse","ide-kdev","ide-msvcpp","kwrite","matlab","navy","nedit","neon","night","pablo","peachpuff","print","rand01","the","typical","vampire","vim","vim-dark","whatis","whitengrey","zellner"];return c&&a.extend(d,c),this.each(function(){var c=d.style.toLowerCase();if(d.style=="random"){var f=Math.floor(Math.random()*e.length);c=e[f]}var g=a(this),h=this.nodeName.toLowerCase();if(h!="pre"){var l="Snippet Error: Sorry, Snippet only formats '
' elements. '<"+h+">' elements are currently unsupported.";return console.log(l),!1}if(g.data("orgHtml")==undefined||g.data("orgHtml")==null){var i=g.html();g.data("orgHtml",i)}if(!g.parent().hasClass("snippet-wrap")){if(typeof b!="string"){if(g.attr("class").length>0)var j=' class="'+g.attr("class")+'"';else var j="";if(g.attr("id").length>0)var k=' id="'+g.attr("id")+'"';else var k="";var l="Snippet Error: You must specify a language on inital usage of Snippet. Reference ";return console.log(l),!1}g.addClass("sh_"+b).addClass("snippet-formatted").wrap("
"),g.removeAttr("style"),sh_highlightDocument();if(d.showNum){var m=g.html();m=m.replace(/\n/g,"
  • "),m="
    1. "+m+"
    ";while(m.indexOf("
  • ")!=-1)m=m.replace("
  • ","")}else{var m=g.html();m=m.replace(/\n/g,"
  • "),m="
    • "+m+"
    ";while(m.indexOf("
  • ")!=-1)m=m.replace("
  • ","")}m=m.replace(/\t/g,"    "),g.html(m);while(g.find("li").eq(0).html()=="")g.find("li").eq(0).remove();g.find("li").each(function(){if(a(this).html().length<2){var b=a(this).html().replace(/\s/g,"");b==""&&(a.browser.opera?a(this).html(" "):a(this).html(" "))}});var n="",o="";g.parent().append(n),g.parent().prepend(o),g.parent().hover(function(){a(this).find(".snippet-menu").fadeIn("fast")},function(){a(this).find(".snippet-menu").fadeOut("fast")});if(d.clipboard!=""&&d.clipboard!=0){var p=g.parent().find("a.snippet-copy");p.show(),p.parents(".snippet-menu").show();var q=g.parents(".snippet-wrap").find(".snippet-textonly").text();ZeroClipboard.setMoviePath(d.clipboard);var r=new ZeroClipboard.Client;r.setText(q),r.glue(p[0],p.parents(".snippet-menu")[0]),r.addEventListener("complete",function(a,b){b.length>500&&(b=b.substr(0,500)+"...\n\n("+(b.length-500)+" characters not shown)"),alert("Copied text to clipboard:\n\n "+b)}),p.parents(".snippet-menu").hide()}else g.parent().find("a.snippet-copy").hide();g.parent().find("a.snippet-text").click(function(){var b=a(this).parents(".snippet-wrap").find(".snippet-formatted"),c=a(this).parents(".snippet-wrap").find(".snippet-textonly");return b.toggle(),c.toggle(),c.is(":visible")?a(this).html("html"):a(this).html("text"),a(this).blur(),!1}),g.parent().find("a.snippet-window").click(function(){var b=a(this).parents(".snippet-wrap").find(".snippet-textonly").html();return snippetPopup(b),a(this).blur(),!1}),d.menu||g.prev(".snippet-menu").find("pre,.snippet-clipboard").hide();if(d.collapse){var s=g.parent().attr("class"),t="",u="";g.parents(".snippet-container").append(t),g.parent().append(u);var v=g.parents(".snippet-container");d.startCollapsed?(v.find(".snippet-reveal").show(),v.find(".snippet-wrap").eq(0).hide()):(v.find(".snippet-reveal").hide(),v.find(".snippet-wrap").eq(0).show()),v.find("a.snippet-toggle").click(function(){return v.find(".snippet-wrap").toggle(),!1})}if(d.transparent){var w={"background-color":"transparent","box-shadow":"none","-moz-box-shadow":"none","-webkit-box-shadow":"none"};g.css(w),g.next(".snippet-textonly").css(w),g.parents(".snippet-container").find(".snippet-reveal pre").css(w)}d.startText&&(g.hide(),g.next(".snippet-textonly").show(),g.parent().find(".snippet-text").html("html"));if(d.box!=""){var x=" ",y=d.box.split(",");for(var z=0;z");var F=g.find("li").eq(0);F.unwrap()}}else{var E=g.find("li").eq(0).parent();if(E.hasClass("snippet-num")){E.wrap("
      ");var F=g.find("li").eq(0);F.unwrap()}}if(d.box!=""){var x=" ",y=d.box.split(",");for(var z=0;z-1&&(b.splice(c,1),this.className=b.join(" ")),this},a.hasClass=function(a){return!!this.className.match(new RegExp("\\s*"+a+"\\s*"))}),a},setMoviePath:function(a){this.moviePath=a},dispatch:function(a,b,c){var d=this.clients[a];d&&d.receiveEvent(b,c)},register:function(a,b){this.clients[a]=b},getDOMObjectPosition:function(a,b){var c={left:0,top:0,width:a.width?a.width:a.offsetWidth,height:a.height?a.height:a.offsetHeight};while(a&&a!=b)c.left+=a.offsetLeft,c.top+=a.offsetTop,a=a.offsetParent;return c},Client:function(a){this.handlers={},this.id=ZeroClipboard.nextId++,this.movieId="ZeroClipboardMovie_"+this.id,ZeroClipboard.register(this.id,this),a&&this.glue(a)}};ZeroClipboard.Client.prototype={id:0,ready:!1,movie:null,clipText:"",handCursorEnabled:!0,cssEffects:!0,handlers:null,glue:function(a,b,c){this.domElement=ZeroClipboard.$(a);var d=99;this.domElement.style.zIndex&&(d=parseInt(this.domElement.style.zIndex,10)+1),typeof b=="string"?b=ZeroClipboard.$(b):typeof b=="undefined"&&(b=document.getElementsByTagName("body")[0]);var e=ZeroClipboard.getDOMObjectPosition(this.domElement,b);this.div=document.createElement("div"),this.div.className="snippet-clipboard";var f=this.div.style;f.position="absolute",f.left=""+e.left+"px",f.top=""+e.top+"px",f.width=""+e.width+"px",f.height=""+e.height+"px",f.zIndex=d;if(typeof c=="object")for(addedStyle in c)f[addedStyle]=c[addedStyle];b.appendChild(this.div),this.div.innerHTML=this.getHTML(e.width,e.height)},getHTML:function(a,b){var c="",d="id="+this.id+"&width="+a+"&height="+b;if(navigator.userAgent.match(/MSIE/)){var e=location.href.match(/^https/i)?"https://":"http://";c+=''}else c+='';return c},hide:function(){this.div&&(this.div.style.left="-2000px")},show:function(){this.reposition()},destroy:function(){if(this.domElement&&this.div){this.hide(),this.div.innerHTML="";var a=document.getElementsByTagName("body")[0];try{a.removeChild(this.div)}catch(b){}this.domElement=null,this.div=null}},reposition:function(a){a&&(this.domElement=ZeroClipboard.$(a),this.domElement||this.hide());if(this.domElement&&this.div){var b=ZeroClipboard.getDOMObjectPosition(this.domElement),c=this.div.style;c.left=""+b.left+"px",c.top=""+b.top+"px"}},setText:function(a){this.clipText=a,this.ready&&this.movie.setText(a)},addEventListener:function(a,b){a=a.toString().toLowerCase().replace(/^on/,""),this.handlers[a]||(this.handlers[a]=[]),this.handlers[a].push(b)},setHandCursor:function(a){this.handCursorEnabled=a,this.ready&&this.movie.setHandCursor(a)},setCSSEffects:function(a){this.cssEffects=!!a},receiveEvent:function(a,b){a=a.toString().toLowerCase().replace(/^on/,"");switch(a){case"load":this.movie=document.getElementById(this.movieId);if(!this.movie){var c=this;setTimeout(function(){c.receiveEvent("load",null)},1);return}if(!this.ready&&navigator.userAgent.match(/Firefox/)&&navigator.userAgent.match(/Windows/)){var c=this;setTimeout(function(){c.receiveEvent("load",null)},100),this.ready=!0;return}this.ready=!0;try{this.movie.setText(this.clipText)}catch(d){}try{this.movie.setHandCursor(this.handCursorEnabled)}catch(d){}break;case"mouseover":this.domElement&&this.cssEffects&&(this.domElement.addClass("hover"),this.recoverActive&&this.domElement.addClass("active"));break;case"mouseout":this.domElement&&this.cssEffects&&(this.recoverActive=!1,this.domElement.hasClass("active")&&(this.domElement.removeClass("active"),this.recoverActive=!0),this.domElement.removeClass("hover"));break;case"mousedown":this.domElement&&this.cssEffects&&this.domElement.addClass("active");break;case"mouseup":this.domElement&&this.cssEffects&&(this.domElement.removeClass("active"),this.recoverActive=!1)}if(this.handlers[a])for(var e=0,f=this.handlers[a].length;e|\|/g,"sh_symbol",-1],[/\{|\}/g,"sh_cbracket",-1],[/(?:[A-Za-z]|_)[A-Za-z0-9_]*(?=[ \t]*\()/g,"sh_function",-1],[/([A-Za-z](?:[^`~!@#$%&*()_=+{}|;:",<.>\/?'\\[\]\^\-\s]|[_])*)((?:<.*>)?)(\s+(?=[*&]*[A-Za-z][^`~!@#$%&*()_=+{}|;:",<.>\/?'\\[\]\^\-\s]*\s*[`~!@#$%&*()_=+{}|;:",<.>\/?'\\[\]\^\-\[\]]+))/g,["sh_usertype","sh_usertype","sh_normal"],-1]],[[/$/g,null,-2],[/(?:?)|(?:?)/g,"sh_url",-1],[/<\?xml/g,"sh_preproc",2,1],[//g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)/g,"sh_keyword",6,1],[/&(?:[A-Za-z0-9]+);/g,"sh_preproc",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,"sh_keyword",6,1],[/@[A-Za-z]+/g,"sh_type",-1],[/(?:TODO|FIXME|BUG)(?:[:]?)/g,"sh_todo",-1]],[[/\?>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/\\(?:\\|")/g,null,-1],[/"/g,"sh_string",-2]],[[/>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/-->/g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[//g,"sh_comment",-2],[/