diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-05-08 10:03:13 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-05-08 19:58:43 +0200 |
commit | 73f9f15607ba23f37ef78b84b6240cce49c1b69b (patch) | |
tree | b63d7141168bb5c464375f27d4087a91b882a52f /core/src/OC | |
parent | df1f53c5c343ff6ac9c7bbe616b2c0cffe8a6380 (diff) | |
download | nextcloud-server-73f9f15607ba23f37ef78b84b6240cce49c1b69b.tar.gz nextcloud-server-73f9f15607ba23f37ef78b84b6240cce49c1b69b.zip |
Move the legacy OC.addScript and OC.addStyle helpers to the bundle
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'core/src/OC')
-rw-r--r-- | core/src/OC/index.js | 3 | ||||
-rw-r--r-- | core/src/OC/legacy-loader.js | 71 |
2 files changed, 74 insertions, 0 deletions
diff --git a/core/src/OC/index.js b/core/src/OC/index.js index a27695d8eda..81cf002e47f 100644 --- a/core/src/OC/index.js +++ b/core/src/OC/index.js @@ -19,6 +19,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import {addScript, addStyle} from './legacy-loader' import Apps from './apps' import {AppConfig, appConfig} from './appconfig' import appswebroots from './appswebroots' @@ -84,6 +85,8 @@ export default { PERMISSION_UPDATE, TAG_FAVORITE, + addScript, + addStyle, Apps, AppConfig, appConfig, diff --git a/core/src/OC/legacy-loader.js b/core/src/OC/legacy-loader.js new file mode 100644 index 00000000000..a2c76c2e3ab --- /dev/null +++ b/core/src/OC/legacy-loader.js @@ -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) + } + } +} |