1 /* 2 JUL - The JavaScript UI Language version 1.6.8 3 Copyright (c) 2012 - 2020 The Zonebuilder <zone.builder@gmx.com> 4 http://sourceforge.net/projects/jul-javascript/ 5 Licenses: GNU GPL2 or later; GNU LGPLv3 or later (http://sourceforge.net/p/jul-javascript/wiki/License/) 6 */ 7 /** 8 @fileOverview A class for working with references in JavaScript 9 */ 10 /* jshint browser: true, curly: true, eqeqeq: true, expr: true, funcscope: true, immed: true, latedef: true, 11 onevar: true, newcap: true, noarg: true, node: true, strict: true, trailing: true, undef: true, unused: vars, wsh: true */ 12 /* globals JUL */ 13 14 (function() { 15 'use strict'; 16 // JUL & tools always remain global namespaces 17 var jul = JUL; 18 19 /* generated by JCS version 1.5.8 */ 20 21 /** 22 Creates a writable reference of a member of the given object 23 @class A class for working with references in JavaScript 24 @param {Object} oRef The object to reference or a config object with 'ref' and 'key' properties 25 @param {String} sKey The name of the member to reference 26 @name JUL.Ref 27 */ 28 jul.ns('JUL.Ref'); 29 30 31 jul.ns('JUL.Ref', /** @lends JUL.Ref */ function (oRef, sKey) { 32 if (!(this instanceof JUL.Ref)) { 33 return new JUL.Ref(oRef, sKey); 34 } 35 if (typeof oRef === 'undefined') { return; } 36 if (typeof sKey === 'undefined') { 37 if (oRef && typeof oRef === 'string') { 38 oRef = oRef.replace(/\\\./g, ':::::').split('.'); 39 sKey = oRef.pop().replace(/:{5}/g, '.'); 40 oRef = JUL.getInstance(this).get(oRef.join('.').replace(/:{5}/g, '\\.')); 41 if (typeof oRef !== 'undefined') { 42 this._ref = oRef; 43 this._key = sKey; 44 } 45 } 46 else if (oRef instanceof JUL.Ref) { 47 JUL.apply(this, oRef); 48 } 49 else if (JUL.typeOf(oRef) === 'Object' && oRef.hasOwnProperty('ref') && oRef.hasOwnProperty('key')) { 50 if (oRef.nsRoot) { 51 this._getJulInstance = JUL._getAutoInstance(oRef.nsRoot); 52 } 53 this._ref = oRef.ref; 54 this._key = oRef.key; 55 for (var sMember in oRef) { 56 if (oRef.hasOwnProperty(sMember) && sMember !== 'key' && sMember !== 'ref' && sMember !== 'nsRoot') { 57 this[sMember] = oRef[sMember]; 58 } 59 } 60 } 61 } 62 else { 63 this._ref = oRef; 64 this._key = sKey; 65 } 66 }); 67 68 jul.apply(jul.get('JUL.Ref').prototype, /** @lends JUL.Ref.prototype */ { 69 /** 70 Applies JavaScript 'delete' operator on the referenced object member 71 @returns {Object} The reference itself 72 */ 73 del: function () { 74 delete this._ref[this._key]; 75 return this; 76 }, 77 /** 78 Gets or sets the name of the referenced member 79 @param {String} [sKey] The new name or index to set the member to. Omit to get the current one. 80 @returns {String} The name of the referenced member 81 */ 82 key: function (sKey) { 83 if (typeof sKey !== 'undefined') { 84 this._key = sKey; 85 return this; 86 } 87 return this._key; 88 }, 89 /** 90 Gets or sets the referenced object or the name of the referenced member 91 @param {Object} [oRef] The new object to reference. Omit to get the current object, set to true to get the property name 92 @param {String} [sKey] The new name of the member to reference 93 @returns {Mixed} The referenced object or member name if getting, nothing if setting 94 */ 95 ref: function (oRef, sKey) { 96 if (typeof oRef === 'undefined') { return this._ref; } 97 if (oRef === true) { return this._key; } 98 if (typeof sKey !== 'undefined') { this._key = sKey; } 99 else if (oRef && typeof oRef === 'string') { 100 oRef = oRef.replace(/\\\./g, ':::::').split('.'); 101 sKey = oRef.pop().replace(/:{5}/g, '.'); 102 oRef = JUL.getInstance(this).get(oRef.join('.').replace(/:{5}/g, '\\.')); 103 if (typeof oRef !== 'undefined') { 104 this._ref = oRef; 105 this._key = sKey; 106 } 107 return this; 108 } 109 if (oRef !== false) { this._ref = oRef; } 110 return this; 111 }, 112 /** 113 Gets or sets the value of the referenced member 114 @param {Object} [oVal] The new value to set the member to. Omit to get the current value 115 @returns {Mixed} The value of the referenced member 116 */ 117 val: function (oVal) { 118 if (typeof oVal !== 'undefined') { 119 this._ref[this._key] = oVal; 120 return this; 121 } 122 return this._ref[this._key]; 123 } 124 }); 125 126 })(); 127 128 /* end JUL.Ref.js */ 129