diff --git a/web/js/htk/image-editor.js b/web/js/htk/image-editor.js index 476c02cd..69497f6e 100755 --- a/web/js/htk/image-editor.js +++ b/web/js/htk/image-editor.js @@ -8,7 +8,6 @@ Vn.define (function () { Htk.ImageEditor = new Class ({ Extends: Htk.Widget - ,Xml: 'js/htk/image-editor.xml' ,initialize: function (props) { @@ -56,6 +55,9 @@ Htk.ImageEditor = new Class this.$('name').value = image; this.$('schema').value = directory; } +}).extend +({ + Xml: 'js/htk/image-editor.xml' }); }); diff --git a/web/js/vn/locale.js b/web/js/vn/locale.js index 17086a28..19ffb550 100755 --- a/web/js/vn/locale.js +++ b/web/js/vn/locale.js @@ -20,8 +20,7 @@ Vn.Locale = { this.init (); - var file = 'locale/'+ this.language +'/'+ path +'.json' - +'?'+ Vn.Cookie.get ('hedera_version'); + var file = 'locale/'+ this.language +'/'+ path +'.json'+ Vn.getVersion (); var request = new XMLHttpRequest (); request.open ('get', file, true); diff --git a/web/js/vn/main.js b/web/js/vn/main.js index 6a2ac5ce..0a650f28 100644 --- a/web/js/vn/main.js +++ b/web/js/vn/main.js @@ -3,6 +3,7 @@ Vn.include ('js/misc/main'); Vn.includeLib ('vn', [ 'browser' + ,'cookie' ,'date' ,'value' ,'error' diff --git a/web/js/vn/mutators.js b/web/js/vn/mutators.js index 89c63751..bd42db9c 100755 --- a/web/js/vn/mutators.js +++ b/web/js/vn/mutators.js @@ -43,12 +43,3 @@ Class.Mutators.Child = function (propName) this.extend ({Child: propName}); }; -Class.Mutators.Xml = function (path) -{ - if (path) - { - //Vn.loadXml (path); - this.extend ({Xml: path}); - } -} - diff --git a/web/js/vn/vn.js b/web/js/vn/vn.js index a5daee0b..b8a52398 100755 --- a/web/js/vn/vn.js +++ b/web/js/vn/vn.js @@ -3,15 +3,26 @@ **/ var Vn = { - Config: {} + Config: {} ,includes: {} ,cssIncludes: {} - ,xmlIncludes: {} - ,tmpIncludes: [] - ,tmpDefine: null + ,currentDeps: [] + ,currentCallback: null ,customTags: {} ,head: document.getElementsByTagName ('head')[0] ,isMobileCached: null + + ,getVersion: function () + { + if (this._version === undefined) + { + var re = /[; ]hedera_version=([^\\s;]*)/; + var sMatch = (' '+ document.cookie).match (re); + this._version = (sMatch) ? '?'+ unescape (sMatch[1]) : ''; + } + + return this._version; + } /** * Includes a new CSS stylesheet in the current document, if the stylesheet @@ -28,7 +39,7 @@ var Vn = var link = document.createElement ('link'); link.rel = 'stylesheet'; link.type = 'text/css'; - link.href = fileName +'?'+ Vn.Cookie.get ('hedera_version'); + link.href = fileName + this.getVersion (); this.head.appendChild (link); this.cssIncludes[fileName] = @@ -59,6 +70,57 @@ var Vn = cssData.included = false; } } + + ,_createIncludeData: function (path) + { + var includeData = { + depCount: 0 + ,success: false + ,loaded: false + ,callbacks: [] + ,dependants: [] + }; + + this.includes[path] = includeData; + return includeData; + } + + ,_handleCallback: function (includeData, callback) + { + if (!callback) + return; + + if (includeData.success) + callback (includeData.loaded); + else + includeData.callbacks.push (callback); + } + + ,_resolveDeps: function (includeData) + { + includeData.success = true; + + var callbacks = includeData.callbacks; + + for (var i = 0; i < callbacks.length; i++) + callbacks[i] (includeData.loaded); + + var dependants = includeData.dependants; + + for (var i = 0; i < dependants.length; i++) + { + var dependant = dependants[i]; + dependant.depCount--; + + if (dependant.depCount == 0) + this._resolveDeps (dependant); + } + + delete includeData.callbacks; + delete includeData.dependants; + delete includeData.depCount; + delete includeData.loaded; + } /** * Initializes the library and calls the passed function when all @@ -83,35 +145,24 @@ var Vn = basePath += location.pathname; var scripts = this.head.getElementsByTagName ('script'); - var includes = this.tmpIncludes; + var includes = this.currentDeps; for (var i = 0; i < scripts.length; i++) { - var relPath = scripts[i].src.substr (basePath.length); - relPath = relPath.substr (0, relPath.indexOf ('.js')); + var path = scripts[i].src.substr (basePath.length); + path = path.substr (0, path.indexOf ('.js')) +'.js'; - var includeData = this.includes[relPath]; + var includeData = this.includes[path]; if (includeData === undefined) { - includeData = { - depCount: 0 - ,callbacks: [] - ,loaded: true - ,dependants: [] - ,success: true - }; - - this.includes[relPath] = includeData; + this.currentDeps = includes; + var includeData = this._createIncludeData (path); + this._onScriptLoad (includeData, true); } - - if (i == scripts.length - 1) - includeData.callbacks.push (this._onMainDepsLoad.bind (this)); - - this.tmpIncludes = includes; - this._onScriptLoad (includeData, true); } + includeData.callbacks.push (this._onMainDepsLoad.bind (this)); window.addEventListener ('load', this._onWindowLoad.bind (this)); } @@ -133,17 +184,6 @@ var Vn = this.mainCallback (); } - ,_handleCallback: function (includeData, callback) - { - if (!callback) - return; - - if (includeData.loaded) - callback (includeData.success); - else - includeData.callbacks.push (callback); - } - /** * Includes a set of javascript files and sets it as dependecies of the * current script. @@ -156,8 +196,8 @@ var Vn = { var includeData = this._realIncludeJs (arguments[i] +'.js'); - if (!includeData.loaded) - this.tmpIncludes.push (includeData); + if (!includeData.success) + this.currentDeps.push (includeData); } } @@ -173,8 +213,8 @@ var Vn = { var includeData = this._realLoadXml (arguments[i]); - if (!includeData.loaded) - this.tmpIncludes.push (includeData); + if (!includeData.success) + this.currentDeps.push (includeData); } } @@ -186,7 +226,7 @@ var Vn = **/ ,define: function (callback) { - this.tmpDefine = callback; + this.currentCallback = callback; } /** @@ -223,24 +263,18 @@ var Vn = if (includeData === undefined) { + includeData = this._createIncludeData (fileName); + var src = fileName; if (!skipVersion) - src = src +'?'+ Vn.Cookie.get ('hedera_version'); + src = src + this.getVersion (); var script = document.createElement ('script'); script.type = 'text/javascript'; script.async = false; script.src = src; - includeData = { - depCount: 0 - ,callbacks: [] - ,loaded: false - ,dependants: [] - ,success: false - }; - script.onload = this._onScriptLoad.bind (this, includeData, true); script.onerror = @@ -248,7 +282,6 @@ var Vn = script.onreadystatechange = this._onScriptStateChange.bind (this, includeData, script); - this.includes[fileName] = includeData; this.head.appendChild (script); } @@ -261,16 +294,16 @@ var Vn = this._onScriptLoad (includeData, true); } - ,_onScriptLoad: function (includeData, success) + ,_onScriptLoad: function (includeData, loaded) { - includeData.success = success; + includeData.loaded = loaded; - if (success) + if (loaded) { - if (this.tmpDefine) - includeData.callbacks.push (this.tmpDefine); + if (this.currentCallback) + includeData.callbacks.push (this.currentCallback); - var includes = this.tmpIncludes; + var includes = this.currentDeps; if (includes && includes.length > 0) { @@ -280,36 +313,13 @@ var Vn = includes[i].dependants.push (includeData); } else - this.resolveDeps (includeData); + this._resolveDeps (includeData); } else - this.resolveDeps (includeData); + this._resolveDeps (includeData); - this.tmpIncludes = []; - this.tmpDefine = null; - } - - ,resolveDeps: function (includeData) - { - includeData.loaded = true; - - var callbacks = includeData.callbacks; - - for (var i = 0; i < callbacks.length; i++) - callbacks[i] (includeData.success); - - var dependants = includeData.dependants; - - for (var i = 0; i < dependants.length; i++) - { - var dependant = dependants[i]; - dependant.depCount--; - - if (dependant.depCount == 0) - this.resolveDeps (dependant); - } - - delete includeData.callbacks; + this.currentDeps = []; + this.currentCallback = null; } /** @@ -330,23 +340,13 @@ var Vn = if (includeData === undefined) { - includeData = { - callbacks: [] - ,loaded: false - ,dependants: [] - ,depCount: 0 - ,success: false - ,xml: null - }; + includeData = this._createIncludeData (path); var request = new XMLHttpRequest (); request.onreadystatechange = this._onXmlReady.bind (this, includeData, request); - request.open ('get', - path +'?'+ Vn.Cookie.get ('hedera_version'), true); + request.open ('get', path + this.getVersion (), true); request.send (); - - this.includes[path] = includeData; } return includeData; @@ -357,12 +357,12 @@ var Vn = if (request.readyState != 4) return; - includeData.success = request.status == 200; + includeData.loaded = request.status == 200; - if (includeData.success) + if (includeData.loaded) includeData.xml = request.responseXML; - this.resolveDeps (includeData); + this._resolveDeps (includeData); } /** diff --git a/web/pages/main/head.php b/web/pages/main/head.php index 5a33cec7..f45e0b2b 100755 --- a/web/pages/main/head.php +++ b/web/pages/main/head.php @@ -5,9 +5,6 @@ use Vn\Hedera\Js; require_once ('global/metatags.php'); Js::includeFile ('js/vn/vn.js'); -Js::includeFile ('js/vn/cookie.js'); Js::includeFile ('pages/main/main.js'); -Js::includeCss ('pages/main/style.css'); - ?> diff --git a/web/pages/main/main.js b/web/pages/main/main.js index 6961d80d..8fa63693 100755 --- a/web/pages/main/main.js +++ b/web/pages/main/main.js @@ -1,4 +1,6 @@ +Vn.includeCss ('pages/main/style.css'); + Vn.include ('js/misc/main'); Vn.include ('js/vn/locale'); Vn.include ('js/vn/main');