/* TimelineJS - ver. 2015-05-11-15-36-39 - 2015-05-11 Copyright (c) 2012-2013 Northwestern University a project of the Northwestern University Knight Lab, originally created by Zach Wise https://github.com/NUKnightLab/TimelineJS This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* ********************************************** Begin VMM.js ********************************************** */ /** * VéritéCo JS Core * Designed and built by Zach Wise at VéritéCo zach@verite.co * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* Simple JavaScript Inheritance By John Resig http://ejohn.org/ MIT Licensed. ================================================== */ (function() { var initializing = false, fnTest = /xyz/.test(function() { xyz; }) ? /\b_super\b/: /.*/; // The base Class implementation (does nothing) this.Class = function() {}; // Create a new Class that inherits from this class Class.extend = function(prop) { var _super = this.prototype; // Instantiate a base class (but only create the instance, // don't run the init constructor) initializing = true; var prototype = new this(); initializing = false; // Copy the properties over onto the new prototype for (var name in prop) { // Check if we're overwriting an existing function prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function(name, fn) { return function() { var tmp = this._super; // Add a new ._super() method that is the same method // but on the super-class this._super = _super[name]; // The method only need to be bound temporarily, so we // remove it when we're done executing var ret = fn.apply(this, arguments); this._super = tmp; return ret; }; })(name, prop[name]) : prop[name]; } // The dummy class constructor function Class() { // All construction is actually done in the init method if (!initializing && this.init) this.init.apply(this, arguments); } // Populate our constructed prototype object Class.prototype = prototype; // Enforce the constructor to be what we expect Class.prototype.constructor = Class; // And make this class extendable Class.extend = arguments.callee; return Class; }; })(); /* Access to the Global Object access the global object without hard-coding the identifier window ================================================== */ var global = (function () { return this || (1,eval)('this'); }()); /* VMM ================================================== */ if (typeof VMM == 'undefined') { /* Main Scope Container ================================================== */ //var VMM = {}; var VMM = Class.extend({}); /* Debug ================================================== */ VMM.debug = true; /* Master Config ================================================== */ VMM.master_config = ({ init: function() { return this; }, sizes: { api: { width: 0, height: 0 } }, vp: "Pellentesque nibh felis, eleifend id, commodo in, interdum vitae, leo", api_keys_master: { flickr: "RAIvxHY4hE/Elm5cieh4X5ptMyDpj7MYIxziGxi0WGCcy1s+yr7rKQ==", //google: "jwNGnYw4hE9lmAez4ll0QD+jo6SKBJFknkopLS4FrSAuGfIwyj57AusuR0s8dAo=", google: "uQKadH1VMlCsp560gN2aOiMz4evWkl1s34yryl3F/9FJOsn+/948CbBUvKLN46U=", twitter: "" }, timers: { api: 7000 }, api: { pushques: [] }, twitter: { active: false, array: [], api_loaded: false, que: [] }, flickr: { active: false, array: [], api_loaded: false, que: [] }, youtube: { active: false, array: [], api_loaded: false, que: [] }, vimeo: { active: false, array: [], api_loaded: false, que: [] }, vine: { active: false, array: [], api_loaded: false, que: [] }, webthumb: { active: false, array: [], api_loaded: false, que: [] }, googlemaps: { active: false, map_active: false, places_active: false, array: [], api_loaded: false, que: [] }, googledocs: { active: false, array: [], api_loaded: false, que: [] }, googleplus: { active: false, array: [], api_loaded: false, que: [] }, wikipedia: { active: false, array: [], api_loaded: false, que: [], tries: 0 }, soundcloud: { active: false, array: [], api_loaded: false, que: [] } }).init(); //VMM.createElement(tag, value, cName, attrs, styles); VMM.createElement = function(tag, value, cName, attrs, styles) { var ce = ""; if (tag != null && tag != "") { // TAG ce += "<" + tag; if (cName != null && cName != "") { ce += " class='" + cName + "'"; }; if (attrs != null && attrs != "") { ce += " " + attrs; }; if (styles != null && styles != "") { ce += " style='" + styles + "'"; }; ce += ">"; if (value != null && value != "") { ce += value; } // CLOSE TAG ce = ce + ""; } return ce; }; VMM.createMediaElement = function(media, caption, credit) { var ce = ""; var _valid = false; ce += "
"; if (media != null && media != "") { valid = true; ce += ""; // CREDIT if (credit != null && credit != "") { ce += VMM.createElement("div", credit, "credit"); } // CAPTION if (caption != null && caption != "") { ce += VMM.createElement("div", caption, "caption"); } } ce += "
"; return ce; }; // Hide URL Bar for iOS and Android by Scott Jehl // https://gist.github.com/1183357 VMM.hideUrlBar = function () { var win = window, doc = win.document; // If there's a hash, or addEventListener is undefined, stop here if( !location.hash || !win.addEventListener ){ //scroll to 1 window.scrollTo( 0, 1 ); var scrollTop = 1, //reset to 0 on bodyready, if needed bodycheck = setInterval(function(){ if( doc.body ){ clearInterval( bodycheck ); scrollTop = "scrollTop" in doc.body ? doc.body.scrollTop : 1; win.scrollTo( 0, scrollTop === 1 ? 0 : 1 ); } }, 15 ); win.addEventListener( "load", function(){ setTimeout(function(){ //reset to hide addr bar at onload win.scrollTo( 0, scrollTop === 1 ? 0 : 1 ); }, 0); }, false ); } }; } /* Trace (console.log) ================================================== */ function trace( msg ) { if (VMM.debug) { if (window.console) { console.log(msg); } else if ( typeof( jsTrace ) != 'undefined' ) { jsTrace.send( msg ); } else { //alert(msg); } } } /* Extending Date to include Week ================================================== */ Date.prototype.getWeek = function() { var onejan = new Date(this.getFullYear(),0,1); return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7); } /* Extending Date to include Day of Year ================================================== */ Date.prototype.getDayOfYear = function() { var onejan = new Date(this.getFullYear(),0,1); return Math.ceil((this - onejan) / 86400000); } /* A MORE SPECIFIC TYPEOF(); // http://rolandog.com/archives/2007/01/18/typeof-a-more-specific-typeof/ ================================================== */ // type.of() var is={ Null:function(a){return a===null;}, Undefined:function(a){return a===undefined;}, nt:function(a){return(a===null||a===undefined);}, Function:function(a){return(typeof(a)==="function")?a.constructor.toString().match(/Function/)!==null:false;}, String:function(a){return(typeof(a)==="string")?true:(typeof(a)==="object")?a.constructor.toString().match(/string/i)!==null:false;}, Array:function(a){return(typeof(a)==="object")?a.constructor.toString().match(/array/i)!==null||a.length!==undefined:false;}, Boolean:function(a){return(typeof(a)==="boolean")?true:(typeof(a)==="object")?a.constructor.toString().match(/boolean/i)!==null:false;}, Date:function(a){return(typeof(a)==="date")?true:(typeof(a)==="object")?a.constructor.toString().match(/date/i)!==null:false;}, HTML:function(a){return(typeof(a)==="object")?a.constructor.toString().match(/html/i)!==null:false;}, Number:function(a){return(typeof(a)==="number")?true:(typeof(a)==="object")?a.constructor.toString().match(/Number/)!==null:false;}, Object:function(a){return(typeof(a)==="object")?a.constructor.toString().match(/object/i)!==null:false;}, RegExp:function(a){return(typeof(a)==="function")?a.constructor.toString().match(/regexp/i)!==null:false;} }; var type={ of:function(a){ for(var i in is){ if(is[i](a)){ return i.toLowerCase(); } } } }; /* ********************************************** Begin VMM.Library.js ********************************************** */ /* * LIBRARY ABSTRACTION ================================================== */ if(typeof VMM != 'undefined') { VMM.smoothScrollTo = function(elem, duration, ease) { if( typeof( jQuery ) != 'undefined' ){ var _ease = "easein", _duration = 1000; if (duration != null) { if (duration < 1) { _duration = 1; } else { _duration = Math.round(duration); } } if (ease != null && ease != "") { _ease = ease; } if (jQuery(window).scrollTop() != VMM.Lib.offset(elem).top) { VMM.Lib.animate('html,body', _duration, _ease, {scrollTop: VMM.Lib.offset(elem).top}) } } }; VMM.attachElement = function(element, content) { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).html(content); } }; VMM.appendElement = function(element, content) { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).append(content); } }; VMM.getHTML = function(element) { var e; if( typeof( jQuery ) != 'undefined' ){ e = jQuery(element).html(); return e; } }; VMM.getElement = function(element, p) { var e; if( typeof( jQuery ) != 'undefined' ){ if (p) { e = jQuery(element).parent().get(0); } else { e = jQuery(element).get(0); } return e; } }; VMM.bindEvent = function(element, the_handler, the_event_type, event_data) { var e; var _event_type = "click"; var _event_data = {}; if (the_event_type != null && the_event_type != "") { _event_type = the_event_type; } if (_event_data != null && _event_data != "") { _event_data = event_data; } if( typeof( jQuery ) != 'undefined' ){ jQuery(element).bind(_event_type, _event_data, the_handler); //return e; } }; VMM.unbindEvent = function(element, the_handler, the_event_type) { var e; var _event_type = "click"; var _event_data = {}; if (the_event_type != null && the_event_type != "") { _event_type = the_event_type; } if( typeof( jQuery ) != 'undefined' ){ jQuery(element).unbind(_event_type, the_handler); //return e; } }; VMM.fireEvent = function(element, the_event_type, the_data) { var e; var _event_type = "click"; var _data = []; if (the_event_type != null && the_event_type != "") { _event_type = the_event_type; } if (the_data != null && the_data != "") { _data = the_data; } if( typeof( jQuery ) != 'undefined' ){ jQuery(element).trigger(_event_type, _data); //return e; } }; VMM.getJSON = function(url, data, callback) { if( typeof( jQuery ) != 'undefined' ){ jQuery.ajaxSetup({ timeout: 3000 }); /* CHECK FOR IE ================================================== */ if ( VMM.Browser.browser == "Explorer" && parseInt(VMM.Browser.version, 10) >= 7 && window.XDomainRequest && url.match('^https?://')) { trace("old IE JSON doesn't like retrieving from different protocol"); var colon = url.indexOf(':'); url = url.substr(colon+1); } return jQuery.getJSON(url, data, callback); } } VMM.parseJSON = function(the_json) { if( typeof( jQuery ) != 'undefined' ){ return jQuery.parseJSON(the_json); } } // ADD ELEMENT AND RETURN IT VMM.appendAndGetElement = function(append_to_element, tag, cName, content) { var e, _tag = "
", _class = "", _content = "", _id = ""; if (tag != null && tag != "") { _tag = tag; } if (cName != null && cName != "") { _class = cName; } if (content != null && content != "") { _content = content; } if( typeof( jQuery ) != 'undefined' ){ e = jQuery(tag); e.addClass(_class); e.html(_content); jQuery(append_to_element).append(e); } return e; }; VMM.Lib = { init: function() { return this; }, hide: function(element, duration) { if (duration != null && duration != "") { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).hide(duration); } } else { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).hide(); } } }, remove: function(element) { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).remove(); } }, detach: function(element) { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).detach(); } }, append: function(element, value) { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).append(value); } }, prepend: function(element, value) { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).prepend(value); } }, show: function(element, duration) { if (duration != null && duration != "") { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).show(duration); } } else { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).show(); } } }, load: function(element, callback_function, event_data) { var _event_data = {elem:element}; // return element by default if (_event_data != null && _event_data != "") { _event_data = event_data; } if( typeof( jQuery ) != 'undefined' ){ jQuery(element).load(_event_data, callback_function); } }, addClass: function(element, cName) { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).addClass(cName); } }, removeClass: function(element, cName) { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).removeClass(cName); } }, attr: function(element, aName, value) { if (value != null && value != "") { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).attr(aName, value); } } else { if( typeof( jQuery ) != 'undefined' ){ return jQuery(element).attr(aName); } } }, prop: function(element, aName, value) { if (typeof jQuery == 'undefined' || !/[1-9]\.[3-9].[1-9]/.test(jQuery.fn.jquery)) { VMM.Lib.attribute(element, aName, value); } else { jQuery(element).prop(aName, value); } }, attribute: function(element, aName, value) { if (value != null && value != "") { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).attr(aName, value); } } else { if( typeof( jQuery ) != 'undefined' ){ return jQuery(element).attr(aName); } } }, visible: function(element, show) { if (show != null) { if( typeof( jQuery ) != 'undefined' ){ if (show) { jQuery(element).show(0); } else { jQuery(element).hide(0); } } } else { if( typeof( jQuery ) != 'undefined' ){ if ( jQuery(element).is(':visible')){ return true; } else { return false; } } } }, css: function(element, prop, value) { if (value != null && value != "") { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).css(prop, value); } } else { if( typeof( jQuery ) != 'undefined' ){ return jQuery(element).css(prop); } } }, cssmultiple: function(element, propval) { if( typeof( jQuery ) != 'undefined' ){ return jQuery(element).css(propval); } }, offset: function(element) { var p; if( typeof( jQuery ) != 'undefined' ){ p = jQuery(element).offset(); } return p; }, position: function(element) { var p; if( typeof( jQuery ) != 'undefined' ){ p = jQuery(element).position(); } return p; }, width: function(element, s) { if (s != null && s != "") { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).width(s); } } else { if( typeof( jQuery ) != 'undefined' ){ return jQuery(element).width(); } } }, height: function(element, s) { if (s != null && s != "") { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).height(s); } } else { if( typeof( jQuery ) != 'undefined' ){ return jQuery(element).height(); } } }, toggleClass: function(element, cName) { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).toggleClass(cName); } }, each:function(element, return_function) { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).each(return_function); } }, html: function(element, str) { var e; if( typeof( jQuery ) != 'undefined' ){ e = jQuery(element).html(); return e; } if (str != null && str != "") { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).html(str); } } else { var e; if( typeof( jQuery ) != 'undefined' ){ e = jQuery(element).html(); return e; } } }, find: function(element, selec) { if( typeof( jQuery ) != 'undefined' ){ return jQuery(element).find(selec); } }, stop: function(element) { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).stop(); } }, delay_animate: function(delay, element, duration, ease, att, callback_function) { if (VMM.Browser.device == "mobile" || VMM.Browser.device == "tablet") { var _tdd = Math.round((duration/1500)*10)/10, __duration = _tdd + 's'; VMM.Lib.css(element, '-webkit-transition', 'all '+ __duration + ' ease'); VMM.Lib.css(element, '-moz-transition', 'all '+ __duration + ' ease'); VMM.Lib.css(element, '-o-transition', 'all '+ __duration + ' ease'); VMM.Lib.css(element, '-ms-transition', 'all '+ __duration + ' ease'); VMM.Lib.css(element, 'transition', 'all '+ __duration + ' ease'); VMM.Lib.cssmultiple(element, _att); } else { if( typeof( jQuery ) != 'undefined' ){ jQuery(element).delay(delay).animate(att, {duration:duration, easing:ease} ); } } }, animate: function(element, duration, ease, att, que, callback_function) { var _ease = "easein", _que = false, _duration = 1000, _att = {}; if (duration != null) { if (duration < 1) { _duration = 1; } else { _duration = Math.round(duration); } } if (ease != null && ease != "") { _ease = ease; } if (que != null && que != "") { _que = que; } if (att != null) { _att = att } else { _att = {opacity: 0} } if (VMM.Browser.device == "mobile" || VMM.Browser.device == "tablet") { var _tdd = Math.round((_duration/1500)*10)/10, __duration = _tdd + 's'; _ease = " cubic-bezier(0.33, 0.66, 0.66, 1)"; //_ease = " ease-in-out"; for (x in _att) { if (Object.prototype.hasOwnProperty.call(_att, x)) { trace(x + " to " + _att[x]); VMM.Lib.css(element, '-webkit-transition', x + ' ' + __duration + _ease); VMM.Lib.css(element, '-moz-transition', x + ' ' + __duration + _ease); VMM.Lib.css(element, '-o-transition', x + ' ' + __duration + _ease); VMM.Lib.css(element, '-ms-transition', x + ' ' + __duration + _ease); VMM.Lib.css(element, 'transition', x + ' ' + __duration + _ease); } } VMM.Lib.cssmultiple(element, _att); } else { if( typeof( jQuery ) != 'undefined' ){ if (callback_function != null && callback_function != "") { jQuery(element).animate(_att, {queue:_que, duration:_duration, easing:_ease, complete:callback_function} ); } else { jQuery(element).animate(_att, {queue:_que, duration:_duration, easing:_ease} ); } } } } } } if( typeof( jQuery ) != 'undefined' ){ /* XDR AJAX EXTENTION FOR jQuery https://github.com/jaubourg/ajaxHooks/blob/master/src/ajax/xdr.js ================================================== */ (function( jQuery ) { if ( window.XDomainRequest ) { jQuery.ajaxTransport(function( s ) { if ( s.crossDomain && s.async ) { if ( s.timeout ) { s.xdrTimeout = s.timeout; delete s.timeout; } var xdr; return { send: function( _, complete ) { function callback( status, statusText, responses, responseHeaders ) { xdr.onload = xdr.onerror = xdr.ontimeout = jQuery.noop; xdr = undefined; complete( status, statusText, responses, responseHeaders ); } xdr = new XDomainRequest(); xdr.open( s.type, s.url ); xdr.onload = function() { callback( 200, "OK", { text: xdr.responseText }, "Content-Type: " + xdr.contentType ); }; xdr.onerror = function() { callback( 404, "Not Found" ); }; if ( s.xdrTimeout ) { xdr.ontimeout = function() { callback( 0, "timeout" ); }; xdr.timeout = s.xdrTimeout; } xdr.send( ( s.hasContent && s.data ) || null ); }, abort: function() { if ( xdr ) { xdr.onerror = jQuery.noop(); xdr.abort(); } } }; } }); } })( jQuery ); /* jQuery Easing v1.3 http://gsgd.co.uk/sandbox/jquery/easing/ ================================================== */ jQuery.easing['jswing'] = jQuery.easing['swing']; jQuery.extend( jQuery.easing, { def: 'easeOutQuad', swing: function (x, t, b, c, d) { //alert(jQuery.easing.default); return jQuery.easing[jQuery.easing.def](x, t, b, c, d); }, easeInExpo: function (x, t, b, c, d) { return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; }, easeOutExpo: function (x, t, b, c, d) { return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; }, easeInOutExpo: function (x, t, b, c, d) { if (t==0) return b; if (t==d) return b+c; if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; }, easeInQuad: function (x, t, b, c, d) { return c*(t/=d)*t + b; }, easeOutQuad: function (x, t, b, c, d) { return -c *(t/=d)*(t-2) + b; }, easeInOutQuad: function (x, t, b, c, d) { if ((t/=d/2) < 1) return c/2*t*t + b; return -c/2 * ((--t)*(t-2) - 1) + b; } }); } /* ********************************************** Begin VMM.Browser.js ********************************************** */ /* * DEVICE AND BROWSER DETECTION ================================================== */ if(typeof VMM != 'undefined' && typeof VMM.Browser == 'undefined') { VMM.Browser = { init: function () { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.tridentVersion = this.searchTridentVersion(navigator.userAgent); this.OS = this.searchString(this.dataOS) || "an unknown OS"; this.device = this.searchDevice(navigator.userAgent); this.orientation = this.searchOrientation(window.orientation); }, searchOrientation: function(orientation) { var orient = ""; if ( orientation == 0 || orientation == 180) { orient = "portrait"; } else if ( orientation == 90 || orientation == -90) { orient = "landscape"; } else { orient = "normal"; } return orient; }, searchDevice: function(d) { var device = ""; if (d.match(/Android/i) || d.match(/iPhone|iPod/i)) { device = "mobile"; } else if (d.match(/iPad/i)) { device = "tablet"; } else if (d.match(/BlackBerry/i) || d.match(/IEMobile/i)) { device = "other mobile"; } else { device = "desktop"; } return device; }, searchString: function (data) { for (var i=0;i'mmmm d',' yyyy''", full_long: "mmm d',' yyyy 'at' hh:MM TT", full_long_small_date: "hh:MM TT'
mmm d',' yyyy''" }, month: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], month_abbr: ["Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."], day: ["Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], day_abbr: ["Sun.", "Mon.", "Tues.", "Wed.", "Thurs.", "Fri.", "Sat."], hour: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], hour_suffix: ["am"], //B.C. bc_format: { year: "yyyy", month_short: "mmm", month: "mmmm yyyy", full_short: "mmm d", full: "mmmm d',' yyyy", time_no_seconds_short: "h:MM TT", time_no_seconds_small_date: "dddd', 'h:MM TT'
'mmmm d',' yyyy''", full_long: "dddd',' mmm d',' yyyy 'at' hh:MM TT", full_long_small_date: "hh:MM TT'
'dddd',' mmm d',' yyyy''" }, setLanguage: function(lang) { trace("SET DATE LANGUAGE"); VMM.Date.dateformats = lang.dateformats; VMM.Date.month = lang.date.month; VMM.Date.month_abbr = lang.date.month_abbr; VMM.Date.day = lang.date.day; VMM.Date.day_abbr = lang.date.day_abbr; dateFormat.i18n.dayNames = lang.date.day_abbr.concat(lang.date.day); dateFormat.i18n.monthNames = lang.date.month_abbr.concat(lang.date.month); }, parse: function(d, precision) { "use strict"; var date, date_array, time_array, time_parse, p = { year: false, month: false, day: false, hour: false, minute: false, second: false, millisecond: false }; if (type.of(d) == "date") { trace("DEBUG THIS, ITs A DATE"); date = d; } else { date = new Date(0); date.setMonth(0); date.setDate(1); date.setHours(0); date.setMinutes(0); date.setSeconds(0); date.setMilliseconds(0); if ( d.match(/,/gi) ) { date_array = d.split(","); for(var i = 0; i < date_array.length; i++) { date_array[i] = parseInt(date_array[i], 10); } if (date_array[0]) { date.setFullYear(date_array[0]); p.year = true; } if (date_array[1]) { date.setMonth(date_array[1] - 1); p.month = true; } if (date_array[2]) { date.setDate(date_array[2]); p.day = true; } if (date_array[3]) { date.setHours(date_array[3]); p.hour = true; } if (date_array[4]) { date.setMinutes(date_array[4]); p.minute = true; } if (date_array[5]) { date.setSeconds(date_array[5]); if (date_array[5] >= 1) { p.second = true; } } if (date_array[6]) { date.setMilliseconds(date_array[6]); if (date_array[6] >= 1) { p.millisecond = true; } } } else if (d.match("/")) { if (d.match(" ")) { time_parse = d.split(" "); if (d.match(":")) { time_array = time_parse[1].split(":"); if (time_array[0] >= 0 ) { date.setHours(time_array[0]); p.hour = true; } if (time_array[1] >= 0) { date.setMinutes(time_array[1]); p.minute = true; } if (time_array[2] >= 0) { date.setSeconds(time_array[2]); p.second = true; } if (time_array[3] >= 0) { date.setMilliseconds(time_array[3]); p.millisecond = true; } } date_array = time_parse[0].split("/"); } else { date_array = d.split("/"); } if (date_array[2]) { date.setFullYear(date_array[2]); p.year = true; } if (date_array[0] >= 0) { var month = date_array[0] - 1; date.setMonth(month); // if (date.getMonth() != month) { // date.setMonth(month); // WTF javascript? // } p.month = true; } if (date_array[1] >= 0) { if (date_array[1].length > 2) { date.setFullYear(date_array[1]); p.year = true; } else { date.setDate(date_array[1]); p.day = true; } } } else if (d.match("now")) { var now = new Date(); date.setFullYear(now.getFullYear()); p.year = true; date.setMonth(now.getMonth()); p.month = true; date.setDate(now.getDate()); p.day = true; if (d.match("hours")) { date.setHours(now.getHours()); p.hour = true; } if (d.match("minutes")) { date.setHours(now.getHours()); date.setMinutes(now.getMinutes()); p.hour = true; p.minute = true; } if (d.match("seconds")) { date.setHours(now.getHours()); date.setMinutes(now.getMinutes()); date.setSeconds(now.getSeconds()); p.hour = true; p.minute = true; p.second = true; } if (d.match("milliseconds")) { date.setHours(now.getHours()); date.setMinutes(now.getMinutes()); date.setSeconds(now.getSeconds()); date.setMilliseconds(now.getMilliseconds()); p.hour = true; p.minute = true; p.second = true; p.millisecond = true; } } else if (d.length <= 8) { p.year = true; date.setFullYear(parseInt(d, 10)); date.setMonth(0); date.setDate(1); date.setHours(0); date.setMinutes(0); date.setSeconds(0); date.setMilliseconds(0); } else if (d.match("T")) { if (navigator.userAgent.match(/MSIE\s(?!9.0)/)) { // IE 8 < Won't accept dates with a "-" in them. time_parse = d.split("T"); if (d.match(":")) { time_array = time_parse[1].split(":"); if (time_array[0] >= 1) { date.setHours(time_array[0]); p.hour = true; } if (time_array[1] >= 1) { date.setMinutes(time_array[1]); p.minute = true; } if (time_array[2] >= 1) { date.setSeconds(time_array[2]); if (time_array[2] >= 1) { p.second = true; } } if (time_array[3] >= 1) { date.setMilliseconds(time_array[3]); if (time_array[3] >= 1) { p.millisecond = true; } } } date_array = time_parse[0].split("-"); if (date_array[0]) { date.setFullYear(date_array[0]); p.year = true; } if (date_array[1] >= 0) { date.setMonth(date_array[1] - 1); p.month = true; } if (date_array[2] >= 0) { date.setDate(date_array[2]); p.day = true; } } else { date = new Date(Date.parse(d)); p.year = true; p.month = true; p.day = true; p.hour = true; p.minute = true; if (date.getSeconds() >= 1) { p.second = true; } if (date.getMilliseconds() >= 1) { p.millisecond = true; } } } else { date = new Date( parseInt(d.slice(0,4), 10), parseInt(d.slice(4,6), 10) - 1, parseInt(d.slice(6,8), 10), parseInt(d.slice(8,10), 10), parseInt(d.slice(10,12), 10) ); p.year = true; p.month = true; p.day = true; p.hour = true; p.minute = true; if (date.getSeconds() >= 1) { p.second = true; } if (date.getMilliseconds() >= 1) { p.millisecond = true; } } } if (precision != null && precision != "") { return { date: date, precision: p }; } else { return date; } }, prettyDate: function(d, is_abbr, p, d2) { var _date, _date2, format, bc_check, is_pair = false, bc_original, bc_number, bc_string; if (d2 != null && d2 != "" && typeof d2 != 'undefined') { is_pair = true; trace("D2 " + d2); } if (type.of(d) == "date") { if (type.of(p) == "object") { if (p.millisecond || p.second && d.getSeconds() >= 1) { // YEAR MONTH DAY HOUR MINUTE if (is_abbr){ format = VMM.Date.dateformats.time_short; } else { format = VMM.Date.dateformats.time_short; } } else if (p.minute) { // YEAR MONTH DAY HOUR MINUTE if (is_abbr){ format = VMM.Date.dateformats.time_no_seconds_short; } else { format = VMM.Date.dateformats.time_no_seconds_small_date; } } else if (p.hour) { // YEAR MONTH DAY HOUR if (is_abbr) { format = VMM.Date.dateformats.time_no_seconds_short; } else { format = VMM.Date.dateformats.time_no_seconds_small_date; } } else if (p.day) { // YEAR MONTH DAY if (is_abbr) { format = VMM.Date.dateformats.full_short; } else { format = VMM.Date.dateformats.full; } } else if (p.month) { // YEAR MONTH if (is_abbr) { format = VMM.Date.dateformats.month_short; } else { format = VMM.Date.dateformats.month; } } else if (p.year) { format = VMM.Date.dateformats.year; } else { format = VMM.Date.dateformats.year; } } else { if (d.getMonth() === 0 && d.getDate() == 1 && d.getHours() === 0 && d.getMinutes() === 0 ) { // YEAR ONLY format = VMM.Date.dateformats.year; } else if (d.getDate() <= 1 && d.getHours() === 0 && d.getMinutes() === 0) { // YEAR MONTH if (is_abbr) { format = VMM.Date.dateformats.month_short; } else { format = VMM.Date.dateformats.month; } } else if (d.getHours() === 0 && d.getMinutes() === 0) { // YEAR MONTH DAY if (is_abbr) { format = VMM.Date.dateformats.full_short; } else { format = VMM.Date.dateformats.full; } } else if (d.getMinutes() === 0) { // YEAR MONTH DAY HOUR if (is_abbr) { format = VMM.Date.dateformats.time_no_seconds_short; } else { format = VMM.Date.dateformats.time_no_seconds_small_date; } } else { // YEAR MONTH DAY HOUR MINUTE if (is_abbr){ format = VMM.Date.dateformats.time_no_seconds_short; } else { format = VMM.Date.dateformats.full_long; } } } _date = dateFormat(d, format, false); //_date = "Jan" bc_check = _date.split(" "); // BC TIME SUPPORT for(var i = 0; i < bc_check.length; i++) { if ( parseInt(bc_check[i], 10) < 0 ) { trace("YEAR IS BC"); bc_original = bc_check[i]; bc_number = Math.abs( parseInt(bc_check[i], 10) ); bc_string = bc_number.toString() + " B.C."; _date = _date.replace(bc_original, bc_string); } } if (is_pair) { _date2 = dateFormat(d2, format, false); bc_check = _date2.split(" "); // BC TIME SUPPORT for(var j = 0; j < bc_check.length; j++) { if ( parseInt(bc_check[j], 10) < 0 ) { trace("YEAR IS BC"); bc_original = bc_check[j]; bc_number = Math.abs( parseInt(bc_check[j], 10) ); bc_string = bc_number.toString() + " B.C."; _date2 = _date2.replace(bc_original, bc_string); } } } } else { trace("NOT A VALID DATE?"); trace(d); } if (is_pair) { return _date + " — " + _date2; } else { return _date; } } }).init(); /* * Date Format 1.2.3 * (c) 2007-2009 Steven Levithan * MIT license * * Includes enhancements by Scott Trenda * and Kris Kowal * * Accepts a date, a mask, or a date and a mask. * Returns a formatted version of the given date. * The date defaults to the current date/time. * The mask defaults to dateFormat.masks.default. */ var dateFormat = function () { var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[WLloSZ]|"[^"]*"|'[^']*'/g, timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g, timezoneClip = /[^-+\dA-Z]/g, pad = function (val, len) { val = String(val); len = len || 2; while (val.length < len) val = "0" + val; return val; }; // Regexes and supporting functions are cached through closure return function (date, mask, utc) { var dF = dateFormat; // You can't provide utc if you skip other args (use the "UTC:" mask prefix) if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) { mask = date; date = undefined; } // Passing date through Date applies Date.parse, if necessary // Caused problems in IE // date = date ? new Date(date) : new Date; if (isNaN(date)) { trace("invalid date " + date); //return ""; } mask = String(dF.masks[mask] || mask || dF.masks["default"]); // Allow setting the utc argument via the mask if (mask.slice(0, 4) == "UTC:") { mask = mask.slice(4); utc = true; } var _ = utc ? "getUTC" : "get", d = date[_ + "Date"](), D = date[_ + "Day"](), m = date[_ + "Month"](), y = date[_ + "FullYear"](), H = date[_ + "Hours"](), M = date[_ + "Minutes"](), s = date[_ + "Seconds"](), L = date[_ + "Milliseconds"](), W = date.getWeek(), o = utc ? 0 : date.getTimezoneOffset(), flags = { d: d, dd: pad(d), ddd: dF.i18n.dayNames[D], dddd: dF.i18n.dayNames[D + 7], m: m + 1, mm: pad(m + 1), mmm: dF.i18n.monthNames[m], mmmm: dF.i18n.monthNames[m + 12], yy: String(y).slice(2), yyyy: y, h: H % 12 || 12, hh: pad(H % 12 || 12), H: H, HH: pad(H), M: M, MM: pad(M), s: s, ss: pad(s), l: pad(L, 3), L: pad(L > 99 ? Math.round(L / 10) : L), t: H < 12 ? "a" : "p", tt: H < 12 ? "am" : "pm", T: H < 12 ? "A" : "P", TT: H < 12 ? "AM" : "PM", Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""), o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10], W: W }; return mask.replace(token, function ($0) { return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1); }); }; }(); // Some common format strings dateFormat.masks = { "default": "ddd mmm dd yyyy HH:MM:ss", shortDate: "m/d/yy", mediumDate: "mmm d, yyyy", longDate: "mmmm d, yyyy", fullDate: "dddd, mmmm d, yyyy", shortTime: "h:MM TT", mediumTime: "h:MM:ss TT", longTime: "h:MM:ss TT Z", isoDate: "yyyy-mm-dd", isoTime: "HH:MM:ss", isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" }; // Internationalization strings dateFormat.i18n = { dayNames: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ], monthNames: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] }; // For convenience... Date.prototype.format = function (mask, utc) { return dateFormat(this, mask, utc); }; } /* ********************************************** Begin VMM.Util.js ********************************************** */ /* * Utilities and Useful Functions ================================================== */ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') { VMM.Util = ({ init: function() { return this; }, removeRange: function(array, from, to) { // rather than change Array.prototype; Thanks Jeff McWhirter for nudge var rest = array.slice((to || from) + 1 || array.length); array.length = from < 0 ? array.length + from : from; return array.push.apply(array, rest); }, /* * CORRECT PROTOCOL (DOES NOT WORK) ================================================== */ correctProtocol: function(url) { var loc = (window.parent.location.protocol).toString(), prefix = "", the_url = url.split("://", 2); if (loc.match("http")) { prefix = loc; } else { prefix = "https"; } return prefix + "://" + the_url[1]; }, /* * MERGE CONFIG ================================================== */ mergeConfig: function(config_main, config_to_merge) { var x; for (x in config_to_merge) { if (Object.prototype.hasOwnProperty.call(config_to_merge, x)) { config_main[x] = config_to_merge[x]; } } return config_main; }, /* * GET OBJECT ATTRIBUTE BY INDEX ================================================== */ getObjectAttributeByIndex: function(obj, index) { if(typeof obj != 'undefined') { var i = 0; for (var attr in obj){ if (index === i){ return obj[attr]; } i++; } return ""; } else { return ""; } }, /* * ORDINAL ================================================== */ ordinal: function(n) { return ["th","st","nd","rd"][(!( ((n%10) >3) || (Math.floor(n%100/10)==1)) ) * (n%10)]; }, /* * RANDOM BETWEEN ================================================== */ //VMM.Util.randomBetween(1, 3) randomBetween: function(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); }, /* * AVERAGE * http://jsfromhell.com/array/average * var x = VMM.Util.average([2, 3, 4]); * VMM.Util.average([2, 3, 4]).mean ================================================== */ average: function(a) { var r = {mean: 0, variance: 0, deviation: 0}, t = a.length; for(var m, s = 0, l = t; l--; s += a[l]); for(m = r.mean = s / t, l = t, s = 0; l--; s += Math.pow(a[l] - m, 2)); return r.deviation = Math.sqrt(r.variance = s / t), r; }, /* * CUSTOM SORT ================================================== */ customSort: function(a, b) { var a1= a, b1= b; if(a1== b1) return 0; return a1> b1? 1: -1; }, /* * Remove Duplicates from Array ================================================== */ deDupeArray: function(arr) { var i, len=arr.length, out=[], obj={}; for (i=0;i h) { _fit.height = h; //_fit.width = Math.round((w / ratio_w) * ratio_h); _fit.width = Math.round((h / ratio_h) * ratio_w); if (_fit.width > w) { trace("FIT: DIDN'T FIT!!! ") } } return _fit; }, r16_9: function(w,h) { //VMM.Util.ratio.r16_9(w, h) // Returns corresponding number if (w !== null && w !== "") { return Math.round((h / 16) * 9); } else if (h !== null && h !== "") { return Math.round((w / 9) * 16); } }, r4_3: function(w,h) { if (w !== null && w !== "") { return Math.round((h / 4) * 3); } else if (h !== null && h !== "") { return Math.round((w / 3) * 4); } } }, doubledigit: function(n) { return (n < 10 ? '0' : '') + n; }, /* * Returns a truncated segement of a long string of between min and max words. If possible, ends on a period (otherwise goes to max). ================================================== */ truncateWords: function(s, min, max) { if (!min) min = 30; if (!max) max = min; var initial_whitespace_rExp = /^[^A-Za-z0-9\'\-]+/gi; var left_trimmedStr = s.replace(initial_whitespace_rExp, ""); var words = left_trimmedStr.split(" "); var result = []; min = Math.min(words.length, min); max = Math.min(words.length, max); for (var i = 0; i$&") .replace(pseudoUrlPattern, "$1$2") .replace(emailAddressPattern, "$1"); }, linkify_with_twitter: function(text,targets,is_touch) { // http://, https://, ftp:// var urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim; var url_pattern = /(\()((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\))|(\[)((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\])|(\{)((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\})|(<|&(?:lt|#60|#x3c);)((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(>|&(?:gt|#62|#x3e);)|((?:^|[^=\s'"\]])\s*['"]?|[^=\s]\s+)(\b(?:ht|f)tps?:\/\/[a-z0-9\-._~!$'()*+,;=:\/?#[\]@%]+(?:(?!&(?:gt|#0*62|#x0*3e);|&(?:amp|apos|quot|#0*3[49]|#x0*2[27]);[.!&',:?;]?(?:[^a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]|$))&[a-z0-9\-._~!$'()*+,;=:\/?#[\]@%]*)*[a-z0-9\-_~$()*+=\/#[\]@%])/img; var url_replace = '$1$4$7$10$13$2$5$8$11$14$3$6$9$12'; // www. sans http:// or https:// var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim; function replaceURLWithHTMLLinks(text) { var exp = /(\b(https?|ftp|file):\/\/([-A-Z0-9+&@#%?=~_|!:,.;]*)([-A-Z0-9+&@#%?\/=~_|!:,.;]*)[-A-Z0-9+&@#\/%=~_|])/ig; return text.replace(exp, "$3"); } // Email addresses var emailAddressPattern = /([a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)/gim; //var twitterHandlePattern = /(@([\w]+))/g; var twitterHandlePattern = /\B@([\w-]+)/gm; var twitterSearchPattern = /(#([\w]+))/g; return text //.replace(urlPattern, "$&") .replace(url_pattern, url_replace) .replace(pseudoUrlPattern, "$1$2") .replace(emailAddressPattern, "$1") .replace(twitterHandlePattern, "@$1"); // TURN THIS BACK ON TO AUTOMAGICALLY LINK HASHTAGS TO TWITTER SEARCH //.replace(twitterSearchPattern, "$1"); }, linkify_wikipedia: function(text) { var urlPattern = /]*>(.*?)<\/i>/gim; return text .replace(urlPattern, "$&") .replace(/]*>/gim, "") .replace(/<\/i>/gim, "") .replace(/]*>/gim, "") .replace(/<\/b>/gim, ""); }, /* * Turns plain text links into real links ================================================== */ // VMM.Util.unlinkify(); unlinkify: function(text) { if(!text) return text; text = text.replace(/]*>/i,""); text = text.replace(/<\/a>/i, ""); return text; }, untagify: function(text) { if (!text) { return text; } text = text.replace(/<\/?\s*\w.*?>/g,""); return text; }, /* * TK ================================================== */ nl2br: function(text) { return text.replace(/(\r\n|[\r\n]|\\n|\\r)/g,"
"); }, /* * Generate a Unique ID ================================================== */ // VMM.Util.unique_ID(size); unique_ID: function(size) { var getRandomNumber = function(range) { return Math.floor(Math.random() * range); }; var getRandomChar = function() { var chars = "abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ"; return chars.substr( getRandomNumber(62), 1 ); }; var randomID = function(size) { var str = ""; for(var i = 0; i < size; i++) { str += getRandomChar(); } return str; }; return randomID(size); }, /* * Tells you if a number is even or not ================================================== */ // VMM.Util.isEven(n) isEven: function(n){ return (n%2 === 0) ? true : false; }, /* * Get URL Variables ================================================== */ // var somestring = VMM.Util.getUrlVars(str_url)["varname"]; getUrlVars: function(string) { var str = string.toString(); if (str.match('&')) { str = str.replace("&", "&"); } else if (str.match('&')) { str = str.replace("&", "&"); } else if (str.match('&')) { str = str.replace("&", "&"); } var vars = [], hash; var hashes = str.slice(str.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; }, /* * Cleans up strings to become real HTML ================================================== */ toHTML: function(text) { text = this.nl2br(text); text = this.linkify(text); return text.replace(/\s\s/g,"  "); }, /* * Returns text strings as CamelCase ================================================== */ toCamelCase: function(s,forceLowerCase) { if(forceLowerCase !== false) forceLowerCase = true; var sps = ((forceLowerCase) ? s.toLowerCase() : s).split(" "); for(var i=0; i 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; }, /* * Transform text to Title Case ================================================== */ toTitleCase: function(t){ if ( VMM.Browser.browser == "Explorer" && parseInt(VMM.Browser.version, 10) >= 7) { return t.replace("_", "%20"); } else { var __TitleCase = { __smallWords: ['a', 'an', 'and', 'as', 'at', 'but','by', 'en', 'for', 'if', 'in', 'of', 'on', 'or','the', 'to', 'v[.]?', 'via', 'vs[.]?'], init: function() { this.__smallRE = this.__smallWords.join('|'); this.__lowerCaseWordsRE = new RegExp('\\b(' + this.__smallRE + ')\\b', 'gi'); this.__firstWordRE = new RegExp('^([^a-zA-Z0-9 \\r\\n\\t]*)(' + this.__smallRE + ')\\b', 'gi'); this.__lastWordRE = new RegExp('\\b(' + this.__smallRE + ')([^a-zA-Z0-9 \\r\\n\\t]*)$', 'gi'); }, toTitleCase: function(string) { var line = ''; var split = string.split(/([:.;?!][ ]|(?:[ ]|^)["“])/); for (var i = 0; i < split.length; ++i) { var s = split[i]; s = s.replace(/\b([a-zA-Z][a-z.'’]*)\b/g,this.__titleCaseDottedWordReplacer); // lowercase the list of small words s = s.replace(this.__lowerCaseWordsRE, this.__lowerReplacer); // if the first word in the title is a small word then capitalize it s = s.replace(this.__firstWordRE, this.__firstToUpperCase); // if the last word in the title is a small word, then capitalize it s = s.replace(this.__lastWordRE, this.__firstToUpperCase); line += s; } // special cases line = line.replace(/ V(s?)\. /g, ' v$1. '); line = line.replace(/(['’])S\b/g, '$1s'); line = line.replace(/\b(AT&T|Q&A)\b/ig, this.__upperReplacer); return line; }, __titleCaseDottedWordReplacer: function (w) { return (w.match(/[a-zA-Z][.][a-zA-Z]/)) ? w : __TitleCase.__firstToUpperCase(w); }, __lowerReplacer: function (w) { return w.toLowerCase() }, __upperReplacer: function (w) { return w.toUpperCase() }, __firstToUpperCase: function (w) { var split = w.split(/(^[^a-zA-Z0-9]*[a-zA-Z0-9])(.*)$/); if (split[1]) { split[1] = split[1].toUpperCase(); } return split.join(''); } }; __TitleCase.init(); t = t.replace(/_/g," "); t = __TitleCase.toTitleCase(t); return t; } } }).init(); } /* ********************************************** Begin LazyLoad.js ********************************************** */ /*jslint browser: true, eqeqeq: true, bitwise: true, newcap: true, immed: true, regexp: false */ /* LazyLoad makes it easy and painless to lazily load one or more external JavaScript or CSS files on demand either during or after the rendering of a web page. Supported browsers include Firefox 2+, IE6+, Safari 3+ (including Mobile Safari), Google Chrome, and Opera 9+. Other browsers may or may not work and are not officially supported. Visit https://github.com/rgrove/lazyload/ for more info. Copyright (c) 2011 Ryan Grove All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @module lazyload @class LazyLoad @static @version 2.0.3 (git) */ LazyLoad = (function (doc) { // -- Private Variables ------------------------------------------------------ // User agent and feature test information. var env, // Reference to the element (populated lazily). head, // Requests currently in progress, if any. pending = {}, // Number of times we've polled to check whether a pending stylesheet has // finished loading. If this gets too high, we're probably stalled. pollCount = 0, // Queued requests. queue = {css: [], js: []}, // Reference to the browser's list of stylesheets. styleSheets = doc.styleSheets; // -- Private Methods -------------------------------------------------------- /** Creates and returns an HTML element with the specified name and attributes. @method createNode @param {String} name element name @param {Object} attrs name/value mapping of element attributes @return {HTMLElement} @private */ function createNode(name, attrs) { var node = doc.createElement(name), attr; for (attr in attrs) { if (attrs.hasOwnProperty(attr)) { node.setAttribute(attr, attrs[attr]); } } return node; } /** Called when the current pending resource of the specified type has finished loading. Executes the associated callback (if any) and loads the next resource in the queue. @method finish @param {String} type resource type ('css' or 'js') @private */ function finish(type) { var p = pending[type], callback, urls; if (p) { callback = p.callback; urls = p.urls; urls.shift(); pollCount = 0; // If this is the last of the pending URLs, execute the callback and // start the next request in the queue (if any). if (!urls.length) { callback && callback.call(p.context, p.obj); pending[type] = null; queue[type].length && load(type); } } } /** Populates the env variable with user agent and feature test information. @method getEnv @private */ function getEnv() { var ua = navigator.userAgent; env = { // True if this browser supports disabling async mode on dynamically // created script nodes. See // http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order async: doc.createElement('script').async === true }; (env.webkit = /AppleWebKit\//.test(ua)) || (env.ie = /MSIE/.test(ua)) || (env.opera = /Opera/.test(ua)) || (env.gecko = /Gecko\//.test(ua)) || (env.unknown = true); } /** Loads the specified resources, or the next resource of the specified type in the queue if no resources are specified. If a resource of the specified type is already being loaded, the new request will be queued until the first request has been finished. When an array of resource URLs is specified, those URLs will be loaded in parallel if it is possible to do so while preserving execution order. All browsers support parallel loading of CSS, but only Firefox and Opera support parallel loading of scripts. In other browsers, scripts will be queued and loaded one at a time to ensure correct execution order. @method load @param {String} type resource type ('css' or 'js') @param {String|Array} urls (optional) URL or array of URLs to load @param {Function} callback (optional) callback function to execute when the resource is loaded @param {Object} obj (optional) object to pass to the callback function @param {Object} context (optional) if provided, the callback function will be executed in this object's context @private */ function load(type, urls, callback, obj, context) { var _finish = function () { finish(type); }, isCSS = type === 'css', nodes = [], i, len, node, p, pendingUrls, url; env || getEnv(); if (urls) { // If urls is a string, wrap it in an array. Otherwise assume it's an // array and create a copy of it so modifications won't be made to the // original. urls = typeof urls === 'string' ? [urls] : urls.concat(); // Create a request object for each URL. If multiple URLs are specified, // the callback will only be executed after all URLs have been loaded. // // Sadly, Firefox and Opera are the only browsers capable of loading // scripts in parallel while preserving execution order. In all other // browsers, scripts must be loaded sequentially. // // All browsers respect CSS specificity based on the order of the link // elements in the DOM, regardless of the order in which the stylesheets // are actually downloaded. if (isCSS || env.async || env.gecko || env.opera) { // Load in parallel. queue[type].push({ urls : urls, callback: callback, obj : obj, context : context }); } else { // Load sequentially. for (i = 0, len = urls.length; i < len; ++i) { queue[type].push({ urls : [urls[i]], callback: i === len - 1 ? callback : null, // callback is only added to the last URL obj : obj, context : context }); } } } // If a previous load request of this type is currently in progress, we'll // wait our turn. Otherwise, grab the next item in the queue. if (pending[type] || !(p = pending[type] = queue[type].shift())) { return; } head || (head = doc.head || doc.getElementsByTagName('head')[0]); pendingUrls = p.urls; for (i = 0, len = pendingUrls.length; i < len; ++i) { url = pendingUrls[i]; if (isCSS) { node = env.gecko ? createNode('style') : createNode('link', { href: url, rel : 'stylesheet' }); } else { node = createNode('script', {src: url}); node.async = false; } node.className = 'lazyload'; node.setAttribute('charset', 'utf-8'); if (env.ie && !isCSS) { node.onreadystatechange = function () { if (/loaded|complete/.test(node.readyState)) { node.onreadystatechange = null; _finish(); } }; } else if (isCSS && (env.gecko || env.webkit)) { // Gecko and WebKit don't support the onload event on link nodes. if (env.webkit) { // In WebKit, we can poll for changes to document.styleSheets to // figure out when stylesheets have loaded. p.urls[i] = node.href; // resolve relative URLs (or polling won't work) pollWebKit(); } else { // In Gecko, we can import the requested URL into a