1 2/* 3 * HAL 4 * Author: Greg Sabia 5 * Support: http://gregsabia.com 6 * 7*/ 8 9HAL = { 10 openThePodBayDoors : function(){ 11 return console.log('I\'m sorry Greg, I\'m afraid I can\'t do that.'); 12 }, 13 _extended : false, 14 _getTimeout : 300, 15 init : function(){ 16 // DOM Ready 17 HAL.gregboxes.init(); 18 HAL.subscribe.init(); 19 HAL.youtube.init(); 20 HAL.kirstieUpdates.init(); 21 HAL.lightboxes.init(); 22 }, 23 please : { 24 init : function(){ 25 $(function(){ 26 if(HAL._extended.init) HAL._extended.init(); 27 }); 28 }, 29 extend : function(obj){ 30 return $.extend(HAL._extended,obj); 31 }, 32 clearText : function(thefield){ 33 if(thefield.defaultValue==thefield.value){ thefield.value = "" } 34 }, 35 replaceText : function(thefield){ 36 if(thefield.value==""){ thefield.value = thefield.defaultValue } 37 }, 38 preloadImages : function(){ 39 var d=document; 40 if(d.images){ 41 if(!d.p) d.p=new Array(); 42 var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length;i++) 43 if(a[i].indexOf("#") != 0){ 44 d.p[j]=new Image; d.p[j++].src=a[i]; 45 } 46 } 47 }, 48 getAnchor : function(){ 49 var url_anchor = document.location.toString(); 50 if(url_anchor.match('#')){ 51 return url_anchor.split('#')[1]; 52 }else{ 53 return false; 54 } 55 }, 56 setAnchor : function(anchor){ 57 var url_anchor = document.location.toString(); 58 59 document.location = url_anchor.split('#')[0]+'#'+anchor; 60 }, 61 setCookie : function(name,value,expiredays){ 62 // Set a cookie 63 var exdate = new Date(); 64 exdate.setDate(exdate.getDate()+expiredays); 65 document.cookie = name+"="+escape(value)+((expiredays == null)?"":";expires="+exdate.toUTCString())+"; path=/"; 66 } 67 }, 68 gregboxes : { 69 init : function(){ 70 $('.gregbox').each(function(){ 71 // Add wrapper 72 if(!$(this).attr('dontrender')) $(this).html('<div class="top"></div><div class="content">'+$(this).html()+'</div><div class="bottom"></div>'); 73 74 // Allow lightbox to be closed when the user clicks off of the box 75 if($(this).attr('closeonblur')){ 76 $(this).bind('dialogopen',function(event,ui){ 77 var gb = this; 78 $('.ui-widget-overlay').click(function(){ 79 $(gb).dialog('close'); 80 }); 81 }); 82 } 83 84 // Assign widths 85 if($(this).hasClass('skinny')){ 86 width = 536; 87 }else{ 88 width = 936; 89 } 90 91 $(this).dialog({ 92 'width': width, 93 'modal': true, 94 'autoOpen': false, 95 'resizable': false 96 }); 97 }); 98 }, 99 open : function(selector){ 100 $(selector).dialog('open'); 101 } 102 }, 103 subscribe : { 104 selector : '#complete-subscription', 105 form : 'form.subscribe', 106 init : function(){ 107 // Form onsubmit 108 $(HAL.subscribe.form).each(function(i,form){ 109 default_value = $('input.subscribe-email',form).val(); 110 111 $('a.arrow',form).click(function(){ 112 $(form).submit(); 113 }); 114 115 $(form).submit(function(){ 116 if(!$('input.optin-checkbox:checked',form).length){ 117 alert('You must select the checkbox before you can get Kirstie\'s updates!'); 118 return false; 119 }else if(!$('input.subscribe-email',form).val() || $('input.subscribe-email',form).val() == default_value){ 120 alert('Please enter a valid email address!'); 121 return false;
122 }else{ 123 // All good, process form 124 return true; 125 } 126 }); 127 }); 128 129 switch(HAL.please.getAnchor()){ 130 case 'complete_subscription' : 131 // Complete the subscription 132 HAL.gregboxes.open(this.selector); 133 134 // Track event 135 HAL.analytics.track.pageview('/subscribe'); 136 137 // Set cookie 138 HAL.please.setCookie('ka_subscribed',true,365); 139 break; 140 case 'error_email' : 141 alert('Please enter a valid email address!'); 142 break; 143 } 144 } 145 }, 146 youtube : { 147 init : function(){ 148 $('a.youtube').click(function(){ 149 HAL.youtube.playHighlight($(this).parent()); 150 }); 151 }, 152 playHighlight : function(e){ 153 $(e).html('<iframe width="363" height="230" src="http://www.youtube.com/embed/'+$('a.youtube',e).attr('rel')+'?autoplay=1" frameborder="0" allowfullscreen="true"></iframe>'); 154 } 155 }, 156 kirstieUpdates : { 157 init : function(){ 158 $('.subscribe-box div.animatebox').each(function(){ 159 var target = this; 160 var animate; 161 animate = function(){ 162 $('.animate-target', target).css('position', 'absolute').css('left', '200px').show().animate({ 163 left : 0 164 }, 1000, function(){ 165 $('.animate-target', target).delay(3000).fadeOut(300, animate); 166 }); 167 } 168 // Recurse animation 169 animate(); 170 }); 171 } 172 }, 173 lightboxes : { 174 init : function(){ 175 $('.lightbox').click(function(event){ 176 var self = this; 177 // Find target 178 var target = $(this).attr('rel'); 179 var video = ($(this).hasClass('video')) ? true : false; 180 181 $('#lightbox').html($(target).html()).lightbox_me({ 182 centered: true, 183 onLoad: function() { 184 if(video){ 185 // Create a video wrapper 186 var box = $(document.createElement('div')).attr('id', 'video-object').css('height', '100%').appendTo($('#lightbox')); 187 // Setup JWPlayer 188 jwplayer('video-object').setup({ 189 file : $(self).attr('data-src'), 190 height : '360', 191 width : '100%', 192 skin : '/assets/js/video/ol.zip', 193 autostart : ($(self).attr('autostart') == 'false') ? false : true, 194 stretching : 'fill', 195 modes : [ 196 { type : 'html5' }, 197 { type : 'flash', 'src' : '/assets/js/video/player.swf' }, 198 { type : 'download' } 199 ], 200 events : { 201 onComplete: function(){ 202 return false; 203 } 204 } 205 }); 206 } 207 }, 208 onClose : function(){ 209 // Stop video 210 jwplayer('video-object').stop(); 211 } 212 }); 213 // Do nothing else 214 event.preventDefault(); 215 return false; 216 }); 217 } 218 }, 219 analytics : { 220 executable : function(){ 221 if(typeof _gaq !== 'undefined'){ 222 return true; 223 }else{ 224 this.log('Couldn\'t track event because analytics is not executable'); 225 return false;
226 } 227 }, 228 log : function(s){ 229 if(typeof console !== 'undefined') console.log(s) 230 }, 231 track : { 232 pageview : function(url,callback){ 233 // Track the pageview 234 if(HAL.analytics.executable()){ 235 var c = _gaq.push(['_trackPageview',url]); 236 HAL.analytics.log('Tracked '+url+' using _trackPageview'); 237 } 238 239 if(callback) callback(); 240 241 return c; 242 }, 243 event : function(category,action,label,value){ 244 if(HAL.analytics.executable()){ 245 var c = _gaq.push(['_trackEvent',category,action,label,value]); 246 HAL.analytics.log('Tracked '+category+':'+action+' using _trackEvent'); 247 } 248 249 return c; 250 } 251 } 252 } 253} 254
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.