Created
August 19, 2013 08:49
-
-
Save Ahrengot/6266990 to your computer and use it in GitHub Desktop.
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() { | |
define(["underscore", "view/elements/DrawerElement"], function(_, DrawerElementView) { | |
var ConfigurationLoader; | |
ConfigurationLoader = (function() { | |
function ConfigurationLoader() { | |
_.bindAll(this); | |
this.load(); | |
} | |
ConfigurationLoader.prototype.getConfigId = function() { | |
var regex; | |
regex = /(.+?)config\/([0-9]+)\/?/; | |
return location.hash.replace(regex, "$2"); | |
}; | |
ConfigurationLoader.prototype.getJsonPath = function() { | |
return GLOBAL.BASE_URL + GLOBAL.JSON_TEMPLATES_DIR + ("/template" + (this.getConfigId()) + ".json"); | |
}; | |
ConfigurationLoader.prototype.load = function() { | |
return $.getJSON(this.getJsonPath()).then(this.parseConfiguration); | |
}; | |
ConfigurationLoader.prototype.parseConfiguration = function(data) { | |
var container, _i, _len, _ref; | |
_ref = data.nodes; | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
container = _ref[_i]; | |
this.buildContainer(container); | |
} | |
}; | |
ConfigurationLoader.prototype.getContainerView = function(name) { | |
var model; | |
model = app.config.elements.findWhere({ | |
name: name | |
}); | |
if (model) { | |
return new DrawerElementView({ | |
model: model | |
}); | |
} else { | |
return false; | |
} | |
}; | |
ConfigurationLoader.prototype.getElementPosition = function(el) { | |
if (this.artboardOffset == null) { | |
this.artboardOffset = app.artboard.$el.offset().left; | |
} | |
return { | |
x: el.position_x + this.artboardOffset, | |
y: el.position_y | |
}; | |
}; | |
ConfigurationLoader.prototype.buildContainer = function(container) { | |
var position, view; | |
view = this.getContainerView(container.element_name); | |
position = this.getElementPosition(container); | |
return $(document).trigger("ahrengot/spawn_element", [view, position]); | |
}; | |
return ConfigurationLoader; | |
})(); | |
return ConfigurationLoader; | |
}); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment