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.
 
 
 
 
 
 

204 lines
5.3 KiB

var EXPO = EXPO || {}; //isolated namespace
// module requires JQuery library, dna.js template engine (http://dnajs.org/)
// protection against duplication of a module code
if (EXPO.placePhoto){
console.warn('WARNING: EXPO.placePhoto is already defined!');
}else{
EXPO.placePhoto = (function() {
// variables
var that = {};
that.settings = {
}; //default module setting
that.lang ={};
//dependence's
//private
// constructor for popup window on gallery page
var ModalBox = function(modalId, containerId, modalTrigger, ajaxUrl, nextButtonId, prevButtonId, closeModalButtonId, modalContainerId){
// object properties
var self = this;
this.currentId = undefined;
this.ajaxUrl = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '') + ajaxUrl;
//modal Window options
this.opt = {
gContainerId:containerId,
mId:modalId,
mTrigger:modalTrigger,
nBtn: nextButtonId,
pBtn: prevButtonId,
cBtn: closeModalButtonId,
mcId: modalContainerId
};
this.$mWindow = undefined;
$(function () {
self.$mWindow = $('#'+self.opt.mId);
self.$mtrigger = $('.'+self.opt.mTrigger);
self.$nBtn = $('#'+self.opt.nBtn);
self.$pBtn = $('#'+self.opt.pBtn);
self.$cBtn = $('#'+self.opt.cBtn);
self.$mtrigger.on('click', function () {
var curId;
try {
curId = $(this).children('img').data('image-id');
self.currentId = curId;
}
catch(err) {
console.log(err.message);
}
self.show();
return false;
});
// next button
self.$nBtn.off('click');
self.$nBtn.on('click', function () {
self.nextSlide();
return false;
});
// previous button
self.$pBtn.off('click');
self.$pBtn.on('click', function () {
self.prevSlide();
return false;
});
//close modal window
self.$cBtn.off('click');
self.$cBtn.on('click', function () {
self.close();
return false;
});
self.$mWindow .off('click');
self.$mWindow .on('click', function (event) {
var targetObj = $(event.target);
if (targetObj.parents().filter('#'+self.opt.mcId).length < 1) {
self.close();
}
return false;
});
});
};
//methods for ModalBox object
ModalBox.prototype = {
//some kin
_getAjax: function (dataToSend, handler) {
var self = this;
if(!dataToSend){
dataToSend = '';
}
$.ajax({
type: 'GET',
url: self.ajaxUrl,
data:dataToSend,
success: function(data) {
if(typeof handler == 'function'){
self.rawData = data;
handler();
} else{
self.rawData = data;
}
}
});
},
// require dna.js template engine
_renderSlide: function (idToRender, handler) {
var self = this;
if(idToRender){
self.currentId = idToRender;
}
if(handler){
dna.empty(self.opt.mcId);
dna.load(self.opt.mcId, (self.ajaxUrl + self.currentId + '/'),{ callback:handler()});
}else{
dna.empty(self.opt.mcId);
dna.load(self.opt.mcId, (self.ajaxUrl + self.currentId + '/'),{empty:true});
}
},
_getId: function (parameter) {
var self = this,
nextSlide = function () {
var curId = $('.'+self.opt.mTrigger+' [data-image-id="'+self.currentId+'"]').parents('li').next().find('img').data('image-id');
if(curId){
self.currentId = curId;
}else{
console.log('there is not next slides');
}
},
prevSlide = function () {
var curId = $('.'+self.opt.mTrigger+' [data-image-id="'+self.currentId+'"]').parents('li').prev().find('img').data('image-id');
if(curId){
self.currentId = curId;
}else{
console.log('there is not previous slides');
}
},
defaultAction = function () {
console.log('_getId('+parameter+') RESULTS:');
console.log(self.currentId);
};
switch(parameter) {
case '>':
nextSlide();
break;
case '<':
prevSlide();
break;
default:
defaultAction();
}
},
//public methods
close: function () {
$('body').removeClass('no-scroll');
this.$mWindow.hide();
},
open: function () {
$('body').addClass('no-scroll');
this.$mWindow.show();
},
nextSlide:function () {
var pastSlide = this.currentId;
this._getId('>');
if(pastSlide != this.currentId){
this._renderSlide();
}
},
prevSlide: function () {
var pastSlide = this.currentId;
this._getId('<');
if(pastSlide != this.currentId){
this._renderSlide();
}
},
// method to get sliderPopup visible and pass to modalBox first initial id and make some init routine
show: function (idToShow) {
var self = this;
this._renderSlide(idToShow, function () {self.open()});
}
};
// methods
//инициализация общих свойств
that.init = function(options) {
// settings extending
$.extend(this.lang, options.lang);
options.lang = null;
$.extend(this.settings, options);
// begin of initialization
var self = this;
this.modal = new ModalBox(self.settings.modalId, self.settings.containerId, self.settings.modalTrigger, self.settings.ajaxUrl, self.settings.nextButtonId, self.settings.prevButtonId, self.settings.closeModalButtonId, self.settings.modalContainerId);
};
return that;
}());
}