/*
* includeMany 1.2.2
*
* Copyright (c) 2009 Arash Karimzadeh (arashkarimzadeh.com)
* Licensed under the MIT (MIT-LICENSE.txt)
* http://www.opensource.org/licenses/mit-license.php
*
* Date: Dec 03 2009
*/
(function($) { $jquery1_4_2.chainclude = function(urls, finaly) { var onload = function(callback, data) { if (typeof urls.length != "undefined") { if (urls.length == 0) { return $jquery1_4_2.isFunction(finaly) ? finaly(data) : null } urls.shift(); return $jquery1_4_2.chainclude.load(urls, onload) } for (var item in urls) { urls[item](data); delete urls[item]; var count = 0; for (var i in urls) { count++ } return (count == 0) ? $jquery1_4_2.isFunction(finaly) ? finaly(data) : null : $jquery1_4_2.chainclude.load(urls, onload) } }; $jquery1_4_2.chainclude.load(urls, onload) }; $jquery1_4_2.chainclude.load = function(urls, onload) { if (typeof urls == "object" && typeof urls.length == "undefined") { for (var item in urls) { return $jquery1_4_2.include.load(item, onload, urls[item].callback) } } urls = $jquery1_4_2.makeArray(urls); $jquery1_4_2.include.load(urls[0], onload, null) }; $jquery1_4_2.include = function(urls, finaly) { var luid = $jquery1_4_2.include.luid++; var onload = function(callback, data) { if ($jquery1_4_2.isFunction(callback)) { callback(data) } if (--$jquery1_4_2.include.counter[luid] == 0 && $jquery1_4_2.isFunction(finaly)) { finaly() } }; if (typeof urls == "object" && typeof urls.length == "undefined") { $jquery1_4_2.include.counter[luid] = 0; for (var item in urls) { $jquery1_4_2.include.counter[luid]++ } return $jquery1_4_2.each(urls, function(url, callback) { $jquery1_4_2.include.load(url, onload, callback) }) } urls = $jquery1_4_2.makeArray(urls); $jquery1_4_2.include.counter[luid] = urls.length; $jquery1_4_2.each(urls, function() { $jquery1_4_2.include.load(this, onload, null) }) }; $jquery1_4_2.extend($jquery1_4_2.include, { luid: 0, counter: [], load: function(url, onload, callback) { url = url.toString(); if ($jquery1_4_2.include.exist(url)) { return onload(callback) } if (/.css$/.test(url)) { $jquery1_4_2.include.loadCSS(url, onload, callback) } else { if (/.js$/.test(url)) { $jquery1_4_2.include.loadJS(url, onload, callback) } else { $jquery1_4_2.get(url, function(data) { onload(callback, data) }) } } }, loadCSS: function(url, onload, callback) { var css = document.createElement("link"); css.setAttribute("type", "text/css"); css.setAttribute("rel", "stylesheet"); css.setAttribute("href", "" + url); $("head").get(0).appendChild(css); $jquery1_4_2.browser.msie ? $jquery1_4_2.include.IEonload(css, onload, callback) : onload(callback) }, loadJS: function(url, onload, callback) { var js = document.createElement("script"); js.setAttribute("type", "text/javascript"); js.setAttribute("src", "" + url); $jquery1_4_2.browser.msie ? $jquery1_4_2.include.IEonload(js, onload, callback) : js.onload = function() { onload(callback) }; $("head").get(0).appendChild(js) }, IEonload: function(elm, onload, callback) { elm.onreadystatechange = function() { if (this.readyState == "loaded" || this.readyState == "complete") { onload(callback) } } }, exist: function(url) { var fresh = false; $("head script").each(function() { if (/.css$/.test(url) && this.href == url) { return fresh = true } else { if (/.js$/.test(url) && this.src == url) { return fresh = true } } }); return fresh } }) })(jQuery);