diff --git a/public/js/jquery/dashboard.js b/public/js/jquery/dashboard.js index 87f7490..1001d1a 100755 --- a/public/js/jquery/dashboard.js +++ b/public/js/jquery/dashboard.js @@ -7,41 +7,56 @@ var pluginName = 'dashboard'; $.fn[pluginName] = function (options) { + var args = arguments; this.each(function () { var _this = $.data(this, pluginName); - if (typeof options === 'string') { - _this[options].apply(_this, {}); - } - else { - return $.data(this, pluginName, new Dashboard(this, $.extend(true, {}, options))); + if (_this && typeof options === 'string') { + _this[options].apply(_this, Array.prototype.slice.call(args, 1)); + } + else if (_this && typeof options === 'object') { + _this['update'].apply(_this, [ options ]); + } + else if (!_this) { + return $.data(this, pluginName, new Dashboard(this, $.extend(true, {}, options))); } }); }; var Dashboard = function (el, options) { - - this.$element = $(el); + this.$element = $(document.createElement('div')).appendTo($(el)); this.options = options; this.render(); }; - Dashboard.prototype.update = function () { + Dashboard.prototype.update = function (options) { + if(options) { + this.options = options; + } this.options.factory.update(); this.render(); }; - + Dashboard.prototype.render = function () { var data = this.options.factory.data; - - var $wrapper = $('
'); - for (i = 0; i < data.length; i++) { - $wrapper - .append($('
') - .append('') - ); - } - this.$element.empty().append($wrapper); + + var $el = this.$element; + var dif = data.length - $el.children().length; + + // diff + if(dif < 0) { $el.children('.item:lt(' + (-1*dif) + ')').remove(); } + if(dif > 0) { for(var i=0;i'); - for (i = 0; i < data.length; i++) { - $wrapper.append('
'); - } - this.$element.empty().append($wrapper); + + var $el = this.$element; + var dif = data.length - $el.children().length; + + // diff + if(dif < 0) { $el.children('.item:lt(' + (-1*dif) + ')').remove(); } + if(dif > 0) { for(var i=0;i