Commit f1588738 by Valera Rozuvan Committed by Alexander Kryklia

Refactoring.

parent 35174dd3
...@@ -163,10 +163,15 @@ define(['logme'], function (logme) { ...@@ -163,10 +163,15 @@ define(['logme'], function (logme) {
if (!attrIsString(obj, 'icon')) { if (!attrIsString(obj, 'icon')) {
return false; return false;
} }
if (!attrIsString(obj, 'label')) { if (!attrIsString(obj, 'label')) {
return false; return false;
} }
if (!attrIsBoolean(obj, 'can_reuse', false)) {
return false;
}
state.config.draggables.push(obj); state.config.draggables.push(obj);
return true; return true;
...@@ -197,7 +202,11 @@ define(['logme'], function (logme) { ...@@ -197,7 +202,11 @@ define(['logme'], function (logme) {
} }
function attrIsString(obj, attr) { function attrIsString(obj, attr) {
if (typeof obj[attr] !== 'string') { if (obj.hasOwnProperty(attr) === false) {
logme('ERROR: Attribute "obj.' + attr + '" is not present.');
return false;
} else if (typeof obj[attr] !== 'string') {
logme('ERROR: Attribute "obj.' + attr + '" is not a string.'); logme('ERROR: Attribute "obj.' + attr + '" is not a string.');
return false; return false;
...@@ -209,6 +218,12 @@ define(['logme'], function (logme) { ...@@ -209,6 +218,12 @@ define(['logme'], function (logme) {
function attrIsInteger(obj, attr) { function attrIsInteger(obj, attr) {
var tempInt; var tempInt;
if (obj.hasOwnProperty(attr) === false) {
logme('ERROR: Attribute "obj.' + attr + '" is not present.');
return false;
}
tempInt = parseInt(obj[attr], 10); tempInt = parseInt(obj[attr], 10);
if (isFinite(tempInt) === false) { if (isFinite(tempInt) === false) {
...@@ -221,6 +236,34 @@ define(['logme'], function (logme) { ...@@ -221,6 +236,34 @@ define(['logme'], function (logme) {
return true; return true;
} }
function attrIsBoolean(obj, attr, defaultVal) {
if (obj.hasOwnProperty(attr) === false) {
if (defaultVal === undefined) {
logme('ERROR: Attribute "obj.' + attr + '" is not present.');
return false;
} else {
obj[attr] = defaultVal;
return true;
}
}
if (obj[attr] === '') {
obj[attr] = defaultVal;
} else if ((obj[attr] === 'false') || (obj[attr] === false)) {
obj[attr] = false;
} else if ((obj[attr] === 'true') || (obj[attr] === true)) {
obj[attr] = true;
} else {
logme('ERROR: Attribute "obj.' + attr + '" is not a boolean.');
return false;
}
return true;
}
}); });
// End of wrapper for RequireJS. As you can see, we are passing // End of wrapper for RequireJS. As you can see, we are passing
......
...@@ -195,6 +195,13 @@ define(['logme', 'update_input'], function (logme, updateInput) { ...@@ -195,6 +195,13 @@ define(['logme', 'update_input'], function (logme, updateInput) {
var draggableObj; var draggableObj;
draggableObj = { draggableObj = {
'id': obj.id,
'isReusable': obj.can_reuse,
'x': -1,
'y': -1,
'zIndex': objIndex, 'zIndex': objIndex,
'oldZIndex': objIndex, 'oldZIndex': objIndex,
'labelEl': null, 'labelEl': null,
...@@ -373,12 +380,15 @@ define(['logme', 'update_input'], function (logme, updateInput) { ...@@ -373,12 +380,15 @@ define(['logme', 'update_input'], function (logme, updateInput) {
'top', 'top',
50 - draggableObj.iconHeightSmall * 0.5 50 - draggableObj.iconHeightSmall * 0.5
); );
draggableObj.hasLoaded = true;
} else { } else {
// If no icon and no label, don't create a draggable. // If no icon and no label, don't create a draggable.
return; return;
} }
} }
// Attach events to "iconEl".
draggableObj.iconEl.mousedown(function (event) { draggableObj.iconEl.mousedown(function (event) {
draggableObj.mouseDown.call(draggableObj, event); draggableObj.mouseDown.call(draggableObj, event);
}); });
...@@ -389,6 +399,7 @@ define(['logme', 'update_input'], function (logme, updateInput) { ...@@ -389,6 +399,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
draggableObj.mouseMove.call(draggableObj, event); draggableObj.mouseMove.call(draggableObj, event);
}); });
// Attach events to "containerEl".
draggableObj.containerEl.mousedown(function (event) { draggableObj.containerEl.mousedown(function (event) {
draggableObj.mouseDown.call(draggableObj, event); draggableObj.mouseDown.call(draggableObj, event);
}); });
...@@ -399,16 +410,7 @@ define(['logme', 'update_input'], function (logme, updateInput) { ...@@ -399,16 +410,7 @@ define(['logme', 'update_input'], function (logme, updateInput) {
draggableObj.mouseMove.call(draggableObj, event); draggableObj.mouseMove.call(draggableObj, event);
}); });
draggableObj.id = obj.id;
draggableObj.x = -1;
draggableObj.y = -1;
state.numDraggablesInSlider += 1; state.numDraggablesInSlider += 1;
if (obj.icon.length === 0) {
draggableObj.hasLoaded = true;
}
state.draggables.push(draggableObj); state.draggables.push(draggableObj);
} }
......
...@@ -70,6 +70,10 @@ define( ...@@ -70,6 +70,10 @@ define(
if (updateInput.check(state) === false) { if (updateInput.check(state) === false) {
updateInput.update(state); updateInput.update(state);
} }
setTimeout(function () {
logme('state.draggables', state.draggables);
}, 500);
}()); }());
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment