You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
2.4 KiB

var EXPO = EXPO || {}; //isolated namespace
EXPO.exposition = EXPO.exposition || {};
if (EXPO.exposition.object){
console.warn('WARNING: EXPO.exposition.object is already defined!');
}else {
EXPO.exposition.object = (function () {
// variables
var that = {},
VisitButtons = function ( opt) {
this.opt = opt;
this.isActive = false;
this.$visitorsList = $(document.getElementById(opt.visitorsListId));
this.$secondary = $(document.getElementById(opt.wrapId));
this._controller();
},
UnVisitButtons = function (opt) {
this.opt = opt;
this.$visitorsList = $(document.getElementById(opt.visitorsListId));
this.$secondary = $(document.getElementById(opt.wrapId));
this._controller();
};
VisitButtons.prototype = {
_controller: function () {
var self = this;
$('.'+this.opt.class).on('click',function(){
self._setName();
$('.'+self.opt.class).hide().siblings('.button').show();
});
},
_setName: function () {
$('<li/>').html(this.opt.template).prependTo(this.$visitorsList);
this.$secondary.hide();
isActive = true;
}
};
UnVisitButtons.prototype = {
_controller: function () {
var self = this;
$('.'+this.opt.class).on('click',function(){
self._unSetName();
$('.'+self.opt.class).hide().siblings('.button').show();
});
},
_unSetName: function () {
var self = this;
this.$visitorsList.children().each(function () {
if($(this).html() == self.opt.template){
$(this).detach();
}
});
if(!this.$visitorsList.children().length){
this.$secondary.show();
}else{
this.$secondary.hide();
}
isActive = true;
}
};
that.opt = {}; //свойства по умолчанию
//private
$(function () {
//$('.visit').on('click', function () {
// console.log('!!!! visit button is clicked!');
//});
});
// methods
//инициализация общих свойств
that.init = function (options) {
$.extend(this.opt, options);
var self = this,
$visitorsWrap = $(document.getElementById(self.opt.visitButton.visitorsListId)),
$secondaryList = $(document.getElementById(self.opt.visitButton.wrapId));
if(!$visitorsWrap.children().length){
$secondaryList.show();
}
this.visitButtons = new VisitButtons(self.opt.visitButton);
this.unVisitButtons = new UnVisitButtons(self.opt.unvisitButton);
};
return that;
}());
}