Merge pull request #15437 from nextcloud/refactor/oc-addscript-addstyle-bundle
Move the legacy OC.addScript and OC.addStyle helpers to the bundle
This commit is contained in:
commit
83679b33b8
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -117,48 +117,6 @@ Object.assign(window.OC, {
|
||||||
return result.join('/');
|
return result.join('/');
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Load a script for the server and load it. If the script is already loaded,
|
|
||||||
* the event handler will be called directly
|
|
||||||
* @param {string} app the app id to which the script belongs
|
|
||||||
* @param {string} script the filename of the script
|
|
||||||
* @param ready event handler to be called when the script is loaded
|
|
||||||
* @deprecated 16.0.0 Use OCP.Loader.loadScript
|
|
||||||
*/
|
|
||||||
addScript:function(app,script,ready){
|
|
||||||
var deferred, path=OC.filePath(app,'js',script+'.js');
|
|
||||||
if(!OC.addScript.loaded[path]) {
|
|
||||||
deferred = $.Deferred();
|
|
||||||
$.getScript(path, function() {
|
|
||||||
deferred.resolve();
|
|
||||||
});
|
|
||||||
OC.addScript.loaded[path] = deferred;
|
|
||||||
} else {
|
|
||||||
if (ready) {
|
|
||||||
ready();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return OC.addScript.loaded[path];
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Loads a CSS file
|
|
||||||
* @param {string} app the app id to which the css style belongs
|
|
||||||
* @param {string} style the filename of the css file
|
|
||||||
* @deprecated 16.0.0 Use OCP.Loader.loadStylesheet
|
|
||||||
*/
|
|
||||||
addStyle:function(app,style){
|
|
||||||
var path=OC.filePath(app,'css',style+'.css');
|
|
||||||
if(OC.addStyle.loaded.indexOf(path)===-1){
|
|
||||||
OC.addStyle.loaded.push(path);
|
|
||||||
if (document.createStyleSheet) {
|
|
||||||
document.createStyleSheet(path);
|
|
||||||
} else {
|
|
||||||
style=$('<link rel="stylesheet" type="text/css" href="'+path+'"/>');
|
|
||||||
$('head').append(style);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads translations for the given app asynchronously.
|
* Loads translations for the given app asynchronously.
|
||||||
*
|
*
|
||||||
|
@ -511,9 +469,6 @@ Object.assign(window.OC, {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
OC.addStyle.loaded=[];
|
|
||||||
OC.addScript.loaded=[];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes core
|
* Initializes core
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {addScript, addStyle} from './legacy-loader'
|
||||||
import Apps from './apps'
|
import Apps from './apps'
|
||||||
import {AppConfig, appConfig} from './appconfig'
|
import {AppConfig, appConfig} from './appconfig'
|
||||||
import appswebroots from './appswebroots'
|
import appswebroots from './appswebroots'
|
||||||
|
@ -84,6 +85,8 @@ export default {
|
||||||
PERMISSION_UPDATE,
|
PERMISSION_UPDATE,
|
||||||
TAG_FAVORITE,
|
TAG_FAVORITE,
|
||||||
|
|
||||||
|
addScript,
|
||||||
|
addStyle,
|
||||||
Apps,
|
Apps,
|
||||||
AppConfig,
|
AppConfig,
|
||||||
appConfig,
|
appConfig,
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import $ from 'jquery'
|
||||||
|
|
||||||
|
const loadedScripts = {}
|
||||||
|
const loadedStyles = []
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a script for the server and load it. If the script is already loaded,
|
||||||
|
* the event handler will be called directly
|
||||||
|
* @param {string} app the app id to which the script belongs
|
||||||
|
* @param {string} script the filename of the script
|
||||||
|
* @param ready event handler to be called when the script is loaded
|
||||||
|
* @deprecated 16.0.0 Use OCP.Loader.loadScript
|
||||||
|
*/
|
||||||
|
export const addScript = (app, script, ready) => {
|
||||||
|
console.warn('OC.addScript is deprecated, use OCP.Loader.loadScript instead')
|
||||||
|
|
||||||
|
let deferred
|
||||||
|
const path = OC.filePath(app, 'js', script + '.js')
|
||||||
|
if (!loadedScripts[path]) {
|
||||||
|
deferred = $.Deferred()
|
||||||
|
$.getScript(path, () => deferred.resolve())
|
||||||
|
loadedScripts[path] = deferred
|
||||||
|
} else {
|
||||||
|
if (ready) {
|
||||||
|
ready()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return loadedScripts[path]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a CSS file
|
||||||
|
* @param {string} app the app id to which the css style belongs
|
||||||
|
* @param {string} style the filename of the css file
|
||||||
|
* @deprecated 16.0.0 Use OCP.Loader.loadStylesheet
|
||||||
|
*/
|
||||||
|
export const addStyle = (app, style) => {
|
||||||
|
console.warn('OC.addStyle is deprecated, use OCP.Loader.loadStylesheet instead')
|
||||||
|
|
||||||
|
const path = OC.filePath(app, 'css', style + '.css')
|
||||||
|
if (loadedStyles.indexOf(path) === -1) {
|
||||||
|
loadedStyles.push(path)
|
||||||
|
if (document.createStyleSheet) {
|
||||||
|
document.createStyleSheet(path)
|
||||||
|
} else {
|
||||||
|
style = $('<link rel="stylesheet" type="text/css" href="' + path + '"/>')
|
||||||
|
$('head').append(style)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue