From f2209bdcf9c56854ed10f18e4d657a7a4da61974 Mon Sep 17 00:00:00 2001 From: cdujeu Date: Fri, 17 Feb 2017 17:52:21 +0100 Subject: [PATCH] Remove sync calls --- .../editor.soundmanager/class.SMPlayer.js | 172 +++++++++--------- .../plugins/editor.soundmanager/manifest.xml | 2 +- .../src/plugins/gui.ajax/res/js/es6/Pydio.es6 | 26 +-- .../gui.ajax/res/js/es6/http/PydioApi.es6 | 48 +---- .../res/js/es6/http/ResourcesManager.es6 | 57 ++++-- .../gui.ajax/res/js/es6/model/Registry.es6 | 5 +- .../res/js/ui/reactjs/jsx/ReactUI/Builder.js | 15 +- 7 files changed, 163 insertions(+), 162 deletions(-) diff --git a/core/src/plugins/editor.soundmanager/class.SMPlayer.js b/core/src/plugins/editor.soundmanager/class.SMPlayer.js index 2b301d3b8a..0f84439810 100644 --- a/core/src/plugins/editor.soundmanager/class.SMPlayer.js +++ b/core/src/plugins/editor.soundmanager/class.SMPlayer.js @@ -17,97 +17,107 @@ * * The latest code can be found at . */ -window.SM2_DEFER = true; -if(!$$("html")[0].hasClassName("no-canvas") && !window.soundManager){ - var conn = new Connexion(); - conn._libUrl = (ajxpBootstrap.parameters.get('SERVER_PREFIX_URI')?ajxpBootstrap.parameters.get('SERVER_PREFIX_URI'):'')+'plugins/editor.soundmanager/sm/'; - conn.loadLibrary('360-player/script/berniecode-animator.js'); - conn.loadLibrary('script/soundmanager2-nodebug-jsmin.js', function(){ - window.soundManager = new SoundManager('plugins/editor.soundmanager/sm/swf/'); - window.soundManager.url = (ajxpBootstrap.parameters.get('SERVER_PREFIX_URI')?ajxpBootstrap.parameters.get('SERVER_PREFIX_URI'):'')+'plugins/editor.soundmanager/sm/swf/'; - if(ajaxplorer && ajaxplorer.user && ajaxplorer.user.getPreference("soundmanager.volume") !== undefined){ - soundManager.defaultOptions.volume = ajaxplorer.user.getPreference("soundmanager.volume"); - } - var conn2 = new Connexion(); - conn2._libUrl = (ajxpBootstrap.parameters.get('SERVER_PREFIX_URI')?ajxpBootstrap.parameters.get('SERVER_PREFIX_URI'):'')+'plugins/editor.soundmanager/sm/'; - conn2.loadLibrary('360-player/script/360player.js', function(){ +function threeSixtyLoaded(){ - if(!window.threeSixtyPlayer) return; + if(!window.threeSixtyPlayer) return; - window.threeSixtyPlayer.config.scaleFont = (navigator.userAgent.match(/msie/i)?false:true); - window.threeSixtyPlayer.config.showHMSTime = true; - window.threeSixtyPlayer.config.useWaveformData = true; - window.threeSixtyPlayer.config.useEQData = true; - // enable this in SM2 as well, as needed - if (window.threeSixtyPlayer.config.useWaveformData) { - window.soundManager.flash9Options.useWaveformData = true; - } - if (window.threeSixtyPlayer.config.useEQData) { - window.soundManager.flash9Options.useEQData = true; + window.threeSixtyPlayer.config.scaleFont = (navigator.userAgent.match(/msie/i)?false:true); + window.threeSixtyPlayer.config.showHMSTime = true; + window.threeSixtyPlayer.config.useWaveformData = true; + window.threeSixtyPlayer.config.useEQData = true; + // enable this in SM2 as well, as needed + if (window.threeSixtyPlayer.config.useWaveformData) { + window.soundManager.flash9Options.useWaveformData = true; + } + if (window.threeSixtyPlayer.config.useEQData) { + window.soundManager.flash9Options.useEQData = true; + } + if (window.threeSixtyPlayer.config.usePeakData) { + window.soundManager.flash9Options.usePeakData = true; + } + if (window.threeSixtyPlayer.config.useWaveformData || window.threeSixtyPlayer.flash9Options.useEQData || window.threeSixtyPlayer.flash9Options.usePeakData) { + // even if HTML5 supports MP3, prefer flash so the visualization features can be used. + window.soundManager.preferFlash = true; + } + + window.soundManager.useFastPolling = true; // increased JS callback frequency, combined with useHighPerformance = true + window.threeSixtyPlayer.config.onfinish = function(smPlayer){ + try{ + var finishingPlayer = smPlayer._360data.oUI360; + if(finishingPlayer.hasClassName("ui360-vis")) { + window.setTimeout(function(){ + finishingPlayer.addClassName("ui360-vis-retracted"); + }, 1000); + }else{ + var links = $$("div.ui360").reject(function(el){ + return el.hasClassName("ui360-vis"); + }); + var index = links.indexOf(finishingPlayer); + if(index < links.length-1 ){ + window.threeSixtyPlayer.handleClick({'target':links[index+1].down("a.sm2_link")}); + } + if(finishingPlayer.up('.ajxpNodeProvider')){ + finishingPlayer.up('.ajxpNodeProvider').removeClassName("SMNodePlaying"); + } } - if (window.threeSixtyPlayer.config.usePeakData) { - window.soundManager.flash9Options.usePeakData = true; + }catch(e){} + }; + + window.threeSixtyPlayer.config.onplay = function(smPlayer){ + try{ + var playerDiv = smPlayer._360data.oUI360; + if(!playerDiv.hasClassName("ui360-vis")) { + if(playerDiv.up('.ajxpNodeProvider')){ + playerDiv.up('.ajxpNodeProvider').addClassName("SMNodePlaying"); + } + }else{ + playerDiv.removeClassName("ui360-vis-retracted"); } - if (window.threeSixtyPlayer.config.useWaveformData || window.threeSixtyPlayer.flash9Options.useEQData || window.threeSixtyPlayer.flash9Options.usePeakData) { - // even if HTML5 supports MP3, prefer flash so the visualization features can be used. - window.soundManager.preferFlash = true; + }catch(e){} + }; + + window.threeSixtyPlayer.config.onstop = function(smPlayer){ + try{ + var playerDiv = smPlayer._360data.oUI360; + if(!playerDiv.hasClassName("ui360-vis")) { + if(playerDiv.up('.ajxpNodeProvider')){ + playerDiv.up('.ajxpNodeProvider').removeClassName("SMNodePlaying"); + } + }else{ + window.setTimeout(function(){ + playerDiv.addClassName("ui360-vis-retracted"); + }, 1000); } + }catch(e){} + }; - window.soundManager.useFastPolling = true; // increased JS callback frequency, combined with useHighPerformance = true - window.threeSixtyPlayer.config.onfinish = function(smPlayer){ - try{ - var finishingPlayer = smPlayer._360data.oUI360; - if(finishingPlayer.hasClassName("ui360-vis")) { - window.setTimeout(function(){ - finishingPlayer.addClassName("ui360-vis-retracted"); - }, 1000); - }else{ - var links = $$("div.ui360").reject(function(el){ - return el.hasClassName("ui360-vis"); - }); - var index = links.indexOf(finishingPlayer); - if(index < links.length-1 ){ - window.threeSixtyPlayer.handleClick({'target':links[index+1].down("a.sm2_link")}); - } - if(finishingPlayer.up('.ajxpNodeProvider')){ - finishingPlayer.up('.ajxpNodeProvider').removeClassName("SMNodePlaying"); - } - } - }catch(e){} - }; + window.soundManager.beginDelayedInit(); +} - window.threeSixtyPlayer.config.onplay = function(smPlayer){ - try{ - var playerDiv = smPlayer._360data.oUI360; - if(!playerDiv.hasClassName("ui360-vis")) { - if(playerDiv.up('.ajxpNodeProvider')){ - playerDiv.up('.ajxpNodeProvider').addClassName("SMNodePlaying"); - } - }else{ - playerDiv.removeClassName("ui360-vis-retracted"); - } - }catch(e){} - }; - window.threeSixtyPlayer.config.onstop = function(smPlayer){ - try{ - var playerDiv = smPlayer._360data.oUI360; - if(!playerDiv.hasClassName("ui360-vis")) { - if(playerDiv.up('.ajxpNodeProvider')){ - playerDiv.up('.ajxpNodeProvider').removeClassName("SMNodePlaying"); - } - }else{ - window.setTimeout(function(){ - playerDiv.addClassName("ui360-vis-retracted"); - }, 1000); - } - }catch(e){} - }; +window.SM2_DEFER = true; +if(!$$("html")[0].hasClassName("no-canvas") && !window.soundManager){ - window.soundManager.beginDelayedInit(); - }); - }); + var conn = new Connexion(); + conn._libUrl = (ajxpBootstrap.parameters.get('SERVER_PREFIX_URI')?ajxpBootstrap.parameters.get('SERVER_PREFIX_URI'):'')+'plugins/editor.soundmanager/sm/'; + conn.loadLibrary('360-player/script/berniecode-animator.js', function(){ + var conn3 = new Connexion(); + conn3._libUrl = conn._libUrl; + conn3.loadLibrary('script/soundmanager2-nodebug-jsmin.js', function(){ + + window.soundManager = new SoundManager('plugins/editor.soundmanager/sm/swf/'); + window.soundManager.url = conn._libUrl + 'swf/'; + if(ajaxplorer && ajaxplorer.user && ajaxplorer.user.getPreference("soundmanager.volume") !== undefined){ + soundManager.defaultOptions.volume = ajaxplorer.user.getPreference("soundmanager.volume"); + } + var conn2 = new Connexion(); + conn2._libUrl = conn._libUrl; + conn2.loadLibrary('360-player/script/360player.js', threeSixtyLoaded, true); + + }, true); + }, true); hookToFilesList(); + } function hookToFilesList(){ diff --git a/core/src/plugins/editor.soundmanager/manifest.xml b/core/src/plugins/editor.soundmanager/manifest.xml index 43d3886194..1cc5c0a2ee 100644 --- a/core/src/plugins/editor.soundmanager/manifest.xml +++ b/core/src/plugins/editor.soundmanager/manifest.xml @@ -8,7 +8,7 @@ - + diff --git a/core/src/plugins/gui.ajax/res/js/es6/Pydio.es6 b/core/src/plugins/gui.ajax/res/js/es6/Pydio.es6 index 81109afbfb..3630b3d203 100644 --- a/core/src/plugins/gui.ajax/res/js/es6/Pydio.es6 +++ b/core/src/plugins/gui.ajax/res/js/es6/Pydio.es6 @@ -125,23 +125,23 @@ class Pydio extends Observable{ if(!this.UI && window.useReactPydioUI){ ResourcesManager.loadClassesAndApply(["React", "PydioReactUI"], function(){ this.UI = new PydioReactUI.Builder(this); - }.bind(this)); - } + this.UI.initTemplates(); + this.UI.modal.initForms(); + this.UI.initObjects(); - this.UI.initTemplates(); - this.UI.modal.initForms(); - this.UI.initObjects(); + if(!this.user) { + PydioApi.getClient().tryToLogUserFromRememberData(); + } + this.fire("registry_loaded", this.Registry.getXML()); - if(!this.user) { - PydioApi.getClient().tryToLogUserFromRememberData(); - } - this.fire("registry_loaded", this.Registry.getXML()); + window.setTimeout(function(){ + this.fire('loaded'); + }.bind(this), 200); - window.setTimeout(function(){ - this.fire('loaded'); - }.bind(this), 200); + this.Router = new Router(this); - this.Router = new Router(this); + }.bind(this)); + } }.bind(this); diff --git a/core/src/plugins/gui.ajax/res/js/es6/http/PydioApi.es6 b/core/src/plugins/gui.ajax/res/js/es6/http/PydioApi.es6 index fb7f241216..eaa4d3f86e 100644 --- a/core/src/plugins/gui.ajax/res/js/es6/http/PydioApi.es6 +++ b/core/src/plugins/gui.ajax/res/js/es6/http/PydioApi.es6 @@ -224,50 +224,14 @@ class PydioApi{ if(window.pydio && pydio.Parameters.get('SERVER_PREFIX_URI')){ PydioApi._libUrl = pydio.Parameters.get('SERVER_PREFIX_URI'); } - //var path = (PydioApi._libUrl?PydioApi._libUrl+'/'+fileName:fileName); - - /*if(window.jQuery && window.jQuery.ajax){ - jQuery.ajax(path, - { - method:'get', - async: (aSync?true:false), - complete:function(transport){ - if(transport.responseText) - { - try - { - var script = transport.responseText; - if (window.execScript){ - window.execScript( script ); - } - else{ - // TO TEST, THIS SEEM TO WORK ON SAFARI - window.my_code = script; - var script_tag = document.createElement('script'); - script_tag.type = 'text/javascript'; - script_tag.innerHTML = 'eval(window.my_code)'; - document.getElementsByTagName('head')[0].appendChild(script_tag); - } - if(onLoadedCode != null) onLoadedCode(); - } - catch(e) - { - alert('error loading '+fileName+':'+ e.message); - } - } - pydio.fire("server_answer"); - } - }); - }else */if(window.Connexion){ - - var conn = new Connexion(); - conn._libUrl = false; - if(pydio.Parameters.get('SERVER_PREFIX_URI')){ - conn._libUrl = pydio.Parameters.get('SERVER_PREFIX_URI'); - } - conn.loadLibrary(fileName, onLoadedCode, aSync); + var conn = new Connexion(); + conn._libUrl = false; + if(pydio.Parameters.get('SERVER_PREFIX_URI')){ + conn._libUrl = pydio.Parameters.get('SERVER_PREFIX_URI'); } + conn.loadLibrary(fileName, onLoadedCode, aSync); + } diff --git a/core/src/plugins/gui.ajax/res/js/es6/http/ResourcesManager.es6 b/core/src/plugins/gui.ajax/res/js/es6/http/ResourcesManager.es6 index 99be2bb101..1cdc79f304 100644 --- a/core/src/plugins/gui.ajax/res/js/es6/http/ResourcesManager.es6 +++ b/core/src/plugins/gui.ajax/res/js/es6/http/ResourcesManager.es6 @@ -85,28 +85,47 @@ class ResourcesManager{ } /** * Load resources - * @param resourcesRegistry $H Ajaxplorer ressources registry + * @param resourcesRegistry Pydio resources registry */ - load(resourcesRegistry, jsAutoloadOnly=false){ - if(this.loaded) return; - if(this.hasDependencies()){ + load(resourcesRegistry, jsAutoloadOnly=false, callback = FuncUtils.Empty){ + if(this.loaded) { + callback(); + return; + } + if(this.hasDependencies() && !this.dependenciesLoaded){ this.resources.dependencies.forEach(function(el){ if(resourcesRegistry[el]){ - resourcesRegistry[el].load(resourcesRegistry); + // Load dependencies and try again + resourcesRegistry[el].load(resourcesRegistry, false, function(){ + this.dependenciesLoaded = true; + this.load(resourcesRegistry, false, callback); + }.bind(this)); } }.bind(this) ); - } + } if(this.resources.forms){ this.resources.forms.forEach(function(value,key){ this.loadGuiForm(key, value); }.bind(this) ); } - if(this.resources.js){ - this.resources.js.forEach(function(value){ - if(jsAutoloadOnly && !value.autoload) return; - this.loadJSResource(value.fileName, value.className); - }.bind(this)); - } + if(this.resources.js){ + let it = this.resources.js.values(); + let cb = function(){ + let object = it.next(); + if(object.value){ + if(jsAutoloadOnly && !object.value.autoload) { + cb(); + return; + } + this.loadJSResource(object.value.fileName, object.value.className, cb, true); + }else{ + callback(); + } + }.bind(this); + cb(); + }else{ + callback(); + } if(this.resources.css){ this.resources.css.forEach(function(value){ this.loadCSSResource(value); @@ -381,10 +400,16 @@ class ResourcesManager{ }else{ // Load sync and apply the callback manually var loader = new ResourcesManager(); - modules.forEach(function(element){ - loader.loadJSResource(element.fileName, element.className, null, false); - }); - callbackFunc(); + let it = modules.values(); + let cb = function(){ + let object = it.next(); + if(object.value){ + loader.loadJSResource(object.value.fileName, object.value.className, cb, true); + }else{ + callbackFunc(); + } + }; + cb(); } } diff --git a/core/src/plugins/gui.ajax/res/js/es6/model/Registry.es6 b/core/src/plugins/gui.ajax/res/js/es6/model/Registry.es6 index 1f4ee3773a..7a2361c830 100644 --- a/core/src/plugins/gui.ajax/res/js/es6/model/Registry.es6 +++ b/core/src/plugins/gui.ajax/res/js/es6/model/Registry.es6 @@ -270,9 +270,10 @@ class Registry{ /** * Trigger the load method of the resourcesManager. * @param resourcesManager ResourcesManager + * @param callback triggered after JS loaded */ - loadEditorResources (resourcesManager){ - resourcesManager.load(this._resourcesRegistry); + loadEditorResources (resourcesManager, callback){ + resourcesManager.load(this._resourcesRegistry, false, callback); } /** diff --git a/core/src/plugins/gui.ajax/res/js/ui/reactjs/jsx/ReactUI/Builder.js b/core/src/plugins/gui.ajax/res/js/ui/reactjs/jsx/ReactUI/Builder.js index a06f59279e..d1ba97140e 100644 --- a/core/src/plugins/gui.ajax/res/js/ui/reactjs/jsx/ReactUI/Builder.js +++ b/core/src/plugins/gui.ajax/res/js/ui/reactjs/jsx/ReactUI/Builder.js @@ -181,13 +181,14 @@ } } if(editorData){ - this._pydio.Registry.loadEditorResources(editorData.resourcesManager); - var editorOpener = this.getEditorOpener(); - if(!editorOpener || editorData.modalOnly){ - modal.openEditorDialog(editorData); - }else{ - editorOpener.openEditorForNode(selectedNode, editorData); - } + this._pydio.Registry.loadEditorResources(editorData.resourcesManager, function(){ + var editorOpener = this.getEditorOpener(); + if(!editorOpener || editorData.modalOnly){ + modal.openEditorDialog(editorData); + }else{ + editorOpener.openEditorForNode(selectedNode, editorData); + } + }); }else{ if(this._pydio.Controller.getActionByName("download")){ this._pydio.Controller.getActionByName("download").apply();