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.image',{initialize:function(){this.on('menuOpened',this.menuOpened);this.on('menuClosed',this.menuClosed);this.on(document,'keydown',this.keyDown);this.on('click','[data-action="setAsCover"]',this.setAsCover);this.on('click','[data-action="setAsProfile"]',this.setAsProfile);this.on('click','[data-action="rotateImage"]',this.rotateImage);},menuOpened:function(){this.scope.find('.elGalleryImage').addClass('cGalleryImageHover');},menuClosed:function(e){this.scope.find('.elGalleryImage').removeClass('cGalleryImageHover');},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="prevMedia"]')[0].click();break;case ips.ui.key.RIGHT:this.scope.find('[data-action="nextMedia"]')[0].click();break;}},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;});}});}(jQuery,_));; ;(function($,_,undefined){"use strict";ips.controller.register('gallery.front.view.note',{_editing:false,_editable:false,_draggingNotEditing:false,_hoverTimerOn:null,_hoverTimerOff:null,_note:'',initialize:function(){this.on('click','.cGalleryNote_border',this.startEditing);this.on('click','[data-action="save"]',this.saveNote);this.on('click','[data-action="cancel"]',this.cancelNote);this.on('click','[data-action="delete"]',this.deleteNote);this.on('mousedown','.cGalleryNote_note',this.mouseDown);this.on('mouseenter',this.mouseEnter);this.on('mouseleave',this.mouseLeave);this.setup();},setup:function(){var self=this;if(!_.isUndefined(this.scope.attr('data-editable'))&&!ips.utils.responsive.currentIs('phone')){this._editable=true;} this._note=this.scope.attr('data-note');this._baseURL=ips.getSetting('baseURL')+'index.php?app=gallery&module=gallery&controller=notes&imageId='+this.scope.closest('.cGalleryViewImage').attr('data-imageID');this._buildNote();this._setUpEditable();this._initialPosition();if(this.scope.attr('data-noteID')=='new'){this.scope.find('.cGalleryNote_border').click();}},saveNote:function(e){e.preventDefault();var self=this;var note=this.scope.find('.cGalleryNote_note textarea').val();var savePosition=false;this.scope.draggable('enable');if(!note.trim()){return;} if(this.scope.attr('data-noteID')=='new'){savePosition=true;} this._saveNote(note,savePosition).done(function(){self._note=note;self._stopEditing();});},cancelNote:function(e){if(this.scope.attr('data-noteID')=='new'){this.deleteNote(e);return;} e.preventDefault();this.scope.draggable('enable');this._stopEditing();},deleteNote:function(e){e.preventDefault();var self=this;ips.ui.alert.show({type:'confirm',icon:'question',message:ips.getString('delete_note_confirm'),callbacks:{ok:function(){self._doDeleteNote();}}});},mouseEnter:function(){var self=this;if(this._hoverTimerOn){clearTimeout(this._hoverTimerOn);} if(!this._editing){this._hoverTimerOn=setTimeout(function(){if(!self.scope.find('.cGalleryNote_note').is(':visible')){ips.utils.anim.go('fadeIn fast',self.scope.find('.cGalleryNote_note'));}});}},mouseLeave:function(){var self=this;if(this._hoverTimerOff){clearTimeout(this._hoverTimerOff);} if(!this._editing){this._hoverTimerOff=setTimeout(function(){if(self.scope.find('.cGalleryNote_note').is(':visible')){ips.utils.anim.go('fadeOut fast',self.scope.find('.cGalleryNote_note'));}});}},mouseDown:function(){},startEditing:function(){if(!this._editable||this._draggingNotEditing){return;} if(this._editing===true){this.scope.find('.cGalleryNote_note > 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)});});},_startDragging:function(){if(!this._editing){this._draggingNotEditing=true;}},_updatePosition:function(){var self=this;if(this.scope.attr('data-noteID')=='new'){return;} this._saveNote(false,true).done(function(){if(!self._editing){self._stopEditing();}});},_initialPosition:function(){var left=this.scope.attr('data-posLeft');var top=this.scope.attr('data-posTop');var width=this.scope.attr('data-dimWidth');var height=this.scope.attr('data-dimHeight');this.scope.css({left:left+'%',top:top+'%',width:width+'%',height:height+'%'});}});}(jQuery,_));; ;(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