| |
| |
| |
| |
| |
| |
| |
| |
|
|
| (function ($, require) { |
|
|
| var exports = require('piwik/UI'); |
|
|
| var ARRAY_PARAM_NAMES = ['compareDates', 'comparePeriods', 'compareSegments']; |
|
|
| |
| |
| |
| |
| |
| |
| var UIControl = function (element) { |
| if (!element) { |
| throw new Error("no element passed to UIControl constructor"); |
| } |
|
|
| this._controlId = UIControl._nextControlId++; |
| UIControl._controls.push(this); |
|
|
| var $element = this.$element = $(element); |
| $element.data('uiControlObject', this); |
|
|
| var params = JSON.parse($element.attr('data-params') || '{}'); |
| for (var key in params) { |
| if (params[key] instanceof Array |
| && ARRAY_PARAM_NAMES.indexOf(key) === -1 |
| ) { |
| params[key] = params[key].join(','); |
| } |
| } |
| this.param = params; |
|
|
| this.props = JSON.parse($element.attr('data-props') || '{}'); |
| }; |
|
|
| |
| |
| |
| UIControl._controls = []; |
|
|
| |
| |
| |
| UIControl._nextControlId = 0; |
|
|
| |
| |
| |
| |
| |
| |
| |
| UIControl.cleanupUnusedControls = function () { |
| var controls = UIControl._controls; |
| |
| |
| var activeControls = UIControl._controls = []; |
|
|
| for (var i = 0; i != controls.length; ++i) { |
| var control = controls[i]; |
| if (control |
| && control.$element |
| && !$.contains(document.documentElement, control.$element[0]) |
| ) { |
| controls[i] = null; |
| control._destroy(); |
|
|
| if (!control._baseDestroyCalled) { |
| throw new Error("Error: " + control.constructor.name + "'s destroy method does not call " + |
| "UIControl.destroy. You may have a memory leak."); |
| } |
| } else { |
| |
| activeControls.push(control); |
| } |
| } |
| }; |
|
|
| UIControl.initElements = function (klass, selector) { |
| $(selector).each(function () { |
| if (!$(this).attr('data-inited')) { |
| var control = new klass(this); |
| $(this).attr('data-inited', 1); |
| } |
| }); |
| }; |
|
|
| UIControl.prototype = { |
|
|
| |
| |
| |
| |
| _destroy: function () { |
| this.$element.removeData('uiControlObject'); |
| delete this.$element; |
|
|
| this._baseDestroyCalled = true; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| onWidgetResize: function (handler) { |
| var $widget = this.$element.closest('.widgetContent'); |
| $widget.on('widget:maximise', handler) |
| .on('widget:minimise', handler) |
| .on('widget:resize', handler); |
| } |
| }; |
|
|
| exports.UIControl = UIControl; |
|
|
| })(jQuery, require); |
|
|