aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
authorValerio Virgillito2012-02-16 21:49:35 -0800
committerValerio Virgillito2012-02-16 21:49:35 -0800
commit9f0c4efe2ed9a00f2c5d85c9d88a8040fedb5d8f (patch)
tree19aa9599e0cc37a126df9d61f7e6f6d4baaae75d /js/lib
parent09f3c65dcbb4d21b75b7fe591c52cb9b9750bf3f (diff)
parente0bead5a36ae987c558607b77745c4018caf59f8 (diff)
downloadninja-9f0c4efe2ed9a00f2c5d85c9d88a8040fedb5d8f.tar.gz
Merge pull request #50 from mencio/canvas-data
Adding canvas data attributes
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/NJUtils.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js
index 8daafa42..887743c5 100755
--- a/js/lib/NJUtils.js
+++ b/js/lib/NJUtils.js
@@ -5,6 +5,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
5</copyright> */ 5</copyright> */
6 6
7var Montage = require("montage/core/core").Montage, 7var Montage = require("montage/core/core").Montage,
8 Uuid = require("montage/core/uuid").Uuid,
8 ElementModel = require("js/models/element-model").ElementModel, 9 ElementModel = require("js/models/element-model").ElementModel,
9 Properties3D = require("js/models/properties-3d").Properties3D, 10 Properties3D = require("js/models/properties-3d").Properties3D,
10 ShapeModel = require("js/models/shape-model").ShapeModel, 11 ShapeModel = require("js/models/shape-model").ShapeModel,
@@ -56,13 +57,18 @@ exports.NJUtils = Object.create(Object.prototype, {
56 57
57 ///// Quick "createElement" function "attr" can be classname or object 58 ///// Quick "createElement" function "attr" can be classname or object
58 ///// with attribute key/values 59 ///// with attribute key/values
60 ///// Suppor for data attributes
59 make : { 61 make : {
60 value: function(tag, attr) { 62 value: function(tag, attr) {
61 var el = document.createElement(tag); 63 var el = document.createElement(tag);
62 if (typeof attr === 'object') { 64 if (typeof attr === 'object') {
63 for (var a in attr) { 65 for (var a in attr) {
64 if (attr.hasOwnProperty(a)) { 66 if (attr.hasOwnProperty(a)) {
65 el[a] = attr[a]; 67 if(a.indexOf("data-") > -1) {
68 el.setAttribute(a, attr[a]);
69 } else {
70 el[a] = attr[a];
71 }
66 } 72 }
67 } 73 }
68 } else if (typeof attr === 'string') { 74 } else if (typeof attr === 'string') {
@@ -247,6 +253,20 @@ exports.NJUtils = Object.create(Object.prototype, {
247 } 253 }
248 return status; 254 return status;
249 } 255 }
256 },
257
258 /* ================= misc methods ================= */
259
260 // Generates an alpha-numeric random number
261 // len: number of chars
262 // default length is '8'
263 generateRandom: {
264 value: function(len) {
265 var length;
266 len ? length = len : length = 8;
267
268 return Uuid.generate().substring(0,length);
269 }
250 } 270 }
251 271
252}); 272});