This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getKeyValue(object, path, default_value){ | |
"use strict" | |
if (typeof object === 'undefined') { | |
return default_value; | |
} | |
let prop_cont_pair = path.split('.'); | |
let prop = prop_cont_pair[0]; | |
let cont = prop_cont_pair.slice(1).join('.'); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setKeyValue(object, path, value) { | |
var prop_cont_pair = path.split('.'); | |
var prop = prop_cont_pair[0]; | |
var cont = prop_cont_pair.slice(1).join('.'); | |
if (cont === '') { | |
object[prop] = value; | |
} else { | |
if(typeof object[prop] === 'undefined') { | |
object[prop] = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.contains = function(element) { | |
return this.indexOf(element) !== -1; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hasClass(element, class_name) { | |
return element.classList.contains(class_name); | |
} | |
function addClass(element, class_name) { | |
if (!hasClass(element, class_name)) { | |
element.classList.add(class_name) | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function KeyboardController(keys, repeat) { | |
var timers = {}; | |
document.addEventListener('keydown', function(event) { | |
var key = event.keyCode; | |
if (!(key in keys)) | |
return true; | |
if (!(key in timers)) { | |
timers[key] = null; | |
keys[key](event); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function augment(obj, function_name, new_function) { | |
var original = obj[function_name]; | |
obj[function_name] = function () { | |
new_function.bind(this, original).apply(this, arguments); | |
original.bind(this).apply(this, arguments); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.remove = function (element) { | |
while (this.contains(element)) { | |
this.splice(this.indexOf(element), 1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.assert = function assert(condition) { | |
if (!condition) { | |
debugger; | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.call_super = function call_super(obj, name) { | |
var super_class = Object.getPrototypeOf(Object.getPrototypeOf(obj)); | |
return (function () { | |
super_class[name].apply(obj, arguments); | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function __module(base, name, func) { | |
if (typeof base[name] === 'undefined') { | |
base[name] = {}; | |
} | |
func(base[name]); | |
} | |
//usage: | |
// __module(window.MyModule, 'namespace', function (exports) { | |
// exports.sayHello = function () { |
OlderNewer