Fallos solucionados en sistema de dependencias de Vn

This commit is contained in:
Juan Ferrer Toribio 2015-09-25 15:35:01 +02:00
parent c26c178e32
commit f3cc7db96d
7 changed files with 105 additions and 113 deletions

View File

@ -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'
});
});

View File

@ -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);

View File

@ -3,6 +3,7 @@ Vn.include ('js/misc/main');
Vn.includeLib ('vn',
[
'browser'
,'cookie'
,'date'
,'value'
,'error'

View File

@ -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});
}
}

View File

@ -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);
}
/**

View File

@ -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');
?>

View File

@ -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');