From 94acf9ffdc65349cc290e51c5d629c292690fb69 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 26 Jul 2012 06:03:59 -0400 Subject: [PATCH] minor changes --- client.js | 6 +----- lib/client/viewer.js | 34 ++++++++++++++++++++++++++-------- lib/cloudfunc.js | 13 +++++++++++++ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/client.js b/client.js index b905e3a7..918c135a 100644 --- a/client.js +++ b/client.js @@ -608,11 +608,7 @@ CloudClient._anyload = function(pParams_o) var lFunc = pParams_o.func; if(!lID){ - lID=lSrc.replace(lSrc.substr(lSrc, - lSrc.lastIndexOf('/')+1), - ''); - /* убираем точку*/ - lID=lID.replace('.','_'); + lID = CloudFunc.getIdBySrc(lSrc); } var element = document.getElementById(lID); /* если скрипт еще не загружен */ diff --git a/lib/client/viewer.js b/lib/client/viewer.js index dd5e9caf..672f8d6b 100644 --- a/lib/client/viewer.js +++ b/lib/client/viewer.js @@ -41,21 +41,28 @@ CloudCommander.Viewer.FancyBox = { }), load: (function(pParent){ return function(){ - var ljsLoad_f = function(){ - CloudCommander.jsload( - 'http://fancyapps.com/fancybox/source/jquery.fancybox.pack.js',{ - onerror: (function(){ + var ljsLoad_f = function(){ + var lSrc = 'http://fancyapps.com/fancybox/source/jquery.fancybox.pack.js'; + + CloudCommander.jsload(lSrc,{ + onerror: (function(){ + pParent.removeNotLoaded(lSrc, pParent); + CloudCommander.jsload(pParent.dir + 'jquery.fancybox.pack.js'); }) }); }; + var lSrc = 'http://fancyapps.com/fancybox/source/jquery.fancybox.css'; + CloudCommander.cssLoad({ - src : 'http://fancyapps.com/fancybox/source/jquery.fancybox.css', + src : lSrc, func : { onload: ljsLoad_f, - onerror: (function(){ + onerror: (function(){ + pParent.removeNotLoaded(lSrc, pParent); + CloudCommander.cssLoad({ src : pParent.dir +'jquery.fancybox.css', func : ljsLoad_f @@ -93,9 +100,20 @@ CloudCommander.Viewer.FancyBox = { console.log(pError); } }, - getById : function(pId){return document.getElementById(pId);}, - getByClass : function(pClass){ + getById : function(pId){return document.getElementById(pId);}, + + getByClass : function(pClass){ return document.getElementsByClassName(pClass); + }, + + removeNotLoaded : function(pSrc, pParent){ + /* removing already loaded element + * with same id + */ + var lId = CloudFunc.getIdBySrc(pSrc); + lId = pParent.getById(lId); + lId && + document.removeChild(lId); } }; CloudCommander.Viewer.Keys = (function(){ diff --git a/lib/cloudfunc.js b/lib/cloudfunc.js index a1e0dada..b57feba8 100644 --- a/lib/cloudfunc.js +++ b/lib/cloudfunc.js @@ -268,6 +268,19 @@ CloudFunc._getDirPath=function(url) return lHtmlPath; }; +/* + * Function gets id by src + * from http://domain.com/1.js to + * 1_js + */ +CloudFunc._getIdBySrc = function(pSrc){ + var lID=pSrc.replace(pSrc.substr(pSrc, + pSrc.lastIndexOf('/')+1), + ''); + /* убираем точку*/ + return lID.replace('.','_'); +}; + /* * Функция ищет в имени файла расширение * и если находит возвращает true