2015-10-17 23:49:24 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-01-10 21:58:21 +01:00
|
|
|
var Backbone = require('backbone'),
|
|
|
|
Tip = require('../util/tip');
|
2015-10-17 23:49:24 +02:00
|
|
|
|
|
|
|
_.extend(Backbone.View.prototype, {
|
|
|
|
hide: function() {
|
|
|
|
return this.toggle(false);
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function() {
|
|
|
|
return this.toggle(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle: function(visible) {
|
2015-10-24 11:15:54 +02:00
|
|
|
if (visible === undefined) {
|
|
|
|
visible = this._hidden;
|
|
|
|
}
|
|
|
|
this.$el.toggleClass('show', !!visible);
|
2015-10-17 23:49:24 +02:00
|
|
|
this.$el.toggleClass('hide', !visible);
|
|
|
|
this._hidden = !visible;
|
|
|
|
this.trigger(visible ? 'show' : 'hide');
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2015-10-31 20:09:32 +01:00
|
|
|
isHidden: function() {
|
|
|
|
return this._hidden;
|
|
|
|
},
|
|
|
|
|
2015-10-17 23:49:24 +02:00
|
|
|
afterPaint: function(callback) {
|
|
|
|
this.requestAnimationFrame(function() {
|
|
|
|
this.requestAnimationFrame(callback);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-01-16 13:35:34 +01:00
|
|
|
setTimeout: function(callback) {
|
|
|
|
setTimeout(callback.bind(this), 0);
|
|
|
|
},
|
|
|
|
|
2015-10-17 23:49:24 +02:00
|
|
|
requestAnimationFrame: function(callback) {
|
|
|
|
requestAnimationFrame(callback.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
renderTemplate: function(model, replace) {
|
2016-02-07 10:16:24 +01:00
|
|
|
if (replace && replace.plain) {
|
|
|
|
this.$el.html(this.template(model));
|
2015-10-17 23:49:24 +02:00
|
|
|
} else {
|
2016-02-07 10:16:24 +01:00
|
|
|
if (replace) {
|
|
|
|
this.$el.html('');
|
|
|
|
}
|
|
|
|
var el = $(this.template(model));
|
|
|
|
if (!this._elAppended || replace) {
|
|
|
|
this.$el.append(el);
|
|
|
|
this._elAppended = true;
|
|
|
|
} else {
|
|
|
|
this.$el.replaceWith(el);
|
|
|
|
}
|
|
|
|
this.setElement(el);
|
2015-10-17 23:49:24 +02:00
|
|
|
}
|
2016-02-07 10:16:24 +01:00
|
|
|
Tip.createTips(this.$el);
|
2015-10-17 23:49:24 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
_parentRemove: Backbone.View.prototype.remove,
|
|
|
|
|
|
|
|
remove: function() {
|
|
|
|
this.trigger('remove');
|
|
|
|
if (this.views) {
|
|
|
|
_.each(this.views, function(view) {
|
|
|
|
if (view) {
|
|
|
|
if (view instanceof Backbone.View) {
|
|
|
|
view.remove();
|
|
|
|
} else if (view.length) {
|
|
|
|
view.forEach(function (v) {
|
|
|
|
v.remove();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (this.scroll) {
|
|
|
|
try { this.scroll.dispose(); }
|
|
|
|
catch (e) { }
|
|
|
|
}
|
|
|
|
this._parentRemove(arguments);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Backbone.View;
|