Move the legacy OC.addScript and OC.addStyle helpers to the bundle

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2019-05-08 10:03:13 +02:00
parent df1f53c5c3
commit 73f9f15607
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
7 changed files with 89 additions and 60 deletions

14
core/js/dist/login.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

12
core/js/dist/main.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -117,48 +117,6 @@ Object.assign(window.OC, {
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.
*
@ -511,9 +469,6 @@ Object.assign(window.OC, {
}
});
OC.addStyle.loaded=[];
OC.addScript.loaded=[];
/**
* Initializes core
*/

View File

@ -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,

View File

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