ips.templates.set('gallery.notes.wrapper',"
");ips.templates.set('gallery.notes.delete'," ×");ips.templates.set('gallery.notes.edit'," ");; ;(function($,_,undefined){"use strict";ips.controller.register('gallery.front.view.notes',{_inAddingState:false,initialize:function(){this.on(document,'click','[data-action="addNote"]',this.startAddNote);this.setup();},setup:function(){var notes;try{notes=$.parseJSON(this.scope.attr('data-notesData'));}catch(err){} if(notes&¬es.length){this._buildNotes(notes);}},startAddNote:function(e){e.preventDefault();this.scope.append(ips.templates.render('gallery.notes.wrapper',{id:'new',left:50,top:50,width:(100 / this.scope.width())*100,height:(100 / this.scope.height())*100,editable:true}));$(document).trigger('contentChange',[this.scope]);},_buildNotes:function(notes){if(notes.length){for(var i=0;i div textarea').focus();return;} this._editing=true;this.scope.addClass('cGalleryNote_editing').append(ips.templates.render('gallery.notes.delete')).find('.cGalleryNote_note > div').html(ips.templates.render('gallery.notes.edit',{note:this._note})).find('textarea').focus();},_doDeleteNote:function(){var url=this._baseURL;var self=this;if(this.scope.attr('data-noteID')=='new'){ips.utils.anim.go('fadeOutDown',self.scope).done(function(){self.scope.remove();});return;} ips.getAjax()(url+'&delete=1&id='+this.scope.attr('data-noteID')).done(function(){ips.utils.anim.go('fadeOutDown',self.scope).done(function(){self.scope.remove();});})},_saveNote:function(noteContent,savePosition){var deferred=$.Deferred();var self=this;var url=this._baseURL;var position='';var note='';if(this.scope.attr('data-noteID')=='new'){url+='&add=1';}else{url+='&edit=1&id='+this.scope.attr('data-noteID');} if(savePosition){position=this._getPosition();} if(noteContent){note=noteContent;} if(this.scope.find('[data-action="save"]').length&¬e){this.scope.find('[data-action="save"]').prop('disabled',true).text(ips.getString('saving_note'));} ips.getAjax()(url,{data:{note:note,position:position}}).done(function(response){if(self.scope.find('[data-action="save"]').length&¬e){self.scope.find('[data-action="save"]').prop('disabled',false).text('Save');} if(_.isObject(response)&&response.id){self.scope.attr('data-noteID',response.id);} deferred.resolve();}).fail(function(){deferred.reject();});return deferred.promise();},_getPosition:function(){var position=[];var parent=this.scope.closest('.cGalleryViewImage');var notePos=this.scope.position();position[0]=(notePos['left']/ parent.width())*100;position[1]=(notePos['top']/ parent.height())*100;position[2]=(this.scope.width()/ parent.width())*100;position[3]=(this.scope.height()/ parent.height())*100;return position.join(',');},_stopEditing:function(){this._editing=false;this._draggingNotEditing=false;this.scope.removeClass('cGalleryNote_editing').find('.cGalleryNote_note > div').text(this._note).end().find('.cGalleryNote_delete').remove();},_buildNote:function(){this.scope.find('.cGalleryNote_note > div').text(this._note);},_setUpEditable:function(){if(!this._editable){return;} var self=this;ips.loader.get(['core/interface/jquery/jquery-ui.js']).then(function(){self.scope.resizable({containment:self.scope.closest('.cGalleryViewImage'),handles:'se',stop:self._updatePosition.bind(self)});self.scope.draggable({containment:self.scope.closest('.cGalleryViewImage'),start:self._startDragging.bind(self),stop:self._updatePosition.bind(self)});self.scope.find('.ui-resizable-handle').on('mouseover',function(){self.scope.closest('.cGalleryViewImage').css({height:self.scope.closest('.cGalleryViewImage').height()+'px'});});});},_startDragging:function(){if(!this._editing){this._draggingNotEditing=true;}},_updatePosition:function(){var self=this;var parent=this.scope.closest('.cGalleryViewImage');var notePos=this.scope.position();var posLeft=this.scope.find('.cGalleryNote_note').css('left');var posRight=this.scope.find('.cGalleryNote_note').css('right');if(parseInt(posLeft)>0){if(notePos['left']+parseInt(this.scope.width())+parseInt(this.scope.find('.cGalleryNote_note').width())>parent.width()){if(notePos['left']-parseInt(this.scope.find('.cGalleryNote_note').width())>0){this.scope.find('.cGalleryNote_note').css('left',posRight);this.scope.find('.cGalleryNote_note').css('right',posLeft);}}} else{if(notePos['left']-parseInt(this.scope.find('.cGalleryNote_note').width())<0){if(notePos['left']+parseInt(this.scope.width())+parseInt(this.scope.find('.cGalleryNote_note').width())viewportHeight+docScrollTop){this._scrolling=true;$('html, body').animate({scrollTop:elemPosition.absPos.top+'px'},function(){self._scrolling=false;});}},keyDown:function(e){if($(e.target).closest('input, textarea, .ipsComposeArea, .ipsComposeArea_editor').length){return;} switch(e.keyCode){case ips.ui.key.LEFT:this.scope.find('[data-action="prevImage"]').click();break;case ips.ui.key.RIGHT:this.scope.find('[data-action="nextImage"]').click();break;}},nextImage:function(e){e.preventDefault();var url=$(e.currentTarget).attr('href');var id=$(e.currentTarget).attr('data-imageID');var title=$(e.currentTarget).attr('title');History.pushState({controller:'gallery.front.view.image',imageID:id,realUrl:url,direction:'next',lightbox:this._inLightbox},title,ips.utils.url.removeParams(['lightbox','browse'],url));},prevImage:function(e){e.preventDefault();var url=$(e.currentTarget).attr('href');var id=$(e.currentTarget).attr('data-imageID');var title=$(e.currentTarget).attr('title');History.pushState({controller:'gallery.front.view.image',imageID:id,realUrl:url,direction:'prev',lightbox:this._inLightbox},title,ips.utils.url.removeParams(['lightbox','browse'],url));},setAsProfile:function(e){e.preventDefault();var url=$(e.currentTarget).attr('href');ips.ui.alert.show({type:'confirm',icon:'question',message:ips.getString('set_as_photo_confirm'),callbacks:{ok:function(){ips.getAjax()(url,{showLoading:true}).done(function(response){ips.ui.flashMsg.show(response.message);}).fail(function(){window.location=url;});}}});},setAsCover:function(e){e.preventDefault();var url=$(e.currentTarget).attr('href');ips.getAjax()(url,{showLoading:true}).done(function(response){ips.ui.flashMsg.show(response.message);}).fail(function(){window.location=url;});},rotateImage:function(e){e.preventDefault();var url=$(e.currentTarget).attr('href');var self=this;ips.getAjax()(url,{showLoading:true}).done(function(response){self.scope.find('[data-role="theImage"]')[0].src=response.src;self.scope.find('[data-role="theImage"]').css({'width':response.width+'px','height':response.height+'px'});self.scope.find('[data-role="theImage"]').closest('.cGalleryViewImage').css({'width':response.width+'px','height':response.height+'px'});ips.ui.flashMsg.show(response.message);}).fail(function(){window.location=url;});},windowResize:function(e){if($(window).width()!==this._windowDims.width||$(window).height()!==this._windowDims.height){this._setUpSizing(true);this._windowDims={width:$(window).width(),height:$(window).height()};}},_cachedUrls:{},_loadURL:function(url,cacheOnly,direction){var self=this;if(cacheOnly&&!_.isUndefined(this._cachedUrls[url])){return;} if(!cacheOnly){this.cleanContents();this._setImageLoading();var urlToRequest=url;} else{if(url.match(/\?/)){if(url.slice(-1)!='?'){var urlToRequest=url+'&preload=1';}}else{var urlToRequest=url+'?preload=1';}} if(_.isUndefined(cacheOnly)||!cacheOnly){if(this._ajaxObj&&_.isFunction(this._ajaxObj.abort)){this._ajaxObj.abort();}}else{if(this._preloadAjax[direction]&&_.isFunction(this._preloadAjax[direction].abort)){this._preloadAjax[direction].abort();}} if(self._cachedUrls[url]){self._updateImage(self._cachedUrls[url]);self._markImageRead(url);return;} var ajax=ips.getAjax();if(cacheOnly){this._preloadAjax[direction]=ajax;}else{this._ajaxObj=ajax;} ajax(urlToRequest,{dataType:'json'}).done(function(response){self._cachedUrls[url]=response;if(!cacheOnly){self._updateImage(response);}}).fail(function(jqXHR,textStatus,errorThrown){if(Debug.isEnabled()){Debug.error(errorThrown);}else{if(!cacheOnly){window.location=url;}}});},_markImageRead:function(url){var self=this;if(url.match(/\?/)){if(url.slice(-1)!='?'){url=url+'&do=markread';}}else{url=url+'?do=markread';} ips.getAjax()(url,{dataType:'json'}).done(function(response){Debug.log("Marked read");});},_updateImage:function(response){this.scope.find('[data-role="imageInfo"]').closest('.cGalleryLightbox_info').show().end().html(response.info);this.scope.find('[data-role="imageFrame"]').replaceWith(response.image);if(response.comments){this.scope.find('[data-role="imageComments"]').html(response.comments);}else{this.scope.find('[data-role="imageComments"]').html('');} $('nav.ipsBreadcrumb [data-role="breadcrumbList"] > li:last-child').html(response.title);$(document).trigger('contentChange',[this.scope]);$(document).trigger('imageUpdated',[{closeLightbox:(response.image.match(/