add OC.get and OC.set to get/set variables by name in javascript
This commit is contained in:
parent
898ca364a2
commit
8990855f88
|
@ -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') ];
|
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();
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue