Fallos solucionados en sistema de dependencias de Vn
This commit is contained in:
parent
c26c178e32
commit
f3cc7db96d
|
@ -8,7 +8,6 @@ Vn.define (function () {
|
||||||
Htk.ImageEditor = new Class
|
Htk.ImageEditor = new Class
|
||||||
({
|
({
|
||||||
Extends: Htk.Widget
|
Extends: Htk.Widget
|
||||||
,Xml: 'js/htk/image-editor.xml'
|
|
||||||
|
|
||||||
,initialize: function (props)
|
,initialize: function (props)
|
||||||
{
|
{
|
||||||
|
@ -56,6 +55,9 @@ Htk.ImageEditor = new Class
|
||||||
this.$('name').value = image;
|
this.$('name').value = image;
|
||||||
this.$('schema').value = directory;
|
this.$('schema').value = directory;
|
||||||
}
|
}
|
||||||
|
}).extend
|
||||||
|
({
|
||||||
|
Xml: 'js/htk/image-editor.xml'
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,8 +20,7 @@ Vn.Locale =
|
||||||
{
|
{
|
||||||
this.init ();
|
this.init ();
|
||||||
|
|
||||||
var file = 'locale/'+ this.language +'/'+ path +'.json'
|
var file = 'locale/'+ this.language +'/'+ path +'.json'+ Vn.getVersion ();
|
||||||
+'?'+ Vn.Cookie.get ('hedera_version');
|
|
||||||
|
|
||||||
var request = new XMLHttpRequest ();
|
var request = new XMLHttpRequest ();
|
||||||
request.open ('get', file, true);
|
request.open ('get', file, true);
|
||||||
|
|
|
@ -3,6 +3,7 @@ Vn.include ('js/misc/main');
|
||||||
Vn.includeLib ('vn',
|
Vn.includeLib ('vn',
|
||||||
[
|
[
|
||||||
'browser'
|
'browser'
|
||||||
|
,'cookie'
|
||||||
,'date'
|
,'date'
|
||||||
,'value'
|
,'value'
|
||||||
,'error'
|
,'error'
|
||||||
|
|
|
@ -43,12 +43,3 @@ Class.Mutators.Child = function (propName)
|
||||||
this.extend ({Child: propName});
|
this.extend ({Child: propName});
|
||||||
};
|
};
|
||||||
|
|
||||||
Class.Mutators.Xml = function (path)
|
|
||||||
{
|
|
||||||
if (path)
|
|
||||||
{
|
|
||||||
//Vn.loadXml (path);
|
|
||||||
this.extend ({Xml: path});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
196
web/js/vn/vn.js
196
web/js/vn/vn.js
|
@ -3,15 +3,26 @@
|
||||||
**/
|
**/
|
||||||
var Vn =
|
var Vn =
|
||||||
{
|
{
|
||||||
Config: {}
|
Config: {}
|
||||||
,includes: {}
|
,includes: {}
|
||||||
,cssIncludes: {}
|
,cssIncludes: {}
|
||||||
,xmlIncludes: {}
|
,currentDeps: []
|
||||||
,tmpIncludes: []
|
,currentCallback: null
|
||||||
,tmpDefine: null
|
|
||||||
,customTags: {}
|
,customTags: {}
|
||||||
,head: document.getElementsByTagName ('head')[0]
|
,head: document.getElementsByTagName ('head')[0]
|
||||||
,isMobileCached: null
|
,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
|
* Includes a new CSS stylesheet in the current document, if the stylesheet
|
||||||
|
@ -28,7 +39,7 @@ var Vn =
|
||||||
var link = document.createElement ('link');
|
var link = document.createElement ('link');
|
||||||
link.rel = 'stylesheet';
|
link.rel = 'stylesheet';
|
||||||
link.type = 'text/css';
|
link.type = 'text/css';
|
||||||
link.href = fileName +'?'+ Vn.Cookie.get ('hedera_version');
|
link.href = fileName + this.getVersion ();
|
||||||
this.head.appendChild (link);
|
this.head.appendChild (link);
|
||||||
|
|
||||||
this.cssIncludes[fileName] =
|
this.cssIncludes[fileName] =
|
||||||
|
@ -59,6 +70,57 @@ var Vn =
|
||||||
cssData.included = false;
|
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
|
* Initializes the library and calls the passed function when all
|
||||||
|
@ -83,35 +145,24 @@ var Vn =
|
||||||
basePath += location.pathname;
|
basePath += location.pathname;
|
||||||
|
|
||||||
var scripts = this.head.getElementsByTagName ('script');
|
var scripts = this.head.getElementsByTagName ('script');
|
||||||
var includes = this.tmpIncludes;
|
var includes = this.currentDeps;
|
||||||
|
|
||||||
for (var i = 0; i < scripts.length; i++)
|
for (var i = 0; i < scripts.length; i++)
|
||||||
{
|
{
|
||||||
var relPath = scripts[i].src.substr (basePath.length);
|
var path = scripts[i].src.substr (basePath.length);
|
||||||
relPath = relPath.substr (0, relPath.indexOf ('.js'));
|
path = path.substr (0, path.indexOf ('.js')) +'.js';
|
||||||
|
|
||||||
var includeData = this.includes[relPath];
|
var includeData = this.includes[path];
|
||||||
|
|
||||||
if (includeData === undefined)
|
if (includeData === undefined)
|
||||||
{
|
{
|
||||||
includeData = {
|
this.currentDeps = includes;
|
||||||
depCount: 0
|
var includeData = this._createIncludeData (path);
|
||||||
,callbacks: []
|
this._onScriptLoad (includeData, true);
|
||||||
,loaded: true
|
|
||||||
,dependants: []
|
|
||||||
,success: true
|
|
||||||
};
|
|
||||||
|
|
||||||
this.includes[relPath] = includeData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
window.addEventListener ('load', this._onWindowLoad.bind (this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,17 +184,6 @@ var Vn =
|
||||||
this.mainCallback ();
|
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
|
* Includes a set of javascript files and sets it as dependecies of the
|
||||||
* current script.
|
* current script.
|
||||||
|
@ -156,8 +196,8 @@ var Vn =
|
||||||
{
|
{
|
||||||
var includeData = this._realIncludeJs (arguments[i] +'.js');
|
var includeData = this._realIncludeJs (arguments[i] +'.js');
|
||||||
|
|
||||||
if (!includeData.loaded)
|
if (!includeData.success)
|
||||||
this.tmpIncludes.push (includeData);
|
this.currentDeps.push (includeData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,8 +213,8 @@ var Vn =
|
||||||
{
|
{
|
||||||
var includeData = this._realLoadXml (arguments[i]);
|
var includeData = this._realLoadXml (arguments[i]);
|
||||||
|
|
||||||
if (!includeData.loaded)
|
if (!includeData.success)
|
||||||
this.tmpIncludes.push (includeData);
|
this.currentDeps.push (includeData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +226,7 @@ var Vn =
|
||||||
**/
|
**/
|
||||||
,define: function (callback)
|
,define: function (callback)
|
||||||
{
|
{
|
||||||
this.tmpDefine = callback;
|
this.currentCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -223,24 +263,18 @@ var Vn =
|
||||||
|
|
||||||
if (includeData === undefined)
|
if (includeData === undefined)
|
||||||
{
|
{
|
||||||
|
includeData = this._createIncludeData (fileName);
|
||||||
|
|
||||||
var src = fileName;
|
var src = fileName;
|
||||||
|
|
||||||
if (!skipVersion)
|
if (!skipVersion)
|
||||||
src = src +'?'+ Vn.Cookie.get ('hedera_version');
|
src = src + this.getVersion ();
|
||||||
|
|
||||||
var script = document.createElement ('script');
|
var script = document.createElement ('script');
|
||||||
script.type = 'text/javascript';
|
script.type = 'text/javascript';
|
||||||
script.async = false;
|
script.async = false;
|
||||||
script.src = src;
|
script.src = src;
|
||||||
|
|
||||||
includeData = {
|
|
||||||
depCount: 0
|
|
||||||
,callbacks: []
|
|
||||||
,loaded: false
|
|
||||||
,dependants: []
|
|
||||||
,success: false
|
|
||||||
};
|
|
||||||
|
|
||||||
script.onload =
|
script.onload =
|
||||||
this._onScriptLoad.bind (this, includeData, true);
|
this._onScriptLoad.bind (this, includeData, true);
|
||||||
script.onerror =
|
script.onerror =
|
||||||
|
@ -248,7 +282,6 @@ var Vn =
|
||||||
script.onreadystatechange =
|
script.onreadystatechange =
|
||||||
this._onScriptStateChange.bind (this, includeData, script);
|
this._onScriptStateChange.bind (this, includeData, script);
|
||||||
|
|
||||||
this.includes[fileName] = includeData;
|
|
||||||
this.head.appendChild (script);
|
this.head.appendChild (script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,16 +294,16 @@ var Vn =
|
||||||
this._onScriptLoad (includeData, true);
|
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)
|
if (this.currentCallback)
|
||||||
includeData.callbacks.push (this.tmpDefine);
|
includeData.callbacks.push (this.currentCallback);
|
||||||
|
|
||||||
var includes = this.tmpIncludes;
|
var includes = this.currentDeps;
|
||||||
|
|
||||||
if (includes && includes.length > 0)
|
if (includes && includes.length > 0)
|
||||||
{
|
{
|
||||||
|
@ -280,36 +313,13 @@ var Vn =
|
||||||
includes[i].dependants.push (includeData);
|
includes[i].dependants.push (includeData);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
this.resolveDeps (includeData);
|
this._resolveDeps (includeData);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
this.resolveDeps (includeData);
|
this._resolveDeps (includeData);
|
||||||
|
|
||||||
this.tmpIncludes = [];
|
this.currentDeps = [];
|
||||||
this.tmpDefine = null;
|
this.currentCallback = 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -330,23 +340,13 @@ var Vn =
|
||||||
|
|
||||||
if (includeData === undefined)
|
if (includeData === undefined)
|
||||||
{
|
{
|
||||||
includeData = {
|
includeData = this._createIncludeData (path);
|
||||||
callbacks: []
|
|
||||||
,loaded: false
|
|
||||||
,dependants: []
|
|
||||||
,depCount: 0
|
|
||||||
,success: false
|
|
||||||
,xml: null
|
|
||||||
};
|
|
||||||
|
|
||||||
var request = new XMLHttpRequest ();
|
var request = new XMLHttpRequest ();
|
||||||
request.onreadystatechange =
|
request.onreadystatechange =
|
||||||
this._onXmlReady.bind (this, includeData, request);
|
this._onXmlReady.bind (this, includeData, request);
|
||||||
request.open ('get',
|
request.open ('get', path + this.getVersion (), true);
|
||||||
path +'?'+ Vn.Cookie.get ('hedera_version'), true);
|
|
||||||
request.send ();
|
request.send ();
|
||||||
|
|
||||||
this.includes[path] = includeData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return includeData;
|
return includeData;
|
||||||
|
@ -357,12 +357,12 @@ var Vn =
|
||||||
if (request.readyState != 4)
|
if (request.readyState != 4)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
includeData.success = request.status == 200;
|
includeData.loaded = request.status == 200;
|
||||||
|
|
||||||
if (includeData.success)
|
if (includeData.loaded)
|
||||||
includeData.xml = request.responseXML;
|
includeData.xml = request.responseXML;
|
||||||
|
|
||||||
this.resolveDeps (includeData);
|
this._resolveDeps (includeData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,9 +5,6 @@ use Vn\Hedera\Js;
|
||||||
require_once ('global/metatags.php');
|
require_once ('global/metatags.php');
|
||||||
|
|
||||||
Js::includeFile ('js/vn/vn.js');
|
Js::includeFile ('js/vn/vn.js');
|
||||||
Js::includeFile ('js/vn/cookie.js');
|
|
||||||
Js::includeFile ('pages/main/main.js');
|
Js::includeFile ('pages/main/main.js');
|
||||||
|
|
||||||
Js::includeCss ('pages/main/style.css');
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
|
||||||
|
Vn.includeCss ('pages/main/style.css');
|
||||||
|
|
||||||
Vn.include ('js/misc/main');
|
Vn.include ('js/misc/main');
|
||||||
Vn.include ('js/vn/locale');
|
Vn.include ('js/vn/locale');
|
||||||
Vn.include ('js/vn/main');
|
Vn.include ('js/vn/main');
|
||||||
|
|
Loading…
Reference in New Issue