PageSourceSearch

https://build.codepoet.com/_static/??-eJyNjTEOgzAMAD9EcANCSoeKt0TB…PlEvLvwlH18syHhqFJ+2UwvO052eD7c6NIX3M5Ogw==

js codepoet.com collected 2026-10-02 04:59:04 UTC 14,945 bytes, 346 lines download raw bytes

1/**
2 * Handles toggling the main navigation menu for small screens.
3 */
4jQuery( document ).ready( function( $ ) {
5	var $masthead = $( '#masthead' ),
6	    timeout = false;
7
8	$.fn.smallMenu = function() {
9		$masthead.find( '.site-navigation' ).removeClass( 'main-navigation' ).addClass( 'main-small-navigation' );
10		$masthead.find( '.site-navigation h1' ).removeClass( 'assistive-text' ).addClass( 'menu-toggle' );
11
12		$( '.menu-toggle' ).unbind( 'click' ).click( function() {
13			$masthead.find( '.menu' ).toggle();
14			$( this ).toggleClass( 'toggled-on' );
15		} );
16	};
17
18	// Check viewport width on first load.
19	if ( $( window ).width() < 600 )
20		$.fn.smallMenu();
21
22	// Check viewport width when user resizes the browser window.
23	$( window ).resize( function() {
24		var browserWidth = $( window ).width();
25
26		if ( false !== timeout )
27			clearTimeout( timeout );
28
29		timeout = setTimeout( function() {
30			if ( browserWidth < 600 ) {
31				$.fn.smallMenu();
32			} else {
33				$masthead.find( '.site-navigation' ).removeClass( 'main-small-navigation' ).addClass( 'main-navigation' );
34				$masthead.find( '.site-navigation h1' ).removeClass( 'menu-toggle' ).addClass( 'assistive-text' );
35				$masthead.find( '.menu' ).removeAttr( 'style' );
36			}
37		}, 200 );
38	} );
39} );;
40///////////////////////////////////////
41// Core
42///////////////////////////////////////
43if (!window.CP) {
44	window.CP = {};
45}
46CP.Core = function () {
47	resourcesScrollPaginate = 0;
48	function homeHeightCheck () {
49
50		// Height check for top 2 homepage items (otherwise layout can get wonky)
51		var signup = jQuery( '.signup' ),
52			firstArticle = jQuery( 'article:eq( 0 )' );
53
54		if ( signup.height() > firstArticle.height() ) {
55			firstArticle.css( 'height', signup.height() + 'px' );
56		}
57
58		if ( signup.height() < firstArticle.height() ) {
59			 signup.css( 'height', firstArticle.height() + 'px' );
60		}
61	}
62	function resourcesFetch ( offset ) {
63		jQuery.post(
64			core.ajaxurl, {
65				action : 'resource-fetch',
66				offset : offset
67			}, function( posts ) {
68				// Loop through and add posts to view
69				if ( 0 != posts.length )
70					resourcesAddToDom( posts );
71				// Kills infinite scroll AJAX calls if there aren't anymore results to bring in
72				if ( 10 > posts.length )
73					return true;
74				else
75					return false;
76			}
77		);
78	}
79	function resourcesAddToDom ( posts ) {
80
81		for ( i=0; i<posts.length; i++ ) {
82
83			// No duplicates - check to see if this post has already been added
84			if ( jQuery( '#post-' + posts[i].id ).length === 0 ) {
85
86				// Set args we'll need to update template
87				var post = {
88					id: posts[i].id,
89					permalink: posts[i].permalink,
90					title: posts[i].title,
91					category: posts[i].category,
92					imgsrc: posts[i].imgsrc,
93					excerpt: posts[i].excerpt
94				};
95
96				// Populate template
97				article = ich.resource( post );
98
99				// Add to DOM
100				jQuery( 'section' ).append( article );
101
102			}
103		}
104	}
105	function scrollWatch () {
106
107		var continueFetching = true,
108			loadedScrollHeight = parseInt( resourcesScrollPaginate ) * 1000;
109
110		if ( loadedScrollHeight < jQuery( window ).scrollTop() ) {
111			// increment by 1
112			resourcesScrollPaginate = resourcesScrollPaginate + 1;
113			// Grab next set of posts
114			continueFetching = resourcesFetch( resourcesScrollPaginate * 10 );
115		}
116
117		// Kill infinite scroll when we've run out of posts to serve up
118		if ( continueFetching ) {
119			setTimeout( function () {
120				scrollWatch();
121			}, 1000);
122		}
123	}
124	return {
125		homeInit: function () {
126			textPlaceholderInit();
127			homeHeightCheck();
128		},
129		homeResize: function () {
130			homeHeightCheck();
131		},
132		resourceInit: function () {
133			// Fix horizontal scroll bug
134			jQuery('.FB_UI_Hidden').css('width', '100px');
135		},
136		resourcesInit: function () {
137			// Start at top
138			jQuery( window ).scrollTop( 0 );
139			// Monitor scrolling to load additional posts
140			scrollWatch();
141		}
142	}
143} ();
144///////////////////////////////////////
145// Plugins
146///////////////////////////////////////
147
148// Cross broswer support for text box placeholder text
149// https://gist.github.com/379601
150// Released under MIT license: http://www.opensource.org/licenses/mit-license.php
151function textPlaceholderInit(){jQuery("[placeholder]").focus(function(){var a=jQuery(this);a.val()==a.attr("placeholder")&&(a.val(""),a.removeClass("placeholder"))}).blur(function(){var a=jQuery(this);if(""==a.val()||a.val()==a.attr("placeholder"))a.addClass("placeholder"),a.val(a.attr("placeholder"))}).blur().parents("form").submit(function(){jQuery(this).find("[placeholder]").each(function(){var a=jQuery(this);a.val()==a.attr("placeholder")&&a.val("")})})};
152
153// ICanHaz.js version 0.10 -- by @HenrikJoreteg
154// More info at: http://icanhazjs.com
155(function(){var q=function(){function c(a){return(""+a).replace(/&(?!\w+;)|[<>"']/g,function(a){return k[a]||a})}var e=Object.prototype.toString;Array.isArray=Array.isArray||function(a){return"[object Array]"==e.call(a)};var i=String.prototype.trim,g;if(i)g=function(a){return null==a?"":i.call(a)};else{var h,m;/\S/.test("\u00a0")?(h=/^[\s\xA0]+/,m=/[\s\xA0]+$/):(h=/^\s+/,m=/\s+$/);g=function(a){return null==a?"":a.toString().replace(h,"").replace(m,"")}}var k={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;",
156"'":"&#39;"},o={},p=function(){};p.prototype={otag:"{{",ctag:"}}",pragmas:{},buffer:[],pragmas_implemented:{"IMPLICIT-ITERATOR":!0},context:{},render:function(a,d,b,f){if(!f)this.context=d,this.buffer=[];if(this.includes("",a)){var a=this.render_pragmas(a),j=this.render_section(a,d,b);!1===j&&(j=this.render_tags(a,d,b,f));if(f)return j;this.sendLines(j)}else{if(f)return a;this.send(a)}},send:function(a){""!==a&&this.buffer.push(a)},sendLines:function(a){if(a)for(var a=a.split("\n"),d=0;d<a.length;d++)this.send(a[d])},
157render_pragmas:function(a){if(!this.includes("%",a))return a;var d=this,b=this.getCachedRegex("render_pragmas",function(a,d){return RegExp(a+"%([\\w-]+) ?([\\w]+=[\\w]+)?"+d,"g")});return a.replace(b,function(a,b,e){if(!d.pragmas_implemented[b])throw{message:"This implementation of mustache doesn't understand the '"+b+"' pragma"};d.pragmas[b]={};e&&(a=e.split("="),d.pragmas[b][a[0]]=a[1]);return""})},render_partial:function(a,d,b){a=g(a);if(!b||void 0===b[a])throw{message:"unknown_partial '"+a+"'"};
158return!d||"object"!=typeof d[a]?this.render(b[a],d,b,!0):this.render(b[a],d[a],b,!0)},render_section:function(a,d,b){if(!this.includes("#",a)&&!this.includes("^",a))return!1;var f=this,j=this.getCachedRegex("render_section",function(a,b){return RegExp("^([\\s\\S]*?)"+a+"(\\^|\\#)\\s*(.+)\\s*"+b+"\n*([\\s\\S]*?)"+a+"\\/\\s*\\3\\s*"+b+"\\s*([\\s\\S]*)$","g")});return a.replace(j,function(a,j,e,c,g,h){var a=j?f.render_tags(j,d,b,!0):"",h=h?f.render(h,d,b,!0):"",n,c=f.find(c,d);"^"===e?n=!c||Array.isArray(c)&&
1590===c.length?f.render(g,d,b,!0):"":"#"===e&&(n=Array.isArray(c)?f.map(c,function(a){return f.render(g,f.create_context(a),b,!0)}).join(""):f.is_object(c)?f.render(g,f.create_context(c),b,!0):"function"==typeof c?c.call(d,g,function(a){return f.render(a,d,b,!0)}):c?f.render(g,d,b,!0):"");return a+n+h})},render_tags:function(a,d,b,f){for(var j=this,e=function(){return j.getCachedRegex("render_tags",function(a,b){return RegExp(a+"(=|!|>|&|\\{|%)?([^#\\^]+?)\\1?"+b+"+","g")})},g=e(),h=function(a,f,h){switch(f){case "!":return"";
160case "=":return j.set_delimiters(h),g=e(),"";case ">":return j.render_partial(h,d,b);case "{":case "&":return j.find(h,d);default:return c(j.find(h,d))}},a=a.split("\n"),i=0;i<a.length;i++)a[i]=a[i].replace(g,h,this),f||this.send(a[i]);if(f)return a.join("\n")},set_delimiters:function(a){a=a.split(" ");this.otag=this.escape_regex(a[0]);this.ctag=this.escape_regex(a[1])},escape_regex:function(a){if(!arguments.callee.sRE)arguments.callee.sRE=RegExp("(\\/|\\.|\\*|\\+|\\?|\\||\\(|\\)|\\[|\\]|\\{|\\}|\\\\)",
161"g");return a.replace(arguments.callee.sRE,"\\$1")},find:function(a,d){function b(a){return!1===a||0===a||a}var a=g(a),f;if(a.match(/([a-z_]+)\./ig)){var c=this.walk_context(a,d);b(c)&&(f=c)}else b(d[a])?f=d[a]:b(this.context[a])&&(f=this.context[a]);return"function"==typeof f?f.apply(d):void 0!==f?f:""},walk_context:function(a,d){for(var b=a.split("."),f=void 0!=d[b[0]]?d:this.context,c=f[b.shift()];void 0!=c&&0<b.length;)f=c,c=c[b.shift()];return"function"==typeof c?c.apply(f):c},includes:function(a,
162d){return-1!=d.indexOf(this.otag+a)}
162,create_context:function(a){if(this.is_object(a))return a;var d=".";if(this.pragmas["IMPLICIT-ITERATOR"])d=this.pragmas["IMPLICIT-ITERATOR"].iterator;var b={};b[d]=a;return b},is_object:function(a){return a&&"object"==typeof a},map:function(a,d){if("function"==typeof a.map)return a.map(d);for(var b=[],c=a.length,e=0;e<c;e++)b.push(d(a[e]));return b},getCachedRegex:function(a,d){var b=o[this.otag];b||(b=o[this.otag]={});var c=b[this.ctag];c||(c=b[this.ctag]={});
163(b=c[a])||(b=c[a]=d(this.otag,this.ctag));return b}};return{name:"mustache.js",version:"0.4.0",to_html:function(a,c,b,f){var e=new p;if(f)e.send=f;e.render(a,c||{},b);if(!f)return e.buffer.join("\n")}}}();(function(){var c={VERSION:"0.10",templates:{},$:"undefined"!==typeof window?window.jQuery||window.Zepto||null:null,addTemplate:function(e,i){if("object"===typeof e)for(var g in e)this.addTemplate(g,e[g]);else c[e]?console.error("Invalid name: "+e+"."):c.templates[e]?console.error('Template "'+e+
164'  " exists'):(c.templates[e]=i,c[e]=function(g,i){var g=g||{},k=q.to_html(c.templates[e],g,c.templates);return c.$&&!i?c.$(k):k})},clearAll:function(){for(var e in c.templates)delete c[e];c.templates={}},refresh:function(){c.clearAll();c.grabTemplates()},grabTemplates:function(){var e,i=document.getElementsByTagName("script"),g,h=[];for(e=0,l=i.length;e<l;e++)if((g=i[e])&&g.innerHTML&&g.id&&("text/html"===g.type||"text/x-icanhaz"===g.type))c.addTemplate(g.id,"".trim?g.innerHTML.trim():g.innerHTML.replace(/^\s+/,
165"").replace(/\s+$/,"")),h.unshift(g);for(e=0,l=h.length;e<l;e++)h[e].parentNode.removeChild(h[e])}};"undefined"!==typeof require?module.exports=c:window.ich=c;"undefined"!==typeof document&&(c.$?c.$(function(){c.grabTemplates()}):document.addEventListener("DOMContentLoaded",function(){c.grabTemplates()},!0))})()})();;
166/* https://github.com/carhartl/jquery-cookie */
167(function($) {
168	$.cookie = function(key, value, options) {
169
170		// key and at least value given, set cookie...
171		if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
172			options = $.extend({}, options);
173
174			if (value === null || value === undefined) {
175				options.expires = -1;
176			}
177
178			if (typeof options.expires === 'number') {
179				var days = options.expires, t = options.expires = new Date();
180				t.setDate(t.getDate() + days);
181			}
182
183			value = String(value);
184
185			return (document.cookie = [
186				encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
187				options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
188				options.path    ? '; path=' + options.path : '',
189				options.domain  ? '; domain=' + options.domain : '',
190				options.secure  ? '; secure' : ''
191			].join(''));
192		}
193
194		// key and possibly options given, get cookie...
195		options = value || {};
196		var decode = options.raw ? function(s) { return s; } : decodeURIComponent;
197
198		var pairs = document.cookie.split('; ');
199		for (var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
200			if (decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, thus pair[1] may be undefined
201		}
202		return null;
203	};
204})(jQuery);;
205jQuery( function($) {
206	var downloadLink = '',
207		ajaxLoader = $( '.ajax-loader' );
208
209	/* Focus the field without highlighting pre-filled values */
210	var cachedEmail = $( '#cm-email-address' ).val();
211	$( '#cm-email-address' ).val( cachedEmail);
212	$( '#cm-email-address' ).focus();
213
214	// Listen for form submissions
215	$( '.notify-me' ).submit( function(e) {
216		e.preventDefault();
217		signupAction( $(this).find("#cm-email-address").val() );
218	});
219	$( '.signup-submit' ).live('click', function(e) {
220		e.preventDefault();
221		signupAction( $(".modal #cm-email-address").val() );
222	});
223
224	// Close modal
225	$( '.shade_dark, .close, .alert-close' ).live('click', function () {
226		$( '.shade_dark, .modal' ).fadeOut();
227		return false;
228	});
229
230	// Click events added to each ebook download option
231	$( '.pdf-link, .mobi-link, .epub-link' ).click( function () {
232
233		var linkUrl = $( this ).attr( 'data-link' ),
234			isCodePoet = $( this ).attr( 'data-iscp' );
235
236		if ( isCodePoet ) {
237			// Track downloads
238			var data = {
239				action: 'codepoet_ebook_download',
240				ebook_link: linkUrl
241			};
242			$.ajax({
243				type: 'POST',
244				url: core.ajaxurl,
245				async: false,
246				data: data
247			});
248
249			// Send them the file
250			window.location = linkUrl;
251		} else {
252			// Else show the signup modal
253			downloadLink = linkUrl;
254			signupModalShow();
255		}
256
257		return false;
258	});
259
260	function signupAction (emailAddress) {
261
262		// Show ajax spinner
263		ajaxLoader.show();
264
265		var data = {
266			action: 'codepoet_email_signup',
267			email: emailAddress,
268			nonce: codepoet_signup.nonce
269		};
270
271		$.post( core.ajaxurl, data, function(response){
272
273			var result = $.parseJSON( response );
274
275			if( 'success' == result.type ) {
276
277				$('#cm-email-address').hide();
278
279				var options = {
280					'header' : 'Success',
281					'body' : "Welcome to the inside track, Code Poet. We'll send you an email digest of all our interviews, books, and resources.",
282					'footer' : ich.closebutton()
283				};
284
285				signupModalShow( options );
286
287				if( result.data && result.data.email ) {
288					$.cookie( 'codepoet_signup', result.data.email, { path: '/', expires: 365 } );
289				}
290
291				if (downloadLink)
292					window.location = downloadLink;
293			}
294			else {
295
296				var options = {
297					'header' : 'Oops...',
298					'body' : result.message,
299					'footer' : ich.closebutton()
300				};
301				signupModalShow( options );
302			}
303
304			// Hide ajax spinner
305			ajaxLoader.hide();
306		});
307
308	}
309
310	function signupModalShow ( options ) {
311
312		var docHeight = jQuery( document ).height(),
313			modalDiv = jQuery( '.modal' ),
314			modalWidth = modalDiv.width(),
315			winWidth = jQuery( window ).width(),
316			settings = $.extend( {
317				'header' : 'Welcome, Code Poet',
318				'body' : ich.signupbody(),
319				'footer' : ich.signupbutton()
320			}, options);
321
322		var ua = navigator.userAgent.toLowerCase(),
323			isAndroid = ua.indexOf("android") > -1;
324
325		// Scroll to top
326		if ( winWidth >
326 480 || isAndroid )
327			jQuery( window ).scrollTop( 0 );
328
329		// show modal bg
330		jQuery( '.shade_dark' ).css( 'height', docHeight + 'px' ).show();
331
332		// Populate Modal
333		$( '.modal-header h3' ).html( settings.header );
334		$( '.modal-body-text' ).html( settings.body );
335		$( '.modal-footer' ).html( settings.footer );
336
337		// Show modal
338		modalDiv.css( 'left', [ winWidth - modalWidth ] / 2 + 'px' ).fadeIn();
339	}
340
341	// Signup link on ourstory page
342	$( '.signup-link' ).click( function () {
343		signupModalShow();
344		return false;
345	});
346});;

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.