1/************************************************************************* 2 * 3 * ZOEY, INC. 4 * __________________ 5 * 6 * COPYRIGHT 2018 Zoey, Inc. 7 * All Rights Reserved. 8 * 9 * NOTICE: You are granted a non-exclusive and non-transferable license 10 * to use the Source Code of the Software provided under this License. 11 * This License is applicable to a single domain and server installation. 12 * Licensee may not resell, rent, lease or distribute the Source Code separately. 13 * Licensee may not use this Source Code to develop or distribute 14 * products that would compete with products marketed by the Licensor. 15 * All information contained herein is, and remains, 16 * the property of Zoey, Inc. and its suppliers, 17 * if any. The intellectual and technical concepts contained 18 * herein are proprietary to Zoey, Inc. and its suppliers and may 19 * be covered by U.S. and Foreign Patents, 20 * patents in process, and are protected by trade secret and/or copyright law. 21 * Dissemination of this information or reproduction of this material 22 * is strictly forbidden unless prior written permission is obtained 23 * from Zoey, Inc. 24 * Licensor's copyright notices must not be removed from the Source Code. 25 */ 26 27(function() { 28 // NOT FOR USE IN THE ADMIN!!!!!!!!!!! 29 // NOTE: this file should not have any external dependencies besides the Zoey module loader 30 31 var ZoeyCoreObserver = (function() { 32 var DEFAULT_KEY = '_ZoeyCoreObserver_'; 33 var ALL_KEY = '*'; 34 35 function ZoeyCoreObserver() { 36 this._listeners = {}; 37 } 38 39 ZoeyCoreObserver.prototype = { 40 _getDefaultKey: function(){ 41 return DEFAULT_KEY; 42 }, 43 _getAllKey: function(){ 44 return ALL_KEY; 45 }, 46 /** 47 * Add a listener 48 * @param {string|function} listener 49 * @param {function} [callback] 50 */ 51 add: function(listener){ 52 var key, callback; 53 54 if(typeof listener === 'function'){ 55 key = this._getDefaultKey(); 56 callback = listener; 57 } else if(typeof listener === 'string' && arguments.length === 2 && typeof arguments[1] === 'function'){ 58 key = listener; 59 callback = arguments[1]; 60 } 61 62 if(key && callback){ 63 if(!this._listeners[key]) 64 this._listeners[key] = []; 65 66 if (!this.has(key, callback)) 67 this._listeners[key].push(callback); 68 } 69 70 return this; 71 }, 72 /** 73 * Check if an observer of given identifier is registered 74 * @param {string|function} identifier 75 * @param {function} [callback] 76 * @returns {boolean} 77 */ 78 has: function(identifier) { 79 if(typeof identifier === 'string'){ 80 var key = identifier; 81 if(!this._listeners[key]) 82 return false; 83 84 if(arguments.length === 1){ 85 return !!this._listeners[key].length; 86 } else if(arguments.length === 2 && this._listeners.hasOwnProperty(key) && typeof arguments[1] === 'function'){ 87 var index = this._listeners[key].indexOf(arguments[1]); 88 return index >= 0; 89 } 90 91 } else if(typeof identifier === 'function'){ 92 for(var oKey in this._listeners){ 93 if(this._listeners.hasOwnProperty(oKey)){ 94 var listener = this._listeners[oKey]; 95 var rIndex = listener.indexOf(identifier); 96 if(rIndex >= 0) 97 return true; 98 } 99 } 100 } 101 102 return false; 103 }, 104 /** 105 * Remove a listener with either its key or its callback 106 * @param {string|function} identifier 107 * @param {function} [callback] 108 */ 109 remove: function(identifier){ 110 if(typeof identifier === 'string'){ 111 var key = identifier; 112 if(!this._listeners[key]) 113 return this; 114 115 if(arguments.length === 1){ 116 this._listeners[key] = null; 117 } else if(arguments.length === 2 && typeof arguments[1] === 'function'){ 118 var index = this._listeners[key].indexOf(arguments[1]); 119 if(index >= 0) 120 this._listeners[key].splice(index, 1); 121 } 122 123 124 } else if(typeof identifier === 'function'){ 125 for(var oKey in this._listeners){ 126 if(this._listeners.hasOwnProperty(oKey)){ 127 var listener = this._listeners[oKey]; 128 var rIndex = listener.indexOf(identifier); 129 if(rIndex >= 0) 130 listener.splice(rIndex, 1); 131 } 132 } 133 } 134 return this; 135 }, 136 removeAll: function(){ 137 this._listeners = {}; 138 return this; 139 }, 140 notify: function(key) { 141 var args = Array.prototype.slice.call(arguments, 1); 142 if (key) { 143 if (this._listeners.hasOwnProperty(key) && this._listeners[key]) {
144 this._listeners[key].slice().forEach(function(callback) { 145 callback.apply(callback, args); 146 }); 147 } 148 if (this._listeners.hasOwnProperty(this._getAllKey()) && this._listeners[this._getAllKey()]) { 149 this._listeners[this._getAllKey()].slice().forEach(function(callback) { 150 callback.apply(callback, args); 151 }); 152 } 153 } else { 154 this.notifyAll.apply(this, args); 155 } 156 157 return this; 158 }, 159 notifyAll: function(){ 160 var args = arguments; 161 Object.keys(this._listeners).forEach(function(key) { 162 if (this._listeners[key]) { 163 this._listeners[key].slice().forEach(function(callback) { 164 callback.apply(callback, args); 165 }); 166 } 167 }.bind(this)); 168 169 return this; 170 } 171 }; 172 173 return ZoeyCoreObserver; 174 })(); 175 176 var ZoeyDefer = (function() { 177 function ZoeyPromise(){ 178 this.queues = { 179 then: [], 180 catch: [], 181 done: [] 182 }; 183 } 184 185 ZoeyPromise.prototype = { 186 _isFunction: function(){ 187 return typeof arguments[0] === 'function'; 188 }, 189 then: function(cb, ecb, dcb){ 190 if(this._isFunction(cb)) this.queues.then.push(cb); 191 if(this._isFunction(ecb)) this.catch(ecb); 192 if(this._isFunction(dcb)) this.done(dcb); 193 194 return this; 195 }, 196 catch: function(cb){ 197 if(this._isFunction(cb)) this.queues.catch.push(cb); 198 return this; 199 }, 200 done: function(cb){ 201 if(this._isFunction(cb)) this.queues.done.push(cb); 202 return this; 203 } 204 }; 205 206 function ZoeyDefer(){ 207 this.promise = new ZoeyPromise(); 208 } 209 ZoeyDefer.prototype = { 210 resolve: function(){ 211 var args = Array.prototype.slice.call(arguments); 212 213 // try { 214 var data = args.slice(); 215 for(var i = 0, len = this.promise.queues.then.length; i<len; i++){ 216 data = this.promise.queues.then[i].apply(this, data); 217 } 218 // } catch(e) { 219 // console.log(e); 220 // } 221 222 return this; 223 }, 224 reject: function(){ 225 var args = Array.prototype.slice.call(arguments); 226 227 // try { 228 var data = args.slice(); 229 for(var i = 0, len = this.promise.queues.catch.length; i<len; i++){ 230 data = this.promise.queues.catch[i].apply(this, data); 231 } 232 // } catch(e) { 233 // console.log(e); 234 // } 235 236 return this; 237 } 238 }; 239 240 return ZoeyDefer; 241 })(); 242 243 var _observer = new ZoeyCoreObserver(); 244 245 var _idGenerator = (function(){ 246 var ids = { 247 _default: 0 248 }; 249 250 return { 251 getId: function(prefix) { 252 if (prefix && typeof prefix === 'string') { 253 if (!ids[prefix]) 254 ids[prefix] = 0; 255 256 return prefix + (++ids[prefix]); 257 } 258 259 return ++ids['_default']; 260 } 261 }; 262 })(); 263 264 var _isFullScreen = (function() { 265 var _fullScreenMethod; 266 267 return function() { 268 if (typeof _fullScreenMethod === 'undefined') { 269 if (typeof document.fullscreenEnabled !== 'undefined') { 270 _fullScreenMethod = function() { 271 return document.fullscreenEnabled; 272 }; 273 } else if (typeof document.fullscreen !== 'undefined') { 274 _fullScreenMethod = function() { 275 return document.fullscreen; 276 }; 277 } else if (typeof document.webkitIsFullScreen !== 'undefined') { 278 // chrome | opera 279 _fullScreenMethod = function() { 280 return document.webkitIsFullScreen; 281 }; 282 } else if (typeof document.mozFullScreen !== 'undefined') { 283 // Firefix 284 _fullScreenMethod = function() { 285 return document.mozFullScreen; 286 }; 287 } else { 288 _fullScreenMethod = function() { 289 return false;
290 }; 291 } 292 } 293 return _fullScreenMethod(); 294 }; 295 })(); 296 297 var zoeyCore = { 298 /** 299 * @return {ZoeyCoreObserver} 300 */ 301 getObserver: function() { 302 return new ZoeyCoreObserver(); 303 }, 304 /** 305 * @param {string} event 306 * @param {function} callback 307 * @return {zoeyCore} 308 */ 309 subscribe: function(event, callback) { 310 _observer.add(event, callback); 311 return this; 312 }, 313 /** 314 * @param {string} event 315 * @param {function} callback 316 * @return {zoeyCore} 317 */ 318 unsubscribe: function(event, callback) { 319 _observer.remove(event, callback); 320 return this; 321 }, 322 /** 323 * @param string event 324 * @return {zoeyCore} 325 */ 326 notify: function(event) { 327 _observer.notify.apply(_observer, arguments); 328 return this; 329 }, 330 /** 331 * @param prefix 332 * @return {string} 333 */ 334 generateId: function(prefix) { 335 return _idGenerator.getId(prefix); 336 }, 337 /** 338 * @return {boolean} 339 */ 340 isFullScreen: function() { 341 return _isFullScreen(); 342 }, 343 /** 344 * @return {ZoeyDefer} 345 */ 346 defer: function() { 347 return new ZoeyDefer(); 348 }, 349 /** 350 * Extends a child class with a parent class. 351 * Adds 'Super' property to the child class and its prototype 352 * Adds 'superDo' property to the child class and its prototype 353 * ex. 354 * ChildClass.Super.call(this); 355 * this.Super === SuperClass 356 * 357 * ChildClass.superDo.call(this, 'superMethod'[, arg1, arg2...]); 358 * this.superDo('superMethod'); 359 * 360 * @param {constructor} ChildClass 361 * @param {constructor} SuperClass 362 * @returns {constructor} ChildClass 363 */ 364 extendClass: function(ChildClass, SuperClass) { 365 function F() {} 366 F.prototype = SuperClass.prototype; 367 368 ChildClass.prototype = Object.assign(new F(), ChildClass.prototype || {}); 369 ChildClass.prototype.constructor = ChildClass; 370 /** 371 * Super Class 372 * @type {constructor} 373 */ 374 ChildClass.Super = ChildClass.prototype.Super = SuperClass; 375 /** 376 * Convenience method to call Super classes methods 377 * @type {function} 378 */ 379 ChildClass.superDo = ChildClass.prototype.superDo = function(method, args) { 380 args = Array.prototype.slice.call(arguments, 1); 381 return SuperClass.prototype[method].apply(this, args); 382 }; 383 384 return ChildClass; 385 } 386 }; 387 388 window.Zoey.export('zoey.core', zoeyCore); 389})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.