Permalink
Browse files

Setting the visibility of X.volumes did not work properly.

The reason was that injects in the constructor overwrote any prototype defined getters/setters and therefor the special case of the visible-setter for X.volumes was fully ignored. The inject functionality now checks if a setter was previously defined on the prototype and then does not replace it.
  • Loading branch information...
1 parent 1798af4 commit f4a13854de39a9902a54bcfffe5b46519c1eea3d Daniel Haehn committed Apr 17, 2013
Showing with 110 additions and 74 deletions.
  1. +75 −71 X.js
  2. +34 −2 objects/volume.js
  3. +1 −1 xtk-deps.js
View
146 X.js
@@ -1,30 +1,30 @@
/*
- *
+ *
* xxxxxxx xxxxxxx
- * x:::::x x:::::x
- * x:::::x x:::::x
- * x:::::xx:::::x
- * x::::::::::x
- * x::::::::x
- * x::::::::x
- * x::::::::::x
- * x:::::xx:::::x
- * x:::::x x:::::x
- * x:::::x x:::::x
+ * x:::::x x:::::x
+ * x:::::x x:::::x
+ * x:::::xx:::::x
+ * x::::::::::x
+ * x::::::::x
+ * x::::::::x
+ * x::::::::::x
+ * x:::::xx:::::x
+ * x:::::x x:::::x
+ * x:::::x x:::::x
* THE xxxxxxx xxxxxxx TOOLKIT
- *
+ *
* http://www.goXTK.com
- *
+ *
* Copyright (c) 2012 The X Toolkit Developers <dev@goXTK.com>
- *
+ *
* The X Toolkit (XTK) is licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
- *
+ *
* "Free software" is a matter of liberty, not price.
* "Free" as in "free speech", not as in "free beer".
* - Richard M. Stallman
- *
- *
+ *
+ *
*/
// entry point
@@ -34,90 +34,90 @@ goog.provide('X.counter');
/**
* The XTK namespace.
- *
+ *
* @const
*/
var X = X || {};
/**
* Can be used to check if the XTK library was compiled.
- *
+ *
* <pre>
* if (X.DEV === undefined) {
* // xtk was compiled
* }
* </pre>
- *
+ *
* @type {boolean}
*/
X.DEV = true;
/**
* Timer functionality which can be used in developer mode to clock certain
* things.
- *
+ *
* <pre>
* X.TIMER(this._classname+'.functionname');
- *
+ *
* ... stuff is happening
* </pre>
- *
+ *
* @param {string} what The title of this timer.
*/
X.TIMER = function(what) {
if (eval('X.DEV === undefined')) {
return;
}
-
+
window.console.time(what);
-
+
};
/**
* Timer functionality which can be used in developer mode to clock certain
* things.
- *
+ *
* <pre>
- * ... stuff was happening
- *
+ * ... stuff was happening
+ *
* X.TIMERSTOP(this._classname+'.functionname');
* </pre>
- *
+ *
* @param {string} what The title of this timer.
*/
X.TIMERSTOP = function(what) {
if (eval('X.DEV === undefined')) {
return;
}
-
+
window.console.timeEnd(what);
-
+
};
/**
* The counter class, keeping track of instance ids.
- *
+ *
* @constructor
*/
X.counter = function() {
this._counter = 0;
-
+
/**
* Get a unique id.
- *
+ *
* @return {number} A unique id
*/
this.uniqueId = function() {
// return a unique id
return this._counter++;
-
+
};
-
+
};
window["X.counter"] = new X.counter();
@@ -128,28 +128,32 @@ window["X.counter"] = new X.counter();
* http://ejohn.org/blog/javascript-getters-and-setters/) which means copying
* properties, getters/setters and functions from a source object to a target.
* Works best on instances.
- *
+ *
* @param {Object} a The target object.
* @param {Object} b The source object.
* @return {Object} The altered object.
*/
function inject(a, b) {
- for ( var i in b) { // iterate over all properties
+ for ( var i in b ) { // iterate over all properties
+
// get getter and setter functions
var g = b.__lookupGetter__(i), s = b.__lookupSetter__(i);
-
+
+ if (i in a) { continue; }
+
if (g || s) { // if there is a getter or setter
if (g) {
- a.__defineGetter__(i, g); // copy getter to new object
+ a.__defineGetter__(i, g); // copy getter to new object but only if it is not defined yet
}
if (s) {
- a.__defineSetter__(i, s); // copy setter to new object
+ a.__defineSetter__(i, s); // copy setter to new object but only if it is not defined yet
}
} else {
a[i] = b[i]; // just copy the value; nothing special
}
}
+
return a; // return the altered object
}
@@ -165,39 +169,39 @@ var $ = window.$;
// XTK's event mechanism. This hack fixes this.
//
function bind_shim() {
-
+
if (!Function.prototype.bind) {
-
+
Function.prototype.bind = function(oThis) {
-
+
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError(
"Function.prototype.bind - what is trying to be bound is not callable");
}
-
+
var fSlice = Array.prototype.slice, aArgs = fSlice.call(arguments, 1), fToBind = this;
-
+
/**
* @constructor
*/
var fNOP = function() {
-
+
};
-
+
var fBound = function() {
-
+
return fToBind.apply(this instanceof fNOP ? this : oThis || window, aArgs
.concat(fSlice.call(arguments)));
};
-
+
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
-
+
return fBound;
};
}
-
+
}
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
@@ -209,39 +213,39 @@ function bind_shim() {
// from: https://gist.github.com/1579671
function requestAnimationFrame_shim() {
-
+
(function() {
-
+
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for ( var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||
window[vendors[x] + 'CancelRequestAnimationFrame'];
}
-
+
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function(callback, element) {
-
+
var currTime = Date.now(); // changed this to avoid new object each time
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() {
-
+
callback(currTime + timeToCall);
}, timeToCall);
lastTime = currTime + timeToCall;
return id;
};
}
-
+
if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function(id) {
-
+
clearTimeout(id);
};
}
}());
-
+
}
@@ -262,18 +266,18 @@ function arrayBufferSlice_shim() {
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-
+
// Attach a slice() method to ArrayBuffer, since our C++ implementation
// doesn't
// have one. A JS version is much easier to implement, though it won't be as
// fast.
-
+
// Don't attempt to replace an already-working slice method.
if (!('slice' in ArrayBuffer.prototype)) {
/**
* Slice an array buffer, as defined here:
* http://www.khronos.org/registry/typedarray/specs/latest/
- *
+ *
* @param {number} start The start index, inclusive. If negative, this is
* interpreted as an index from the end of the array.
* @param {number=} opt_end The end index, exclusive. If negative, this is
@@ -288,10 +292,10 @@ function arrayBufferSlice_shim() {
if (start === undefined) {
throw new Error('Not enough arguments.');
}
-
+
// Handle missing end arguments.
var end = opt_end || this.byteLength;
-
+
// Interpret negative values as indices from the end of the array. Convert
// them to indices from the beginning.
if (start < 0) {
@@ -300,37 +304,37 @@ function arrayBufferSlice_shim() {
if (end < 0) {
end = this.byteLength + end;
}
-
+
// Handle negative-length slices.
if (end < start) {
start = 0;
end = 0;
}
-
+
// Clamp the range.
if (start < 0) {
start = 0;
}
if (end < 0) {
end = 0;
}
-
+
if (start > this.byteLength) {
start = this.byteLength;
}
if (end > this.byteLength) {
end = this.byteLength;
}
-
+
// Create a new buffer, and copy data into it.
var result = new ArrayBuffer(end - start);
var inBytes = new Uint8Array(this);
var outBytes = new Uint8Array(result);
-
+
for ( var inIndex = start, outIndex = 0; inIndex < end; ++inIndex, ++outIndex) {
outBytes[outIndex] = inBytes[inIndex];
}
-
+
return result;
};
}
Oops, something went wrong.

0 comments on commit f4a1385

Please sign in to comment.