1// Some CSS depends on the `js` class. 2$( "html" ).addClass( "js" ).removeClass( "no-js" ); 3 4/* 5 * All sites 6 */ 7$(function() { 8 // copyable auto-select-all 9 $( ".copyable" ).on( "click", function() { 10 if ( typeof this.select === "function" ) { 11 this.select(); 12 } 13 }); 14 15 // collapsible navigation for smaller screens 16 $('.menu-trigger').on('click', function (e) { 17 var $btn = $(this), 18 $nav = $(this).next('.menu'); 19 if ($nav.hasClass('menu-open')) { 20 $btn.attr('aria-expanded', 'false'); 21 $nav.removeClass('menu-open'); 22 } else { 23 $btn.attr('aria-expanded', 'true'); 24 $nav.addClass('menu-open'); 25 $nav.find('a').first().focus(); 26 } 27 }); 28}); 29 30 31 32 33 34/* 35 * API sites 36 */ 37$(function() { 38 $( ".entry-example" ).each(function() { 39 var iframeSrc, 40 src = $( this ).find( ".syntaxhighlighter" ), 41 output = $( this ).find( ".code-demo" ); 42 43 if ( !src.length || !output.length ) { 44 return; 45 } 46 47 // Get the original source 48 iframeSrc = src.find( "td.code .line" ).map(function() { 49 // Convert non-breaking spaces from highlighted code to normal spaces 50 return $( this ).text().replace( /\xa0/g, " " ); 51 // Restore new lines from original source 52 }).get().join( "\n" ); 53 54 iframeSrc = iframeSrc 55 // Insert styling for the live demo that we don't want in the 56 // highlighted code 57 .replace( "</head>", 58 "<style>" + 59 "html, body { border:0; margin:0; padding:0; }" + 60 "body { font-family: 'Helvetica', 'Arial', 'Verdana', 'sans-serif'; }" + 61 "</style>" + 62 "</head>" ) 63 // IE <10 executes scripts in the order in which they're loaded, 64 // not the order in which they're written. So we need to defer inline 65 // scripts so that scripts which need to be fetched are executed first. 66 .replace( /<script>([\s\S]+)<\/script>/, 67 "<script>" + 68 "window.onload = function() {" + 69 "$1" + 70 "};" + 71 "</script>" ); 72 73 var iframe = document.createElement( "iframe" ); 74 iframe.width = "100%"; 75 iframe.height = output.attr( "data-height" ) || 250; 76 output.append( iframe ); 77 78 var doc = (iframe.contentWindow || iframe.contentDocument).document; 79 doc.write( iframeSrc ); 80 doc.close(); 81 }); 82}); 83 84/* 85 * jqueryui.com 86 */ 87$(function() { 88 var demoFrame = $( ".demo-frame" ), 89 demoDescription = $( ".demo-description" ), 90 sourceView = $( ".view-source > div" ), 91 demoList = $( ".demo-list" ), 92 currentDemo = location.hash.substring( 1 ); 93 94 demoList.on( "click", "a", function( event ) { 95 event.preventDefault(); 96 97 var filename = "/" + event.target.pathname.replace( /^\//, "" ), 98 parts = filename.split( "/" ), 99 plugin = parts[ 3 ], 100 demo = parts[ 4 ].substring( 0, parts[ 4 ].length - 5 ); 101 102 if ( demoList.is( "[data-full-nav]" ) ) { 103 window.location = "/" + (demo === "default" ? plugin : demo) + "/"; 104 return; 105 } 106 107 $.getJSON( "/resources/demos/demo-list.json" ).then(function( demoList ) { 108 demoDescription.html( $.grep( demoList[ plugin ], function( x ) { 109 return x.filename === demo; 110 })[ 0 ].description ); 111 demoFrame.attr( "src", filename ); 112 }); 113 114 $.get( filename.replace( "demos", "demos-highlight" ) ).then(function( content ) { 115 sourceView.html( content ); 116 }); 117 118 demoList.find( ".active" ).removeClass( "active" ); 119 $( this ).parent().addClass( "active" ); 120 location.hash = "#" + demo; 121 }); 122 123 $( ".view-source a" ).on( "click", function() { 124 sourceView.animate({ 125 opacity: "toggle", 126 height: "toggle" 127 }); 128 }); 129 130 if ( currentDemo ) { 131 demoList.find( "a" ).filter(function() { 132 return this.pathname.split( "/" )[ 4 ] === (currentDemo + ".html"); 133 }).click(); 134 } 135});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.