Move OC.get and OC.set to the bundle
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
c60f6716b4
commit
ae8959af74
5 changed files with 59 additions and 37 deletions
BIN
core/js/dist/main.js
vendored
BIN
core/js/dist/main.js
vendored
Binary file not shown.
BIN
core/js/dist/main.js.map
vendored
BIN
core/js/dist/main.js.map
vendored
Binary file not shown.
|
@ -1113,41 +1113,4 @@ if (window.history.pushState) {
|
||||||
else {
|
else {
|
||||||
$(window).on('hashchange', _.bind(OC.Util.History._onPopState, OC.Util.History));
|
$(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
56
core/src/OC/get_set.js
Normal 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
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ import Config from './config'
|
||||||
import ContactsMenu from './contactsmenu'
|
import ContactsMenu from './contactsmenu'
|
||||||
import Dialogs from './dialogs'
|
import Dialogs from './dialogs'
|
||||||
import EventSource from './eventsource'
|
import EventSource from './eventsource'
|
||||||
|
import {get, set} from './get_set'
|
||||||
import {isUserAdmin} from './admin'
|
import {isUserAdmin} from './admin'
|
||||||
import L10N from './l10n'
|
import L10N from './l10n'
|
||||||
import {
|
import {
|
||||||
|
@ -67,6 +68,8 @@ export default {
|
||||||
Util,
|
Util,
|
||||||
debug,
|
debug,
|
||||||
generateUrl,
|
generateUrl,
|
||||||
|
get: get(window),
|
||||||
|
set: set(window),
|
||||||
getRootPath,
|
getRootPath,
|
||||||
filePath,
|
filePath,
|
||||||
redirect,
|
redirect,
|
||||||
|
|
Loading…
Reference in a new issue