moving widgets and variables code out of ajaxify
parent
0dd7339bec
commit
b023ef01af
@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
/*global ajaxify*/
|
||||
|
||||
(function(ajaxify) {
|
||||
var parsedVariables = {};
|
||||
|
||||
ajaxify.variables = {};
|
||||
|
||||
ajaxify.variables.set = function(key, value) {
|
||||
parsedVariables[key] = value;
|
||||
};
|
||||
|
||||
ajaxify.variables.get = function(key) {
|
||||
return parsedVariables[key];
|
||||
};
|
||||
|
||||
ajaxify.variables.flush = function() {
|
||||
parsedVariables = {};
|
||||
};
|
||||
|
||||
ajaxify.variables.parse = function() {
|
||||
$('#content [template-variable]').each(function(index, element) {
|
||||
var value = null;
|
||||
|
||||
switch ($(element).attr('template-type')) {
|
||||
case 'boolean':
|
||||
value = ($(element).val() === 'true' || $(element).val() === '1') ? true : false;
|
||||
break;
|
||||
case 'int':
|
||||
case 'integer':
|
||||
value = parseInt($(element).val());
|
||||
break;
|
||||
default:
|
||||
value = $(element).val();
|
||||
break;
|
||||
}
|
||||
|
||||
ajaxify.variables.set($(element).attr('template-variable'), value);
|
||||
});
|
||||
};
|
||||
}(ajaxify || {}));
|
@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
/*global ajaxify, socket, templates*/
|
||||
|
||||
(function(ajaxify) {
|
||||
ajaxify.widgets.reposition = function() {
|
||||
$('body [no-widget-class]').each(function() {
|
||||
var $this = $(this);
|
||||
$this.removeClass();
|
||||
$this.addClass($this.attr('no-widget-class'));
|
||||
});
|
||||
};
|
||||
|
||||
ajaxify.widgets.render = function(tpl_url, url, callback) {
|
||||
var widgetLocations = [], numLocations;
|
||||
|
||||
$('#content [widget-area]').each(function() {
|
||||
widgetLocations.push($(this).attr('widget-area'));
|
||||
});
|
||||
|
||||
numLocations = widgetLocations.length;
|
||||
|
||||
if (!numLocations) {
|
||||
ajaxify.widgets.reposition();
|
||||
}
|
||||
|
||||
function renderWidgets(location) {
|
||||
var area = $('#content [widget-area="' + location + '"]');
|
||||
|
||||
socket.emit('widgets.render', {template: tpl_url + '.tpl', url: url, location: location}, function(err, renderedWidgets) {
|
||||
if (area.html()) {
|
||||
area.html(templates.parse(area.html(), {widgets: renderedWidgets}))
|
||||
.removeClass('hidden');
|
||||
|
||||
if (!renderedWidgets.length) {
|
||||
ajaxify.widgets.reposition();
|
||||
}
|
||||
}
|
||||
|
||||
$('#content [widget-area] img:not(.user-img)').addClass('img-responsive');
|
||||
checkCallback();
|
||||
});
|
||||
}
|
||||
|
||||
function checkCallback() {
|
||||
numLocations--;
|
||||
if (numLocations < 0 && callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
for (var i in widgetLocations) {
|
||||
if (widgetLocations.hasOwnProperty(i)) {
|
||||
renderWidgets(widgetLocations[i]);
|
||||
}
|
||||
}
|
||||
|
||||
checkCallback();
|
||||
};
|
||||
}(ajaxify || {}));
|
Loading…
Reference in New Issue