diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-08-29 21:52:42 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-08-30 03:02:29 +0200 |
commit | 8990855f88c8cf0803bcf7220699c54b46b0d546 (patch) | |
tree | 8ca6d52be6be0b0f2d02227b2b79eb783e4cc743 /core/js | |
parent | 898ca364a2d59406b8a7f8c30b1aec899f80f531 (diff) | |
download | nextcloud-server-8990855f88c8cf0803bcf7220699c54b46b0d546.tar.gz nextcloud-server-8990855f88c8cf0803bcf7220699c54b46b0d546.zip |
add OC.get and OC.set to get/set variables by name in javascript
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/js.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/core/js/js.js b/core/js/js.js index c38eebbff29..0a7c84f61da 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -587,3 +587,40 @@ function formatDate(date){ t('files','July'), t('files','August'), t('files','September'), t('files','October'), t('files','November'), t('files','December') ]; return monthNames[date.getMonth()]+' '+date.getDate()+', '+date.getFullYear()+', '+((date.getHours()<10)?'0':'')+date.getHours()+':'+((date.getMinutes()<10)?'0':'')+date.getMinutes(); } + +/** + * get a variable by name + * @param string name + */ +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 mixed 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; +} |