Add the LICENSE.txt file
[armadillo.git] / frontend / utils.js
1 //
2 // Armadillo File Manager
3 // Copyright (c) 2011, Robert Sesek <http://www.bluestatic.org>
4 //
5 // This program is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation, either version 3 of the License, or any later version.
8 //
9
10 $.extend({
11 /**
12 * Defines a namespace.
13 * @param {string} ns
14 */
15 namespace: function(ns) {
16 var parent = window;
17 this.each(ns.split('.'), function (i, space) {
18 parent[space] = parent[space] || {};
19 parent = parent[space];
20 });
21 },
22
23 /**
24 * Shortcut for creating a DOM element.
25 * @param {string} elm
26 */
27 createDom: function(elm) {
28 return this(document.createElement(elm));
29 }
30 });
31
32 // Not all browsers (notably Safari) support ES5 Function.bind(). This is a
33 // rough approximation from:
34 // <https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind>.
35 if (!Function.prototype.bind) {
36 Function.prototype.bind = function (oThis) {
37 if (typeof this !== "function") {
38 // closest thing possible to the ECMAScript 5 internal IsCallable function
39 throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
40 }
41
42 var aArgs = Array.prototype.slice.call(arguments, 1);
43 var fToBind = this;
44 var fNOP = function () {};
45 var fBound = function () {
46 return fToBind.apply(this instanceof fNOP ? this : oThis || window,
47 aArgs.concat(Array.prototype.slice.call(arguments)));
48 };
49
50 fNOP.prototype = this.prototype;
51 fBound.prototype = new fNOP();
52 return fBound;
53 };
54 }