///#source 1 1 /src/1.0.0/core.js /*! head.core - v1.0.2 */ /* * headjs the only script in your * author tero piirainen (tipiirai) * maintainer robert hoffmann (itechnology) * license mit / http://bit.ly/mit-license * website http://headjs.com */ (function (win, undefined) { "use strict"; // gt, gte, lt, lte, eq breakpoints would have been more simple to write as ['gt','gte','lt','lte','eq'] // but then we would have had to loop over the collection on each resize() event, // a simple object with a direct access to true/false is therefore much more efficient var doc = win.document, nav = win.navigator, loc = win.location, html = doc.documentelement, klass = [], conf = { screens: [240, 320, 480, 640, 768, 800, 1024, 1280, 1440, 1680, 1920], screenscss: {"gt": true, "gte": false, "lt": true, "lte": false, "eq": false}, browsers: [ {ie: {min: 6, max: 11}} //,{ chrome : { min: 8, max: 33 } } //,{ ff : { min: 3, max: 26 } } //,{ ios : { min: 3, max: 7 } } //,{ android: { min: 2, max: 4 } } //,{ webkit : { min: 9, max: 12 } } //,{ opera : { min: 9, max: 12 } } ], browsercss: {"gt": true, "gte": false, "lt": true, "lte": false, "eq": true}, html5: true, page: "-page", section: "-section", head: "head" }; if (win.head_conf) { for (var item in win.head_conf) { if (win.head_conf[item] !== undefined) { conf[item] = win.head_conf[item]; } } } function pushclass(name) { klass[klass.length] = name; } function removeclass(name) { // need to test for both space and no space // https://github.com/headjs/headjs/issues/270 // https://github.com/headjs/headjs/issues/226 var re = new regexp(" ?\\b" + name + "\\b"); html.classname = html.classname.replace(re, ""); } function each(arr, fn) { for (var i = 0, l = arr.length; i < l; i++) { fn.call(arr, arr[i], i); } } // api var api = win[conf.head] = function () { api.ready.apply(null, arguments); }; api.feature = function (key, enabled, queue) { // internal: apply all classes if (!key) { html.classname += " " + klass.join(" "); klass = []; return api; } if (object.prototype.tostring.call(enabled) === "[object function]") { enabled = enabled.call(); } pushclass((enabled ? "" : "no-") + key); api[key] = !!enabled; // apply class to html element if (!queue) { removeclass("no-" + key); removeclass(key); api.feature(); } return api; }; // no queue here, so we can remove any eventual pre-existing no-js class api.feature("js", true); // browser type & version var ua = nav.useragent.tolowercase(), mobile = /mobile|android|kindle|silk|midp|phone|(windows .+arm|touch)/.test(ua); // useful for enabling/disabling feature (we can consider a desktop navigator to have more cpu/gpu power) api.feature("mobile", mobile, true); api.feature("desktop", !mobile, true); // http://www.zytrax.com/tech/web/browser_ids.htm // http://www.zytrax.com/tech/web/mobile_ids.html ua = /(chrome|firefox)[ \/]([\w.]+)/.exec(ua) || // chrome & firefox /(iphone|ipad|ipod)(?:.*version)?[ \/]([\w.]+)/.exec(ua) || // mobile ios /(android)(?:.*version)?[ \/]([\w.]+)/.exec(ua) || // mobile webkit /(webkit|opera)(?:.*version)?[ \/]([\w.]+)/.exec(ua) || // safari & opera /(msie) ([\w.]+)/.exec(ua) || /(trident).+rv:(\w.)+/.exec(ua) || []; var browser = ua[1], version = parsefloat(ua[2]); switch (browser) { case "msie": case "trident": browser = "ie"; version = doc.documentmode || version; break; case "firefox": browser = "ff"; break; case "ipod": case "ipad": case "iphone": browser = "ios"; break; case "webkit": browser = "safari"; break; } // browser vendor and version api.browser = { name: browser, version: version }; api.browser[browser] = true; for (var i = 0, l = conf.browsers.length; i < l; i++) { for (var key in conf.browsers[i]) { if (browser === key) { pushclass(key); var min = conf.browsers[i][key].min; var max = conf.browsers[i][key].max; for (var v = min; v <= max; v++) { if (version > v) { if (conf.browsercss.gt) { pushclass("gt-" + key + v); } if (conf.browsercss.gte) { pushclass("gte-" + key + v); } } else if (version < v) { if (conf.browsercss.lt) { pushclass("lt-" + key + v); } if (conf.browsercss.lte) { pushclass("lte-" + key + v); } } else if (version === v) { if (conf.browsercss.lte) { pushclass("lte-" + key + v); } if (conf.browsercss.eq) { pushclass("eq-" + key + v); } if (conf.browsercss.gte) { pushclass("gte-" + key + v); } } } } else { pushclass("no-" + key); } } } pushclass(browser); pushclass(browser + parseint(version, 10)); // ie lt9 specific if (conf.html5 && browser === "ie" && version < 9) { // html5 support : you still need to add html5 css initialization styles to your site // see: assets/html5.css each("abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|main|mark|meter|nav|output|progress|section|summary|time|video".split("|"), function (el) { doc.createelement(el); }); } // css "router" each(loc.pathname.split("/"), function (el, i) { if (this.length > 2 && this[i + 1] !== undefined) { if (i) { pushclass(this.slice(i, i + 1).join("-").tolowercase() + conf.section); } } else { // pageid var id = el || "index", index = id.indexof("."); if (index > 0) { id = id.substring(0, index); } html.id = id.tolowercase() + conf.page; // on root? if (!i) { pushclass("root" + conf.section); } } }); // basic screen info api.screen = { height: win.screen.height, width: win.screen.width }; // viewport resolutions: w-100, lt-480, lt-1024 ... function screensize() { // remove earlier sizes html.classname = html.classname.replace(/ (w-|eq-|gt-|gte-|lt-|lte-|portrait|no-portrait|landscape|no-landscape)\d+/g, ""); // viewport width var iw = win.innerwidth || html.clientwidth, ow = win.outerwidth || win.screen.width; api.screen.innerwidth = iw; api.screen.outerwidth = ow; // for debugging purposes, not really useful for anything else pushclass("w-" + iw); each(conf.screens, function (width) { if (iw > width) { if (conf.screenscss.gt) { pushclass("gt-" + width); } if (conf.screenscss.gte) { pushclass("gte-" + width); } } else if (iw < width) { if (conf.screenscss.lt) { pushclass("lt-" + width); } if (conf.screenscss.lte) { pushclass("lte-" + width); } } else if (iw === width) { if (conf.screenscss.lte) { pushclass("lte-" + width); } if (conf.screenscss.eq) { pushclass("e-q" + width); } if (conf.screenscss.gte) { pushclass("gte-" + width); } } }); // viewport height var ih = win.innerheight || html.clientheight, oh = win.outerheight || win.screen.height; api.screen.innerheight = ih; api.screen.outerheight = oh; // no need for onchange event to detect this api.feature("portrait", (ih > iw)); api.feature("landscape", (ih < iw)); } screensize(); // throttle navigators from triggering too many resize events var resizeid = 0; function onresize() { win.cleartimeout(resizeid); resizeid = win.settimeout(screensize, 50); } // manually attach, as to not overwrite existing handler if (win.addeventlistener) { win.addeventlistener("resize", onresize, false); } else { // ie8 and less win.attachevent("onresize", onresize); } }(window)); ///#source 1 1 /src/1.0.0/css3.js /*! head.css3 - v1.0.0 */ /* * headjs the only script in your * author tero piirainen (tipiirai) * maintainer robert hoffmann (itechnology) * license mit / http://bit.ly/mit-license * website http://headjs.com */ (function (win, undefined) { "use strict"; var doc = win.document, /* to add a new test: head.feature("video", function() { var tag = document.createelement('video'); return !!tag.canplaytype; }); good place to grab more tests https://github.com/modernizr/modernizr/blob/master/modernizr.js */ /* css modernizer */ el = doc.createelement("i"), style = el.style, prefs = " -o- -moz- -ms- -webkit- -khtml- ".split(" "), domprefs = "webkit moz o ms khtml".split(" "), headvar = win.head_conf && win.head_conf.head || "head", api = win[headvar]; // thanks paul irish! function testprops(props) { for (var i in props) { if (style[props[i]] !== undefined) { return true; } } return false; } function testall(prop) { var camel = prop.charat(0).touppercase() + prop.substr(1), props = (prop + " " + domprefs.join(camel + " ") + camel).split(" "); return !!testprops(props); } var tests = { // should we seperate linear/radial ? // seems like some browsers need a test for prefix http://caniuse.com/#feat=css-gradients gradient: function () { var s1 = "background-image:", s2 = "gradient(linear,left top,right bottom,from(#9f9),to(#fff));", s3 = "linear-gradient(left top,#eee,#fff);"; style.csstext = (s1 + prefs.join(s2 + s1) + prefs.join(s3 + s1)).slice(0, -s1.length); return !!style.backgroundimage; }, rgba: function () { style.csstext = "background-color:rgba(0,0,0,0.5)"; return !!style.backgroundcolor; }, opacity: function () { return el.style.opacity === ""; }, textshadow: function () { return style.textshadow === ""; }, multiplebgs: function () { style.csstext = "background:url(https://),url(https://),red url(https://)"; // if the ua supports multiple backgrounds, there should be three occurrences // of the string "url(" in the return value for elemstyle.background var result = (style.background || "").match(/url/g); return object.prototype.tostring.call(result) === "[object array]" && result.length === 3; }, boxshadow: function () { return testall("boxshadow"); }, borderimage: function () { return testall("borderimage"); }, borderradius: function () { return testall("borderradius"); }, cssreflections: function () { return testall("boxreflect"); }, csstransforms: function () { return testall("transform"); }, csstransitions: function () { return testall("transition"); }, touch: function () { return "ontouchstart" in win; }, retina: function () { return (win.devicepixelratio > 1); }, /* font-face support. uses browser sniffing but is synchronous. http://paulirish.com/2009/font-face-feature-detection/ */ fontface: function () { var browser = api.browser.name, version = api.browser.version; switch (browser) { case "ie": return version >= 9; case "chrome": return version >= 13; case "ff": return version >= 6; case "ios": return version >= 5; case "android": return false; case "webkit": return version >= 5.1; case "opera": return version >= 10; default: return false; } } }; // queue features for (var key in tests) { if (tests[key]) { api.feature(key, tests[key].call(), true); } } // enable features at once api.feature(); }(window)); ///#source 1 1 /src/1.0.0/load.js /*! head.load - v1.0.3 */ /* * headjs the only script in your * author tero piirainen (tipiirai) * maintainer robert hoffmann (itechnology) * license mit / http://bit.ly/mit-license * website http://headjs.com */ (function (win, undefined) { "use strict"; //#region variables var doc = win.document, domwaiters = [], handlers = {}, // user functions waiting for events assets = {}, // loadable items in various states isasync = "async" in doc.createelement("script") || "mozappearance" in doc.documentelement.style || win.opera, isdomready, /*** public api ***/ headvar = win.head_conf && win.head_conf.head || "wind", api = win[headvar] = (win[headvar] || function () { api.ready.apply(null, arguments); }), // states preloading = 1, preloaded = 2, loading = 3, loaded = 4; //#endregion //#region private functions //#region helper functions function noop() { // does nothing } function each(arr, callback) { if (!arr) { return; } // arguments special type if (typeof arr === "object") { arr = [].slice.call(arr); } // do the job for (var i = 0, l = arr.length; i < l; i++) { callback.call(arr, arr[i], i); } } /* a must read: http://bonsaiden.github.com/javascript-garden ************************************************************/ function is(type, obj) { var clas = object.prototype.tostring.call(obj).slice(8, -1); return obj !== undefined && obj !== null && clas === type; } function isfunction(item) { return is("function", item); } function isarray(item) { return is("array", item); } function tolabel(url) { ///converts a url to a file label var items = url.split("/"), name = items[items.length - 1], i = name.indexof("?"); return i !== -1 ? name.substring(0, i) : name; } // info: this look like a "im triggering callbacks all over the place, but only wanna run it one time function" ..should try to make everything work without it if possible // info: even better. look into promises/defered's like jquery is doing function one(callback) { ///execute a callback only once callback = callback || noop; if (callback._done) { return; } callback(); callback._done = 1; } //#endregion function conditional(test, success, failure, callback) { /// /// info: use cases: /// head.test(condition, null , "file.nok" , callback); /// head.test(condition, "fileok.js", null , callback); /// head.test(condition, "fileok.js", "file.nok" , callback); /// head.test(condition, "fileok.js", ["file.nok", "file.nok"], callback); /// head.test({ /// test : condition, /// success : [{ label1: "file1ok.js" }, { label2: "file2ok.js" }], /// failure : [{ label1: "file1nok.js" }, { label2: "file2nok.js" }], /// callback: callback /// ); /// head.test({ /// test : condition, /// success : ["file1ok.js" , "file2ok.js"], /// failure : ["file1nok.js", "file2nok.js"], /// callback: callback /// ); /// var obj = (typeof test === "object") ? test : { test: test, success: !!success ? isarray(success) ? success : [success] : false, failure: !!failure ? isarray(failure) ? failure : [failure] : false, callback: callback || noop }; // test passed ? var passed = !!obj.test; // do we have a success case if (passed && !!obj.success) { obj.success.push(obj.callback); api.load.apply(null, obj.success); } // do we have a fail case else if (!passed && !!obj.failure) { obj.failure.push(obj.callback); api.load.apply(null, obj.failure); } else { callback(); } return api; } function getasset(item) { /// /// assets are in the form of /// { /// name : label, /// url : url, /// state: state /// } /// var asset = {}; if (typeof item === "object") { for (var label in item) { if (!!item[label]) { asset = { name: label, url: item[label] }; } } } else { asset = { name: tolabel(item), url: item }; } // is the item already existant var existing = assets[asset.name]; if (existing && existing.url === asset.url) { return existing; } assets[asset.name] = asset; return asset; } function allloaded(items) { items = items || assets; for (var name in items) { if (items.hasownproperty(name) && items[name].state !== loaded) { return false; } } return true; } function onpreload(asset) { asset.state = preloaded; each(asset.onpreload, function (afterpreload) { afterpreload.call(); }); } function preload(asset, callback) { if (asset.state === undefined) { asset.state = preloading; asset.onpreload = []; loadasset({url: asset.url, type: "cache"}, function () { onpreload(asset); }); } } function apiloadhack() { /// preload with text/cache hack /// /// head.load("http://domain.com/file.js","http://domain.com/file.js", callback) /// head.load(["http://domain.com/file.js","http://domain.com/file.js"], callback) /// head.load({ label1: "http://domain.com/file.js" }, { label2: "http://domain.com/file.js" }, callback) /// head.load([{ label1: "http://domain.com/file.js" }, { label2: "http://domain.com/file.js" }], callback) /// var args = arguments, callback = args[args.length - 1], rest = [].slice.call(args, 1), next = rest[0]; if (!isfunction(callback)) { callback = null; } // if array, repush as args if (isarray(args[0])) { args[0].push(callback); api.load.apply(null, args[0]); return api; } // multiple arguments if (!!next) { /* preload with text/cache hack (not good!) * http://blog.getify.com/on-script-loaders/ * http://www.nczonline.net/blog/2010/12/21/thoughts-on-script-loaders/ * if caching is not configured correctly on the server, then items could load twice ! *************************************************************************************/ each(rest, function (item) { // item is not a callback or empty string if (!isfunction(item) && !!item) { preload(getasset(item)); } }); // execute load(getasset(args[0]), isfunction(next) ? next : function () { api.load.apply(null, rest); }); } else { // single item load(getasset(args[0])); } return api; } function apiloadasync() { /// /// simply load and let browser take care of ordering /// /// head.load("http://domain.com/file.js","http://domain.com/file.js", callback) /// head.load(["http://domain.com/file.js","http://domain.com/file.js"], callback) /// head.load({ label1: "http://domain.com/file.js" }, { label2: "http://domain.com/file.js" }, callback) /// head.load([{ label1: "http://domain.com/file.js" }, { label2: "http://domain.com/file.js" }], callback) /// var args = arguments, callback = args[args.length - 1], items = {}; if (!isfunction(callback)) { callback = null; } // if array, repush as args if (isarray(args[0])) { args[0].push(callback); api.load.apply(null, args[0]); return api; } // jrh 262#issuecomment-26288601 // first populate the items array. // when allloaded is called, all items will be populated. // issue when lazy loaded, the callback can execute early. each(args, function (item, i) { if (item !== callback) { item = getasset(item); items[item.name] = item; } }); each(args, function (item, i) { if (item !== callback) { item = getasset(item); load(item, function () { if (allloaded(items)) { one(callback); } }); } }); return api; } function load(asset, callback) { ///used with normal loading logic callback = callback || noop; if (asset.state === loaded) { callback(); return; } // info: why would we trigger a ready event when its not really loaded yet ? if (asset.state === loading) { api.ready(asset.name, callback); return; } if (asset.state === preloading) { asset.onpreload.push(function () { load(asset, callback); }); return; } asset.state = loading; loadasset(asset, function () { asset.state = loaded; callback(); // handlers for this asset each(handlers[asset.name], function (fn) { one(fn); }); // dom is ready & no assets are queued for loading // info: shouldn't we be doing the same test above ? if (isdomready && allloaded()) { each(handlers.all, function (fn) { one(fn); }); } }); } function getextension(url) { url = url || ""; var items = url.split("?")[0].split("."); return items[items.length - 1].tolowercase(); } /* parts inspired from: https://github.com/cujojs/curl ******************************************************/ function loadasset(asset, callback) { callback = callback || noop; function error(event) { event = event || win.event; // release event listeners ele.onload = ele.onreadystatechange = ele.onerror = null; // do callback callback(); // need some more detailed error handling here } function process(event) { event = event || win.event; // ie 7/8 (2 events on 1st load) // 1) event.type = readystatechange, s.readystate = loading // 2) event.type = readystatechange, s.readystate = loaded // ie 7/8 (1 event on reload) // 1) event.type = readystatechange, s.readystate = complete // event.type === 'readystatechange' && /loaded|complete/.test(s.readystate) // ie 9 (3 events on 1st load) // 1) event.type = readystatechange, s.readystate = loading // 2) event.type = readystatechange, s.readystate = loaded // 3) event.type = load , s.readystate = loaded // ie 9 (2 events on reload) // 1) event.type = readystatechange, s.readystate = complete // 2) event.type = load , s.readystate = complete // event.type === 'load' && /loaded|complete/.test(s.readystate) // event.type === 'readystatechange' && /loaded|complete/.test(s.readystate) // ie 10 (3 events on 1st load) // 1) event.type = readystatechange, s.readystate = loading // 2) event.type = load , s.readystate = complete // 3) event.type = readystatechange, s.readystate = loaded // ie 10 (3 events on reload) // 1) event.type = readystatechange, s.readystate = loaded // 2) event.type = load , s.readystate = complete // 3) event.type = readystatechange, s.readystate = complete // event.type === 'load' && /loaded|complete/.test(s.readystate) // event.type === 'readystatechange' && /complete/.test(s.readystate) // other browsers (1 event on 1st load) // 1) event.type = load, s.readystate = undefined // other browsers (1 event on reload) // 1) event.type = load, s.readystate = undefined // event.type == 'load' && s.readystate = undefined // !doc.documentmode is for ie6/7, ie8+ have documentmode if (event.type === "load" || (/loaded|complete/.test(ele.readystate) && (!doc.documentmode || doc.documentmode < 9))) { // remove timeouts win.cleartimeout(asset.errortimeout); win.cleartimeout(asset.csstimeout); // release event listeners ele.onload = ele.onreadystatechange = ele.onerror = null; // do callback callback(); } } function iscssloaded() { // should we test again ? 20 retries = 5secs ..after that, the callback will be triggered by the error handler at 7secs if (asset.state !== loaded && asset.cssretries <= 20) { // loop through stylesheets for (var i = 0, l = doc.stylesheets.length; i < l; i++) { // do we have a match ? // we need to tests agains ele.href and not asset.url, because a local file will be assigned the full http path on a link element if (doc.stylesheets[i].href === ele.href) { process({"type": "load"}); return; } } // increment & try again asset.cssretries++; asset.csstimeout = win.settimeout(iscssloaded, 250); } } var ele; var ext = getextension(asset.url); if (ext === "css") { ele = doc.createelement("link"); ele.type = "text/" + (asset.type || "css"); ele.rel = "stylesheet"; ele.href = asset.url; /* onload supported for css on unsupported browsers * safari windows 5.1.7, ff < 10 */ // set counter to zero asset.cssretries = 0; asset.csstimeout = win.settimeout(iscssloaded, 500); } else { ele = doc.createelement("script"); ele.type = "text/" + (asset.type || "javascript"); ele.src = asset.url; } ele.onload = ele.onreadystatechange = process; ele.onerror = error; /* good read, but doesn't give much hope ! * http://blog.getify.com/on-script-loaders/ * http://www.nczonline.net/blog/2010/12/21/thoughts-on-script-loaders/ * https://hacks.mozilla.org/2009/06/defer/ */ // async: load in parallel and execute as soon as possible ele.async = false; // defer: load in parallel but maintain execution order ele.defer = false; // timout for asset loading asset.errortimeout = win.settimeout(function () { error({type: "timeout"}); }, 7e3); // use insertbefore to keep ie from throwing operation aborted (thx bryan forbes!) var head = doc.head || doc.getelementsbytagname("head")[0]; // but insert at end of head, because otherwise if it is a stylesheet, it will not override values head.insertbefore(ele, head.lastchild); } /* parts inspired from: https://github.com/jrburke/requirejs ************************************************************/ function init() { var items = doc.getelementsbytagname("script"); // look for a script with a data-head-init attribute for (var i = 0, l = items.length; i < l; i++) { var datamain = items[i].getattribute("data-headjs-load"); if (!!datamain) { api.load(datamain); return; } } } function ready(key, callback) { /// /// info: use cases: /// head.ready(callback); /// head.ready(document , callback); /// head.ready("file.js", callback); /// head.ready("label" , callback); /// head.ready(["label1", "label2"], callback); /// // dom ready check: head.ready(document, function() { }); if (key === doc) { if (isdomready) { one(callback); } else { domwaiters.push(callback); } return api; } // shift arguments if (isfunction(key)) { callback = key; key = "all"; // holds all callbacks that where added without labels: ready(callback) } // queue all items from key and return. the callback will be executed if all items from key are already loaded. if (isarray(key)) { var items = {}; each(key, function (item) { items[item] = assets[item]; api.ready(item, function () { if (allloaded(items)) { one(callback); } }); }); return api; } // make sure arguments are sane if (typeof key !== "string" || !isfunction(callback)) { return api; } // this can also be called when we trigger events based on filenames & labels var asset = assets[key]; // item already loaded --> execute and return if (asset && asset.state === loaded || key === "all" && allloaded() && isdomready) { one(callback); return api; } var arr = handlers[key]; if (!arr) { arr = handlers[key] = [callback]; } else { arr.push(callback); } return api; } /* mix of stuff from jquery & iecontentloaded * http://dev.w3.org/html5/spec/the-end.html#the-end ***************************************************/ function domready() { // make sure body exists, at least, in case ie gets a little overzealous (jquery ticket #5443). if (!doc.body) { // let's not get nasty by setting a timeout too small.. (loop mania guaranteed if assets are queued) win.cleartimeout(api.readytimeout); api.readytimeout = win.settimeout(domready, 50); return; } if (!isdomready) { isdomready = true; init(); each(domwaiters, function (fn) { one(fn); }); } } function domcontentloaded() { // w3c if (doc.addeventlistener) { doc.removeeventlistener("domcontentloaded", domcontentloaded, false); domready(); } // ie else if (doc.readystate === "complete") { // we're here because readystate === "complete" in oldie // which is good enough for us to call the dom ready! doc.detachevent("onreadystatechange", domcontentloaded); domready(); } } // catch cases where ready() is called after the browser event has already occurred. // we once tried to use readystate "interactive" here, but it caused issues like the one // discovered by chriss here: http://bugs.jquery.com/ticket/12282#comment:15 if (doc.readystate === "complete") { domready(); } // w3c else if (doc.addeventlistener) { doc.addeventlistener("domcontentloaded", domcontentloaded, false); // a fallback to window.onload, that will always work win.addeventlistener("load", domready, false); } // ie else { // ensure firing before onload, maybe late but safe also for iframes doc.attachevent("onreadystatechange", domcontentloaded); // a fallback to window.onload, that will always work win.attachevent("onload", domready); // if ie and not a frame // continually check to see if the document is ready var top = false; try { top = !win.frameelement && doc.documentelement; } catch (e) { } if (top && top.doscroll) { (function doscrollcheck() { if (!isdomready) { try { // use the trick by diego perini // http://javascript.nwbox.com/iecontentloaded/ top.doscroll("left"); } catch (error) { // let's not get nasty by setting a timeout too small.. (loop mania guaranteed if assets are queued) win.cleartimeout(api.readytimeout); api.readytimeout = win.settimeout(doscrollcheck, 50); return; } // and execute any waiting functions domready(); } }()); } } //#endregion //#region public exports // info: determine which method to use for loading api.load = api.js = isasync ? apiloadasync : apiloadhack; api.test = conditional; api.ready = ready; //#endregion //#region init // perform this when dom is ready api.ready(doc, function () { if (allloaded()) { each(handlers.all, function (callback) { one(callback); }); } if (api.feature) { api.feature("domloaded", true); } }); //#endregion }(window)); /*********wind js*********/ /* * phpwind js core * @copyright : copyright 2011, phpwind.com * @descript : phpwind核心js * @author : chaoren1641@gmail.com * @thanks : head.js (http://headjs.com) * $id: wind.js 21971 2012-12-17 12:11:36z hao.lin $ : */ /* * 防止浏览器不支持console报错 */ if (!window.console) { window.console = {}; var funs = ["profiles", "memory", "_commandlineapi", "debug", "error", "info", "log", "warn", "dir", "dirxml", "trace", "assert", "count", "marktimeline", "profile", "profileend", "time", "timeend", "timestamp", "group", "groupcollapsed", "groupend"]; for (var i = 0; i < funs.length; i++) { console[funs[i]] = function () { }; } } /* *解决ie6下不支持背景缓存 */ wind.ready(function () { if (!+'\v1' && !('maxheight' in document.body.style)) { try { document.execcommand("backgroundimagecache", false, true); } catch (e) { } } }); /* *wind core */ (function (win) { var root = win.gv.web_root + win.gv.js_root || location.origin + '/public/js/', //在wind.js加载之前定义gv.js_root ver = '', //定义常用js组件别名,使用别名加载 alias = { datepicker: 'datepicker/datepicker', jquery: 'jquery', colorpicker: 'colorpicker/colorpicker', tabs: 'tabs/tabs', swfobject: 'swfobject', imgready: 'imgready', //jquery util plugs ajaxform: 'ajaxform', cookie: 'cookie', treeview: 'treeview', treetable: 'treetable/treetable', draggable: 'draggable', validate: 'jquery.validate/jquery.validate', 'validate-extends': 'jquery.validate/additional-methods', artdialog: 'artdialog/artdialog', iframetools: 'artdialog/iframetools', xd: 'xd',//iframe跨域通信 noty: 'noty/noty-2.4.1', noty3: 'noty3/noty.min', jcrop: 'jcrop/js/jcrop', ajaxfileupload: 'ajaxfileupload', layer: 'layer/layer', plupload: 'plupload/plupload.full.min', echarts: 'echarts/echarts.min', viewer: 'viewer/viewer', colorpicker:'colorpicker/js/colorpicker', mousewheel: 'jquery.mousewheel/jquery.mousewheel.min', bootstrapdatetimepicker: 'bootstrap-datetimepicker/js/bootstrap-datetimepicker', dragula: 'dragula/dragula.min', imagesloaded: 'masonry/imagesloaded.pkgd.min', masonry: 'masonry/masonry.pkgd.min', masonry3: 'masonry/masonry-3.3.2.pkgd', ueditor:'ueditor/ueditor.all.min' }, //css路径 alias_css = { colorpicker: 'colorpicker/style', artdialog: 'artdialog/skins/default', datepicker: 'datepicker/style', treetable: 'treetable/treetable', jcrop: 'jcrop/css/jquery.jcrop.min', layer: 'layer/skin/default/layer', viewer: 'viewer/viewer', noty3: 'noty3/noty', colorpicker: 'colorpicker/css/colorpicker', animate: 'animate/animate', bootstrapdatetimepicker: 'bootstrap-datetimepicker/css/bootstrap-datetimepicker', dragula: 'dragula/dragula.min', ueditor:'ueditor/themes/default/css/ueditor' }; //add suffix and version for (var i in alias) { if (alias.hasownproperty(i)) { alias[i] = root + alias[i] + '.js?v=' + ver; } } for (var i in alias_css) { if (alias_css.hasownproperty(i)) { alias_css[i] = root + alias_css[i] + '.css?v=' + ver; } } //css loader win.wind = win.wind || {}; //!todo old webkit and old firefox does not support wind.css = function (alias/*alias or path*/, callback) { var url = alias_css[alias] ? alias_css[alias] : alias var link = document.createelement('link'); link.rel = 'stylesheet'; link.href = url; link.onload = link.onreadystatechange = function () {//chrome link无onload事件 var state = link.readystate; if (callback && !callback.done && (!state || /loaded|complete/.test(state))) { callback.done = true; callback(); } } document.getelementsbytagname('head')[0].appendchild(link); }; /** * 更新或者添加js 别名,在 wind.use()调用名使用 * @param newalias ,要设置的别名对象 */ wind.alias = function (newalias) { for (var i in newalias) { alias[i] = newalias[i]; } } /** * 更新或者添加css 别名,在 wind.css()调用名使用 * @param newalias ,要设置的别名对象 */ wind.aliascss = function (newalias) { for (var i in newalias) { alias_css[i] = newalias[i]; } } //using the alias to load the script file wind.use = function () { var args = arguments, len = args.length; for (var i = 0; i < len; i++) { if (typeof args[i] === 'string' && alias[args[i]]) { args[i] = alias[args[i]]; } } wind.js.apply(null, args); }; //wind javascript template (author: john resig http://ejohn.org/blog/javascript-micro-templating/) var cache = {}; wind.tmpl = function (str, data) { var fn = !/\w/.test(str) ? cache[str] = cache[str] || tmpl(str) : new function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" + "with(obj){p.push('" + str.replace(/[\r\t\n]/g, " ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g, "$1\r").replace(/\t=(.*?)%>/g, "',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'") + "');}return p.join('');"); return data ? fn(data) : fn; }; //wind全局功能函数命名空间 wind.util = {} })(window);