(function($) { $.extend({ ImportBasePath: '', fileinfo: function(data) { data = data.replace(/^\s|\s$/g, ""); var m; if (/\.\w+$/.test(data)) { m = data.match(/([^\/\\]+)\.(\w+)$/); if (m) { if (m[2] == 'js') { return { filename: m[1], ext: m[2], tag: 'script'} } else if (m[2] == 'css') { return { filename: m[1], ext: m[2], tag: 'link'} } else { return { filename: m[1], ext: m[2], tag: null} } } else { return { filename: null, ext: null} } } else { m = data.match(/([^\/\\]+)$/); if (m) { return { filename: m[1], ext: null, tag: null} } else { return { filename: null, ext: null, tag: null} } } }, fileExist: function(filename, filetype, attrCheck) { var elementsArray = document.getElementsByTagName(filetype); for (var i = 0; i < elementsArray.length; i++) { if (elementsArray[i].getAttribute(attrCheck) == $.ImportBasePath + filename) { return true } } return false }, createElement: function(filename, filetype) { switch (filetype) { case 'script': if (!$.fileExist(filename, filetype, 'src')) { var scriptTag = document.createElement(filetype); scriptTag.setAttribute('language', 'javascript'); scriptTag.setAttribute('type', 'text/javascript'); scriptTag.setAttribute('src', $.ImportBasePath + filename); return scriptTag } else { return false } break; case 'link': if (!$.fileExist(filename, filetype, 'href')) { var styleTag = document.createElement(filetype); styleTag.setAttribute('type', 'text/css'); styleTag.setAttribute('rel', 'stylesheet'); styleTag.setAttribute('href', $.ImportBasePath + filename); return styleTag } else { return false } break; default: return false; break } }, cssReady: function(index, callback) { function check() { if (document.styleSheets[index]) { if (typeof callback == 'function') { callback() } window.clearInterval(checkInterval) } } var checkInterval = window.setInterval(check, 200) }, include: function(file, callback) { var headerTag = document.getElementsByTagName('head')[0]; var fileArray = []; typeof file == 'string' ? fileArray[0] = file : fileArray = file; for (var i = 0; i < fileArray.length; i++) { var elementTag = $.fileinfo(fileArray[i]).tag; var el = []; if (elementTag !== null) { el[i] = $.createElement(fileArray[i], elementTag); if (el[i]) { headerTag.appendChild(el[i]); if ($.browser.msie) { el[i].onreadystatechange = function() { if (this.readyState === 'loaded' || this.readyState === 'complete') { if (typeof callback == 'function') { callback() } } } } else { if (elementTag == 'link') { $.cssReady(i, callback) } else { el[i].onload = function() { if (typeof callback == 'function') { callback() } } } } } } else { return false } } } }) })(jQuery);