Move OC.get and OC.set to the bundle

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2019-04-29 17:50:34 +02:00
parent c60f6716b4
commit ae8959af74
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
5 changed files with 65 additions and 43 deletions

10
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

@ -1113,41 +1113,4 @@ if (window.history.pushState) {
else {
$(window).on('hashchange', _.bind(OC.Util.History._onPopState, OC.Util.History));
}
/**
* Get a variable by name
* @param {string} name
* @return {*}
*/
OC.get=function(name) {
var namespaces = name.split(".");
var tail = namespaces.pop();
var context=window;
for(var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
if(!context){
return false;
}
}
return context[tail];
};
/**
* Set a variable by name
* @param {string} name
* @param {*} value
*/
OC.set=function(name, value) {
var namespaces = name.split(".");
var tail = namespaces.pop();
var context=window;
for(var i = 0; i < namespaces.length; i++) {
if(!context[namespaces[i]]){
context[namespaces[i]]={};
}
context = context[namespaces[i]];
}
context[tail]=value;
};

56
core/src/OC/get_set.js Normal file
View File

@ -0,0 +1,56 @@
/*
* @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/>.
*/
/**
* Get a variable by name
* @param {string} name
* @return {*}
*/
export const get = context => name => {
const namespaces = name.split('.')
const tail = namespaces.pop()
for (var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]]
if (!context) {
return false
}
}
return context[tail]
}
/**
* Set a variable by name
* @param {string} name
* @param {*} value
*/
export const set = context => (name, value) => {
const namespaces = name.split(".")
const tail = namespaces.pop()
for (let i = 0; i < namespaces.length; i++) {
if (!context[namespaces[i]]) {
context[namespaces[i]] = {}
}
context = context[namespaces[i]]
}
context[tail] = value
}

View File

@ -26,6 +26,7 @@ import Config from './config'
import ContactsMenu from './contactsmenu'
import Dialogs from './dialogs'
import EventSource from './eventsource'
import {get, set} from './get_set'
import {isUserAdmin} from './admin'
import L10N from './l10n'
import {
@ -67,6 +68,8 @@ export default {
Util,
debug,
generateUrl,
get: get(window),
set: set(window),
getRootPath,
filePath,
redirect,