Commit 6a281dd8 by lduarte1991

Annotation Tools: Spacing Issues fixed for catch.js

parent df8d51b9
...@@ -28,7 +28,7 @@ window.CatchSources = ("CatchSources" in window) ? CatchSources : {}; ...@@ -28,7 +28,7 @@ window.CatchSources = ("CatchSources" in window) ? CatchSources : {};
CatchSources.HTMLTEMPLATES = function(root){ CatchSources.HTMLTEMPLATES = function(root){
var root = root || ''; var root = root || '';
return { return {
//Main // Main
annotationList: annotationList:
'<div class="annotationListButtons">'+ '<div class="annotationListButtons">'+
'{{{ PublicPrivate }}}'+ '{{{ PublicPrivate }}}'+
...@@ -76,7 +76,7 @@ annotationList: ...@@ -76,7 +76,7 @@ annotationList:
'<div class="moreButtonCatch">'+gettext('More')+'</div>'+ '<div class="moreButtonCatch">'+gettext('More')+'</div>'+
'</div>', '</div>',
//Main->PublicPrivateInstructor // Main->PublicPrivateInstructor
annotationPublicPrivateInstructor: annotationPublicPrivateInstructor:
'<div class="selectors"><div class="PublicPrivate myNotes active">'+gettext('My Notes')+'<span class="action">myNotes</span></div>'+ '<div class="selectors"><div class="PublicPrivate myNotes active">'+gettext('My Notes')+'<span class="action">myNotes</span></div>'+
'<div class="PublicPrivate instructor"> '+gettext('Instructor')+'<span class="action">instructor</span></div>'+ '<div class="PublicPrivate instructor"> '+gettext('Instructor')+'<span class="action">instructor</span></div>'+
...@@ -87,7 +87,7 @@ annotationPublicPrivateInstructor: ...@@ -87,7 +87,7 @@ annotationPublicPrivateInstructor:
'<option>'+gettext('Annotation Text')+'</option>'+ '<option>'+gettext('Annotation Text')+'</option>'+
'</select><input type="text" name="search"/><div class="search-icon" alt="Run search."></div><div class="clear-search-icon" alt="Clear search.">'+gettext('Clear')+'</div></div>', '</select><input type="text" name="search"/><div class="search-icon" alt="Run search."></div><div class="clear-search-icon" alt="Clear search.">'+gettext('Clear')+'</div></div>',
//Main->PublicPrivate // Main->PublicPrivate
annotationPublicPrivate: annotationPublicPrivate:
'<div class="selectors"><div class="PublicPrivate myNotes active">'+gettext('My Notes')+'<span class="action">myNotes</span></div>'+ '<div class="selectors"><div class="PublicPrivate myNotes active">'+gettext('My Notes')+'<span class="action">myNotes</span></div>'+
'<div class="PublicPrivate public"> '+gettext('Public')+'<span class="action">public</span></div></div>'+ '<div class="PublicPrivate public"> '+gettext('Public')+'<span class="action">public</span></div></div>'+
...@@ -97,7 +97,7 @@ annotationPublicPrivate: ...@@ -97,7 +97,7 @@ annotationPublicPrivate:
'<option>'+gettext('Annotation Text')+'</option>'+ '<option>'+gettext('Annotation Text')+'</option>'+
'</select><input type="text" name="search"/><div class="search-icon" alt="Run search."></div><div class="clear-search-icon" alt="Clear search.">'+gettext('Clear')+'</div></div>', '</select><input type="text" name="search"/><div class="search-icon" alt="Run search."></div><div class="clear-search-icon" alt="Clear search.">'+gettext('Clear')+'</div></div>',
//Main->MediaSelector // Main->MediaSelector
annotationMediaSelector: annotationMediaSelector:
'<ul class="ui-tabs-nav">'+ '<ul class="ui-tabs-nav">'+
'<li class="ui-state-default" media="text">'+ '<li class="ui-state-default" media="text">'+
...@@ -111,16 +111,15 @@ annotationMediaSelector: ...@@ -111,16 +111,15 @@ annotationMediaSelector:
'</li>'+ '</li>'+
'</ul>', '</ul>',
//Main->ContainerRow // Main->ContainerRow
annotationItem: annotationItem:
'<div class="annotationItem {{ evenOrOdd }} {{ openOrClosed }}" annotationId="{{ id }}">'+ '<div class="annotationItem {{ evenOrOdd }} {{ openOrClosed }}" annotationId="{{ id }}">'+
'{{{ annotationRow }}}'+ '{{{ annotationRow }}}'+
'{{{ annotationDetail }}}'+ '{{{ annotationDetail }}}'+
'</div>', '</div>',
//Main->ContainerRow->Reply // Main->ContainerRow->Reply
annotationReply: annotationReply:
//<blockquote style="font-size:90%"><p><em>On Sep 14, 2013 4:35 PM <a href="#">jharvard</a>, wrote from [<a href="#">show map location</a>]:</em></p><p>{{{ an.text }}}</p></blockquote>
'{{#if annotations}}'+ '{{#if annotations}}'+
'{{#each annotations}}'+ '{{#each annotations}}'+
'<blockquote class="replyItem" annotationId="{{this.id}}" style="font-size:90%">'+ '<blockquote class="replyItem" annotationId="{{this.id}}" style="font-size:90%">'+
...@@ -150,7 +149,7 @@ annotationReply: ...@@ -150,7 +149,7 @@ annotationReply:
'{{/each}}'+ '{{/each}}'+
'{{/if}}', '{{/if}}',
//Main->ContainerRow->Row // Main->ContainerRow->Row
annotationRow: annotationRow:
'<div class="annotationRow item">'+ '<div class="annotationRow item">'+
'<div class="expandableIcon field">'+ '<div class="expandableIcon field">'+
...@@ -187,7 +186,7 @@ annotationRow: ...@@ -187,7 +186,7 @@ annotationRow:
'</div>'+ '</div>'+
'</div>', '</div>',
//Main->ContainerRow->DetailRow // Main->ContainerRow->DetailRow
annotationDetail: annotationDetail:
'{{#if mediatypeforgrid.text}}'+ '{{#if mediatypeforgrid.text}}'+
'<div class="annotationDetail">'+ '<div class="annotationDetail">'+
...@@ -277,32 +276,32 @@ annotationDetail: ...@@ -277,32 +276,32 @@ annotationDetail:
CatchAnnotation = function (element, options) { CatchAnnotation = function (element, options) {
//local variables // local variables
var $ = jQuery, var $ = jQuery,
options = options || {}; options = options || {};
//Options // Options
var defaultOptions = { var defaultOptions = {
media: 'text', media: 'text',
userId: '', //this is an integer and its value is the userId to see user annotations userId: '', // this is an integer and its value is the userId to see user annotations
externalLink: false,//This is true if you want to open the link in a new URL. However, it is false if you want to open the url in the same page externalLink: false,//This is true if you want to open the link in a new URL. However, it is false if you want to open the url in the same page
showMediaSelector: true, //whether show the selector of Media Annotations or not showMediaSelector: true, // whether show the selector of Media Annotations or not
showPublicPrivate: true, //Whether show Public or Private Annotation Selector showPublicPrivate: true, // Whether show Public or Private Annotation Selector
pagination: 50, //Number of Annotations per load in the pagination pagination: 50, // Number of Annotations per load in the pagination
flags:false //This checks to see if user is staff and has access to see flags flags:false // This checks to see if user is staff and has access to see flags
}; };
this.options = $.extend( true, defaultOptions, options ); this.options = $.extend( true, defaultOptions, options );
//element // element
this.element = element; this.element = element;
//clean boolean // clean boolean
this.clean = false; this.clean = false;
//Reset element an create a new element div // Reset element an create a new element div
element.html('<div id="mainCatch" class="annotationListContainer"></div>'); element.html('<div id="mainCatch" class="annotationListContainer"></div>');
this.current_tab = this.options.default_tab; this.current_tab = this.options.default_tab;
//INIT // INIT
var self = this; var self = this;
$( document ).ready(function() { $( document ).ready(function() {
self.init(); self.init();
...@@ -316,46 +315,46 @@ CatchAnnotation = function (element, options) { ...@@ -316,46 +315,46 @@ CatchAnnotation = function (element, options) {
CatchAnnotation.prototype = { CatchAnnotation.prototype = {
init: function(){ init: function(){
//Set variables // Set variables
//Initial Templates // Initial Templates
this.TEMPLATENAMES = [ this.TEMPLATENAMES = [
"annotationList", //Main "annotationList", // Main
"annotationPublicPrivate", //Main->PublicPrivate "annotationPublicPrivate", // Main->PublicPrivate
"annotationPublicPrivateInstructor", //Main->PublicPrivateInstructor "annotationPublicPrivateInstructor", // Main->PublicPrivateInstructor
"annotationMediaSelector", //Main->MediaSelector "annotationMediaSelector", // Main->MediaSelector
"annotationItem", //Main->ContainerRow "annotationItem", // Main->ContainerRow
"annotationReply",//Main->ContainerRow->Reply "annotationReply", // Main->ContainerRow->Reply
"annotationRow", //Main->ContainerRow->Row "annotationRow", // Main->ContainerRow->Row
"annotationDetail",//Main->ContainerRow->DetailRow "annotationDetail", // Main->ContainerRow->DetailRow
]; ];
//annotator // annotator
var wrapper = $('.annotator-wrapper').parent()[0]; var wrapper = $('.annotator-wrapper').parent()[0];
var annotator = $.data(wrapper, 'annotator'); var annotator = $.data(wrapper, 'annotator');
this.annotator = annotator; this.annotator = annotator;
//Subscribe to annotator // Subscribe to annotator
this._subscribeAnnotator(); this._subscribeAnnotator();
// //
// Handlebars Register Library // Handlebars Register Library
// //
Handlebars.registerHelper('deparagraph', function(txt) { Handlebars.registerHelper('deparagraph', function(txt) {
var dpg = txt.replace("<p>", "").replace("</p>", ""); var dpg = txt.replace("<p>", "").replace("</p>", "");
return dpg; return dpg;
}); });
//Compile templates // Compile templates
this.HTMLTEMPLATES = CatchSources.HTMLTEMPLATES(this.options.imageUrlRoot); this.HTMLTEMPLATES = CatchSources.HTMLTEMPLATES(this.options.imageUrlRoot);
this.TEMPLATES = {}; this.TEMPLATES = {};
this._compileTemplates(); this._compileTemplates();
// the default annotations are the user's personal ones instead of instructor // the default annotations are the user's personal ones instead of instructor.
// if the default tab is instructor, we must refresh the catch to pull the ones // if the default tab is instructor, we must refresh the catch to pull the ones
// under the instructor's email. passing empty strings as arguments will default // under the instructor's email. Calling changeUserId will update this.options.userId
// to pulling the annotations for the email within this.options.userId. // and most importantly refresh not only the highlights (from Annotator)
// but also the table below from the annotations database server (called Catch).
if(this.options.default_tab.toLowerCase() == 'instructor'){ if(this.options.default_tab.toLowerCase() == 'instructor'){
this.options.userId = this.options.instructor_email; this.changeUserId(this.options.instructor_email);
this.changeUserId(this.options.userId);
} }
}, },
// //
...@@ -365,26 +364,26 @@ CatchAnnotation.prototype = { ...@@ -365,26 +364,26 @@ CatchAnnotation.prototype = {
return this.TEMPLATES[templateName]() || ''; return this.TEMPLATES[templateName]() || '';
}, },
refreshCatch: function(newInstance) { refreshCatch: function(newInstance) {
var mediaType = this.options.media || 'text', var mediaType = this.options.media || 'text';
annotationItems = [], var annotationItems = [];
index = 0, var index = 0;
annotations = this.annotator.plugins['Store'].annotations || [], var annotations = this.annotator.plugins['Store'].annotations || [];
el = $("#mainCatch.annotationListContainer"), var el = $("#mainCatch.annotationListContainer");
self = this, var self = this;
newInstance = newInstance || false; var newInstance = newInstance || false;
annotations.forEach(function(annotation) { annotations.forEach(function(annotation) {
var isMedia = annotation.media==self.options.media, var isMedia = annotation.media==self.options.media;
isUser = (typeof self.options.userId!='undefined' && self.options.userId!='' && self.options.userId!=null)? var isUser = (typeof self.options.userId!='undefined' && self.options.userId!='' && self.options.userId!=null)?
self.options.userId == annotation.user.id:true, self.options.userId == annotation.user.id:true;
isInList = newInstance?false:self._isInList(annotation); var isInList = newInstance?false:self._isInList(annotation);
if (isMedia && isUser && !isInList){ if (isMedia && isUser && !isInList){
var item = jQuery.extend(true, {}, annotation); var item = jQuery.extend(true, {}, annotation);
self._formatCatch(item); self._formatCatch(item);
//Authorized // Authorized
var permissions = self.annotator.plugins.Permissions, var permissions = self.annotator.plugins.Permissions;
authorized = permissions.options.userAuthorize('delete', annotation,permissions.user), var authorized = permissions.options.userAuthorize('delete', annotation,permissions.user);
updateAuthorized = permissions.options.userAuthorize('update', annotation,permissions.user); var updateAuthorized = permissions.options.userAuthorize('update', annotation,permissions.user);
item.authToDeleteButton = authorized; item.authToDeleteButton = authorized;
item.authToEditButton = updateAuthorized; item.authToEditButton = updateAuthorized;
...@@ -423,14 +422,14 @@ CatchAnnotation.prototype = { ...@@ -423,14 +422,14 @@ CatchAnnotation.prototype = {
}); });
} }
//Set SelButtons to media // Set SelButtons to media
var SelButtons = el.find('.annotationList li').removeClass('active'); //reset var SelButtons = el.find('.annotationList li').removeClass('active'); // reset
for (var index=0;index<SelButtons.length;index++) { for (var index=0;index<SelButtons.length;index++) {
var span = $(SelButtons[index]); var span = $(SelButtons[index]);
if (span.attr("media")==this.options.media) $(SelButtons[index]).addClass('active'); if (span.attr("media")==this.options.media) $(SelButtons[index]).addClass('active');
} }
//Set PublicPrivate // Set PublicPrivate
var PublicPrivateButtons = el.find('.annotationListButtons .PublicPrivate').removeClass('active'); //reset var PublicPrivateButtons = el.find('.annotationListButtons .PublicPrivate').removeClass('active'); // reset
for (var index=0;index<PublicPrivateButtons.length;index++) { for (var index=0;index<PublicPrivateButtons.length;index++) {
var span = $(PublicPrivateButtons[index]).find('span'); var span = $(PublicPrivateButtons[index]).find('span');
if (span.html().toLowerCase()==self.current_tab.toLowerCase()) { if (span.html().toLowerCase()==self.current_tab.toLowerCase()) {
...@@ -449,67 +448,67 @@ CatchAnnotation.prototype = { ...@@ -449,67 +448,67 @@ CatchAnnotation.prototype = {
} }
} }
//reset all old events // reset all old events
el.off(); el.off();
//Bind functions // Bind functions
var openAnnotationItem = this.__bind(this._openAnnotationItem, this), var openAnnotationItem = this.__bind(this._openAnnotationItem, this);
closeAnnotationItem = this.__bind(this._closeAnnotationItem, this), var closeAnnotationItem = this.__bind(this._closeAnnotationItem, this);
onGeolocationClick = this.__bind(this._onGeolocationClick, this), var onGeolocationClick = this.__bind(this._onGeolocationClick, this);
onPlaySelectionClick = this.__bind(this._onPlaySelectionClick, this), var onPlaySelectionClick = this.__bind(this._onPlaySelectionClick, this);
onShareControlsClick = this.__bind(this._onShareControlsClick, this), var onShareControlsClick = this.__bind(this._onShareControlsClick, this);
onSelectionButtonClick = this.__bind(this._onSelectionButtonClick, this), var onSelectionButtonClick = this.__bind(this._onSelectionButtonClick, this);
onPublicPrivateButtonClick = this.__bind(this._onPublicPrivateButtonClick, this), var onPublicPrivateButtonClick = this.__bind(this._onPublicPrivateButtonClick, this);
onQuoteMediaButton = this.__bind(this._onQuoteMediaButton, this), var onQuoteMediaButton = this.__bind(this._onQuoteMediaButton, this);
onControlRepliesClick = this.__bind(this._onControlRepliesClick, this), var onControlRepliesClick = this.__bind(this._onControlRepliesClick, this);
onMoreButtonClick = this.__bind(this._onMoreButtonClick, this), var onMoreButtonClick = this.__bind(this._onMoreButtonClick, this);
onSearchButtonClick = this.__bind(this._onSearchButtonClick, this), var onSearchButtonClick = this.__bind(this._onSearchButtonClick, this);
onClearSearchButtonClick = this.__bind(this._onClearSearchButtonClick, this), var onClearSearchButtonClick = this.__bind(this._onClearSearchButtonClick, this);
onDeleteReplyButtonClick = this.__bind(this._onDeleteReplyButtonClick, this), var onDeleteReplyButtonClick = this.__bind(this._onDeleteReplyButtonClick, this);
onZoomToImageBoundsButtonClick = this.__bind(this._onZoomToImageBoundsButtonClick, this); var onZoomToImageBoundsButtonClick = this.__bind(this._onZoomToImageBoundsButtonClick, this);
//Open Button // Open Button
el.on("click", ".annotationItem .annotationRow", openAnnotationItem); el.on("click", ".annotationItem .annotationRow", openAnnotationItem);
//Close Button // Close Button
el.on("click", ".annotationItem .detailHeader", closeAnnotationItem); el.on("click", ".annotationItem .detailHeader", closeAnnotationItem);
//Geolocation button // Geolocation button
el.on("click",".annotationItem .detailHeader .geolocationIcon img", onGeolocationClick); el.on("click",".annotationItem .detailHeader .geolocationIcon img", onGeolocationClick);
//controlPanel buttons // controlPanel buttons
el.on("click",".annotationItem .annotationDetail .controlPanel", onShareControlsClick); el.on("click",".annotationItem .annotationDetail .controlPanel", onShareControlsClick);
//VIDEO // VIDEO
if (this.options.media=='video') { if (this.options.media=='video') {
//PlaySelection button // PlaySelection button
el.on("click",".annotationItem .annotationDetail .playMediaButton", onPlaySelectionClick); el.on("click",".annotationItem .annotationDetail .playMediaButton", onPlaySelectionClick);
} }
//TEXT // TEXT
if (this.options.media=='text') { if (this.options.media=='text') {
//PlaySelection button // PlaySelection button
el.on("click",".annotationItem .annotationDetail .quote", onQuoteMediaButton); el.on("click",".annotationItem .annotationDetail .quote", onQuoteMediaButton);
} }
//IMAGE // IMAGE
if (this.options.media=='image') { if (this.options.media=='image') {
//PlaySelection button // PlaySelection button
el.on("click",".annotationItem .annotationDetail .zoomToImageBounds", onZoomToImageBoundsButtonClick); el.on("click",".annotationItem .annotationDetail .zoomToImageBounds", onZoomToImageBoundsButtonClick);
} }
//controlReplies // controlReplies
el.on("click",".annotationItem .controlReplies", onControlRepliesClick); el.on("click",".annotationItem .controlReplies", onControlRepliesClick);
//Selection Buttons // Selection Buttons
el.on("click",".annotationList li", onSelectionButtonClick); el.on("click",".annotationList li", onSelectionButtonClick);
//PublicPrivate Buttons // PublicPrivate Buttons
el.on("click",".annotationListButtons .PublicPrivate", onPublicPrivateButtonClick); el.on("click",".annotationListButtons .PublicPrivate", onPublicPrivateButtonClick);
//More Button // More Button
el.on("click",".annotationListButtons .moreButtonCatch", onMoreButtonClick); el.on("click",".annotationListButtons .moreButtonCatch", onMoreButtonClick);
//Search Button // Search Button
el.on("click",".searchbox .search-icon", onSearchButtonClick); el.on("click",".searchbox .search-icon", onSearchButtonClick);
//Clear Search Button // Clear Search Button
el.on("click",".searchbox .clear-search-icon", onClearSearchButtonClick); el.on("click",".searchbox .clear-search-icon", onClearSearchButtonClick);
//Delete Reply Button // Delete Reply Button
el.on("click", ".replies .replyItem .deleteReply", onDeleteReplyButtonClick); el.on("click", ".replies .replyItem .deleteReply", onDeleteReplyButtonClick);
}, },
...@@ -535,27 +534,27 @@ CatchAnnotation.prototype = { ...@@ -535,27 +534,27 @@ CatchAnnotation.prototype = {
* Since it's a vendor file, this is the workaround for that bug. * Since it's a vendor file, this is the workaround for that bug.
*/ */
cleanUpAnnotations: function(){ cleanUpAnnotations: function(){
var annotator = this.annotator, var annotator = this.annotator;
store = annotator.plugins.Store, var store = annotator.plugins.Store;
annotations = store.annotations, var annotations = store.annotations;
self = this; var self = this;
//goes through all the annotations currently loaded // goes through all the annotations currently loaded
$.each(annotations, function(key, value){ $.each(annotations, function(key, value){
//if the options.userID (i.e. the value we are searching for) is empty signifying // if the options.userID (i.e. the value we are searching for) is empty signifying
//public or is equal to the person with update access, then we leave it alone, // public or is equal to the person with update access, then we leave it alone,
//otherwise we need to clean them up (i.e. disable them). // otherwise we need to clean them up (i.e. disable them).
if(self.options.userId !== '' && self.options.userId !== value.permissions.update[0]){ if(self.options.userId !== '' && self.options.userId !== value.permissions.update[0]){
$.each(value.highlights, function(key1, value1){ $.each(value.highlights, function(key1, value1){
$(value1).removeClass('annotator-hl'); $(value1).removeClass('annotator-hl');
}); });
} }
}); });
}, },
loadAnnotations: function() { loadAnnotations: function() {
var annotator = this.annotator, var annotator = this.annotator;
loadFromSearch = annotator.plugins.Store.options.loadFromSearch, var loadFromSearch = annotator.plugins.Store.options.loadFromSearch;
loadedAn = this.element.find('.annotationList .annotationItem').length; var loadedAn = this.element.find('.annotationList .annotationItem').length;
loadedAn = typeof loadedAn!='undefined' ?loadedAn:0; loadedAn = typeof loadedAn!='undefined' ?loadedAn:0;
loadFromSearch.limit = this.options.pagination; loadFromSearch.limit = this.options.pagination;
...@@ -565,42 +564,42 @@ CatchAnnotation.prototype = { ...@@ -565,42 +564,42 @@ CatchAnnotation.prototype = {
// Dani had this for some reason. we can't remember. but if something // Dani had this for some reason. we can't remember. but if something
// breaks, uncomment next line. // breaks, uncomment next line.
//annotator.plugins['Store'].loadAnnotationsFromSearch(loadFromSearch); // annotator.plugins['Store'].loadAnnotationsFromSearch(loadFromSearch);
//Make sure to be openned all annotations for this pagination // Make sure to be openned all annotations for this pagination
loadFromSearch.limit = this.options.pagination+loadedAn; loadFromSearch.limit = this.options.pagination+loadedAn;
loadFromSearch.offset = 0; loadFromSearch.offset = 0;
annotator.plugins['Store'].loadAnnotationsFromSearch(loadFromSearch); annotator.plugins['Store'].loadAnnotationsFromSearch(loadFromSearch);
//text loading annotations // text loading annotations
var moreBut = this.element.find('.annotationListButtons .moreButtonCatch'); var moreBut = this.element.find('.annotationListButtons .moreButtonCatch');
moreBut.html('Please wait, loading...'); moreBut.html('Please wait, loading...');
}, },
//check whether is necessary more button or not // check whether is necessary to have a more button or not
checkTotAnnotations: function(){ checkTotAnnotations: function(){
var annotator = this.annotator, var annotator = this.annotator;
loadFromSearch = annotator.plugins.Store.options.loadFromSearch, var loadFromSearch = annotator.plugins.Store.options.loadFromSearch;
oldLimit = loadFromSearch.limit, var oldLimit = loadFromSearch.limit;
oldOffset = loadFromSearch.offset, var oldOffset = loadFromSearch.offset;
self = this; var self = this;
loadFromSearch.limit = 0; loadFromSearch.limit = 0;
loadFromSearch.offset = 0; loadFromSearch.offset = 0;
loadFromSearch.media = this.options.media; loadFromSearch.media = this.options.media;
loadFromSearch.userid = this.options.userId; loadFromSearch.userid = this.options.userId;
var onSuccess = function(response){ var onSuccess = function(response){
var totAn = self.element.find('.annotationList .annotationItem').length, var totAn = self.element.find('.annotationList .annotationItem').length;
maxAn = response.total, var maxAn = response.total;
moreBut = self.element.find('.annotationListButtons .moreButtonCatch'); var moreBut = self.element.find('.annotationListButtons .moreButtonCatch');
if (totAn<maxAn && totAn > 0) if (totAn<maxAn && totAn > 0)
moreBut.show(); moreBut.show();
else else
moreBut.hide(); moreBut.hide();
} }
var obj = loadFromSearch, var obj = loadFromSearch;
action = 'search'; var action = 'search';
var id, options, url; var id, options, url;
id = obj && obj.id; id = obj && obj.id;
...@@ -608,11 +607,11 @@ CatchAnnotation.prototype = { ...@@ -608,11 +607,11 @@ CatchAnnotation.prototype = {
options = annotator.plugins['Store']._apiRequestOptions(action, obj, onSuccess); options = annotator.plugins['Store']._apiRequestOptions(action, obj, onSuccess);
$.ajax(url, options); $.ajax(url, options);
//reset values // reset values
loadFromSearch.limit = oldLimit; loadFromSearch.limit = oldLimit;
loadFromSearch.offset = oldOffset; loadFromSearch.offset = oldOffset;
//set More button text // set More button text
var moreBut = this.element.find('.annotationListButtons .moreButtonCatch'); var moreBut = this.element.find('.annotationListButtons .moreButtonCatch');
moreBut.html('More'); moreBut.html('More');
...@@ -622,13 +621,13 @@ CatchAnnotation.prototype = { ...@@ -622,13 +621,13 @@ CatchAnnotation.prototype = {
// LOCAL UTILITIES // LOCAL UTILITIES
// //
_subscribeAnnotator: function(){ _subscribeAnnotator: function(){
var self = this, var self = this;
annotator = this.annotator; var annotator = this.annotator;
//Subscribe to Annotator changes // Subscribe to Annotator changes
annotator.subscribe("annotationsLoaded", function (annotations){ annotator.subscribe("annotationsLoaded", function (annotations){
self.cleanUpAnnotations(); self.cleanUpAnnotations();
self.refreshCatch(self.clean); self.refreshCatch(self.clean);
//hide or show more button // hide or show more button
self.checkTotAnnotations(); self.checkTotAnnotations();
}); });
annotator.subscribe("annotationUpdated", function (annotation){ annotator.subscribe("annotationUpdated", function (annotation){
...@@ -636,14 +635,14 @@ CatchAnnotation.prototype = { ...@@ -636,14 +635,14 @@ CatchAnnotation.prototype = {
self.checkTotAnnotations(); self.checkTotAnnotations();
}); });
annotator.subscribe("annotationDeleted", function (annotation){ annotator.subscribe("annotationDeleted", function (annotation){
var annotations = annotator.plugins['Store'].annotations, var annotations = annotator.plugins['Store'].annotations;
tot = typeof annotations !='undefined'?annotations.length:0, var tot = typeof annotations !='undefined'?annotations.length:0;
attempts = 0; // max 100 var attempts = 0; // max 100
if(annotation.media == "image"){ if(annotation.media == "image"){
self.refreshCatch(true); self.refreshCatch(true);
self.checkTotAnnotations(); self.checkTotAnnotations();
} else { } else {
//This is to watch the annotations object, to see when is deleted the annotation // This is to watch the annotations object, to see when is deleted the annotation
var ischanged = function(){ var ischanged = function(){
var new_tot = annotator.plugins['Store'].annotations.length; var new_tot = annotator.plugins['Store'].annotations.length;
if (attempts<100) if (attempts<100)
...@@ -655,34 +654,34 @@ CatchAnnotation.prototype = { ...@@ -655,34 +654,34 @@ CatchAnnotation.prototype = {
attempts++; attempts++;
ischanged(); ischanged();
} }
},100); //wait for the change in the annotations },100); // wait for the change in the annotations
}; };
ischanged(); ischanged();
} }
}); });
annotator.subscribe("annotationCreated", function (annotation){ annotator.subscribe("annotationCreated", function (annotation){
var attempts = 0; // max 100 var attempts = 0; // max 100
//There is a delay between calls to the backend--especially reading after // There is a delay between calls to the backend--especially reading after
//writing. This function listens to when a function is created and waits // writing. This function listens to when a function is created and waits
//until the server provides it with an annotation id before doing anything // until the server provides it with an annotation id before doing anything
//with it. // with it.
var ischanged = function(){ var ischanged = function(){
if (attempts<100) if (attempts<100)
setTimeout(function(){ setTimeout(function(){
if (typeof annotation.id!='undefined'){ if (typeof annotation.id!='undefined'){
//once it gets the annotation id, the table refreshes to show // once it gets the annotation id, the table refreshes to show
//the edits // the edits
self.refreshCatch(); self.refreshCatch();
if (typeof annotation.parent != 'undefined' && annotation.parent != '0'){ if (typeof annotation.parent != 'undefined' && annotation.parent != '0'){
//if annotation made was actually a replay to an annotation // if annotation made was actually a replay to an annotation
//i.e. the only difference is that annotations that are // i.e. the only difference is that annotations that are
//not replies have no "parent" // not replies have no "parent"
var replies = $("[annotationid="+annotation.parent+"]").find(".controlReplies .hideReplies"); var replies = $("[annotationid="+annotation.parent+"]").find(".controlReplies .hideReplies");
//forces "Show replies" section to show and then refreshes // forces "Show replies" section to show and then refreshes
//via two clicks // via two clicks
replies.show(); replies.show();
replies.click(); replies.click();
replies.click(); replies.click();
...@@ -691,7 +690,7 @@ CatchAnnotation.prototype = { ...@@ -691,7 +690,7 @@ CatchAnnotation.prototype = {
attempts++; attempts++;
ischanged(); ischanged();
} }
},100); //wait for annotation id },100); // wait for annotation id
}; };
ischanged(); ischanged();
}); });
...@@ -699,23 +698,23 @@ CatchAnnotation.prototype = { ...@@ -699,23 +698,23 @@ CatchAnnotation.prototype = {
__bind: function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __bind: function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
_compileTemplates: function() { _compileTemplates: function() {
var self = this; var self = this;
//Change the html tags to functions // Change the html tags to functions
this.TEMPLATENAMES.forEach(function(templateName) { this.TEMPLATENAMES.forEach(function(templateName) {
self.TEMPLATES[templateName] = Handlebars.compile(self.HTMLTEMPLATES[templateName]); self.TEMPLATES[templateName] = Handlebars.compile(self.HTMLTEMPLATES[templateName]);
}); });
}, },
_isVideoJS: function (an){ _isVideoJS: function (an){
var annotator = this.annotator, var annotator = this.annotator;
rt = an.rangeTime, var rt = an.rangeTime;
isOpenVideojs = (typeof annotator.mplayer != 'undefined'), var isOpenVideojs = (typeof annotator.mplayer != 'undefined');
isVideo = (typeof an.media!='undefined' && an.media=='video'), var isVideo = (typeof an.media!='undefined' && an.media=='video');
isNumber = (typeof rt!='undefined' && !isNaN(parseFloat(rt.start)) && isFinite(rt.start) && !isNaN(parseFloat(rt.end)) && isFinite(rt.end)); var isNumber = (typeof rt!='undefined' && !isNaN(parseFloat(rt.start)) && isFinite(rt.start) && !isNaN(parseFloat(rt.end)) && isFinite(rt.end));
return (isOpenVideojs && isVideo && isNumber); return (isOpenVideojs && isVideo && isNumber);
}, },
_isInList: function (an){ _isInList: function (an){
var annotator = this.annotator, var annotator = this.annotator;
isInList = false, var isInList = false;
list = $('#mainCatch .annotationList .annotationRow.item'); var list = $('#mainCatch .annotationList .annotationRow.item');
for (_i = 0, _len = list.length; _i < _len; _i++) { for (_i = 0, _len = list.length; _i < _len; _i++) {
if ($(list[_i]).parent().attr('annotationid') == an.id) if ($(list[_i]).parent().attr('annotationid') == an.id)
isInList = true; isInList = true;
...@@ -726,23 +725,23 @@ CatchAnnotation.prototype = { ...@@ -726,23 +725,23 @@ CatchAnnotation.prototype = {
var item = item || {}; var item = item || {};
if(this._isVideoJS(item)){ if(this._isVideoJS(item)){
//format time // format time
item.rangeTime.start= typeof vjs!='undefined'?vjs.formatTime(item.rangeTime.start):item.rangeTime.start; item.rangeTime.start= typeof vjs!='undefined'?vjs.formatTime(item.rangeTime.start):item.rangeTime.start;
item.rangeTime.end= typeof vjs!='undefined'?vjs.formatTime(item.rangeTime.end):item.rangeTime.end; item.rangeTime.end= typeof vjs!='undefined'?vjs.formatTime(item.rangeTime.end):item.rangeTime.end;
} }
//format date // format date
if(typeof item.updated!='undefined' && typeof createDateFromISO8601!='undefined') if(typeof item.updated!='undefined' && typeof createDateFromISO8601!='undefined')
item.updated = createDateFromISO8601(item.updated); item.updated = createDateFromISO8601(item.updated);
//format geolocation // format geolocation
if(typeof item.geolocation!='undefined' && (typeof item.geolocation.latitude=='undefined'||item.geolocation.latitude=='')) if(typeof item.geolocation!='undefined' && (typeof item.geolocation.latitude=='undefined'||item.geolocation.latitude==''))
delete item.geolocation; delete item.geolocation;
/* NEW VARIABLES */ /* NEW VARIABLES */
//set plainText for Catch // set plainText for Catch
item.plainText = item.text.replace(/&(lt|gt);/g, function (strMatch, p1){ item.plainText = item.text.replace(/&(lt|gt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">"; return (p1 == "lt")? "<" : ">";
});//Change to < and > tags });//Change to < and > tags
item.plainText = item.plainText.replace(/<\/?[^>]+(>|$)/g, "").replace('&nbsp;',''); //remove all the html tags item.plainText = item.plainText.replace(/<\/?[^>]+(>|$)/g, "").replace('&nbsp;',''); // remove all the html tags
item.mediatypeforgrid = {}; item.mediatypeforgrid = {};
item.mediatypeforgrid[item.media] = true; item.mediatypeforgrid[item.media] = true;
...@@ -751,7 +750,7 @@ CatchAnnotation.prototype = { ...@@ -751,7 +750,7 @@ CatchAnnotation.prototype = {
item.thumbnailLink = item.target.thumb; item.thumbnailLink = item.target.thumb;
}; };
//Flags // Flags
if(!this.options.flags && typeof item.tags != 'undefined' && item.tags.length > 0){ if(!this.options.flags && typeof item.tags != 'undefined' && item.tags.length > 0){
for(var len=item.tags.length, index = len-1; index >= 0; --index){ for(var len=item.tags.length, index = len-1; index >= 0; --index){
var currTag = item.tags[index]; var currTag = item.tags[index];
...@@ -770,15 +769,15 @@ CatchAnnotation.prototype = { ...@@ -770,15 +769,15 @@ CatchAnnotation.prototype = {
var isClosed = $(evt.currentTarget).closest(".annotationItem").hasClass("closed"); var isClosed = $(evt.currentTarget).closest(".annotationItem").hasClass("closed");
if (isClosed) { if (isClosed) {
$(evt.currentTarget).closest(".annotationItem").removeClass("closed").addClass("open"); $(evt.currentTarget).closest(".annotationItem").removeClass("closed").addClass("open");
//Add Share button // Add Share button
var shareControl = $(evt.currentTarget).closest(".annotationItem").find('.annotationDetail .controlPanel:first'), var shareControl = $(evt.currentTarget).closest(".annotationItem").find('.annotationDetail .controlPanel:first'),
annotator = this.annotator, annotator = this.annotator,
idAnnotation = shareControl.parent().find('.idAnnotation').html(), idAnnotation = shareControl.parent().find('.idAnnotation').html(),
uri = shareControl.parent().find('.uri').html(); uri = shareControl.parent().find('.uri').html();
//remove the last share container // remove the last share container
shareControl.find('.share-container-annotator').remove(); shareControl.find('.share-container-annotator').remove();
shareControl.append(annotator.plugins.Share.buildHTMLShareButton("",idAnnotation)); shareControl.append(annotator.plugins.Share.buildHTMLShareButton("",idAnnotation));
//Set actions button // Set actions button
annotator.plugins.Share.buttonsActions(shareControl[0],1,uri); annotator.plugins.Share.buttonsActions(shareControl[0],1,uri);
} else { } else {
$(evt.currentTarget).closest(".annotationItem").removeClass("open").addClass("closed"); $(evt.currentTarget).closest(".annotationItem").removeClass("open").addClass("closed");
...@@ -791,15 +790,15 @@ CatchAnnotation.prototype = { ...@@ -791,15 +790,15 @@ CatchAnnotation.prototype = {
} }
}, },
_onGeolocationClick: function(evt) { _onGeolocationClick: function(evt) {
var latitude = $(evt.target).parent().find('.latitude').html(), var latitude = $(evt.target).parent().find('.latitude').html();
longitude = $(evt.target).parent().find('.longitude').html(); var longitude = $(evt.target).parent().find('.longitude').html();
var imgSrc = '<img src="http://maps.googleapis.com/maps/api/staticmap?center='+latitude+','+longitude+'&zoom=14&size=500x500&sensor=false&markers=color:green%7Clabel:G%7C'+latitude+','+longitude+'">'; var imgSrc = '<img src="http://maps.googleapis.com/maps/api/staticmap?center='+latitude+','+longitude+'&zoom=14&size=500x500&sensor=false&markers=color:green%7Clabel:G%7C'+latitude+','+longitude+'">';
$(evt.target).parents('.detailHeader:first').find('#myLocationMap .map').html(imgSrc); $(evt.target).parents('.detailHeader:first').find('#myLocationMap .map').html(imgSrc);
}, },
_onPlaySelectionClick: function(evt) { _onPlaySelectionClick: function(evt) {
var id = $(evt.target).find('.idAnnotation').html(), var id = $(evt.target).find('.idAnnotation').html();
uri = $(evt.target).find('.uri').html(); var uri = $(evt.target).find('.uri').html();
container = $(evt.target).find('.container').html(); var container = $(evt.target).find('.container').html();
if(this.options.externalLink){ if(this.options.externalLink){
uri += (uri.indexOf('?') >= 0)?'&ovaId='+id:'?ovaId='+id; uri += (uri.indexOf('?') >= 0)?'&ovaId='+id:'?ovaId='+id;
location.href = uri; location.href = uri;
...@@ -819,7 +818,7 @@ CatchAnnotation.prototype = { ...@@ -819,7 +818,7 @@ CatchAnnotation.prototype = {
var anFound = an; var anFound = an;
var playFunction = function(){ var playFunction = function(){
//Fix problem with youtube videos in the first play. The plugin don't have this trigger // Fix problem with youtube videos in the first play. The plugin don't have this trigger
if (player.techName == 'Youtube'){ if (player.techName == 'Youtube'){
var startAPI = function(){ var startAPI = function(){
ovaInstance.showAnnotation(anFound); ovaInstance.showAnnotation(anFound);
...@@ -852,12 +851,12 @@ CatchAnnotation.prototype = { ...@@ -852,12 +851,12 @@ CatchAnnotation.prototype = {
} }
}, },
_onZoomToImageBoundsButtonClick: function(evt){ _onZoomToImageBoundsButtonClick: function(evt){
var zoomToBounds = $(evt.target).hasClass('zoomToImageBounds')?$(evt.target):$(evt.target).parents('.zoomToImageBounds:first'), var zoomToBounds = $(evt.target).hasClass('zoomToImageBounds')?$(evt.target):$(evt.target).parents('.zoomToImageBounds:first');
osdaId = zoomToBounds.find('.idAnnotation').html(), var osdaId = zoomToBounds.find('.idAnnotation').html();
uri = zoomToBounds.find('.uri').html(); var uri = zoomToBounds.find('.uri').html();
var allannotations = this.annotator.plugins['Store'].annotations, var allannotations = this.annotator.plugins['Store'].annotations;
osda = this.annotator.osda; var osda = this.annotator.osda;
if(this.options.externalLink){ if(this.options.externalLink){
uri += (uri.indexOf('?') >= 0)?'&osdaId='+osdaId:'?osdaId='+osdaId; uri += (uri.indexOf('?') >= 0)?'&osdaId='+osdaId:'?osdaId='+osdaId;
...@@ -865,8 +864,8 @@ CatchAnnotation.prototype = { ...@@ -865,8 +864,8 @@ CatchAnnotation.prototype = {
} }
for(var item in allannotations){ for(var item in allannotations){
var an = allannotations[item]; var an = allannotations[item];
//Makes sure that all images are set to transparent in case one was // Makes sure that all images are set to transparent in case one was
//previously selected. // previously selected.
an.highlights[0].style.background = "rgba(0,0,0,0)"; an.highlights[0].style.background = "rgba(0,0,0,0)";
if (typeof an.id!='undefined' && an.id == osdaId){//this is the annotation if (typeof an.id!='undefined' && an.id == osdaId){//this is the annotation
var bounds = new OpenSeadragon.Rect(an.bounds.x, an.bounds.y, an.bounds.width, an.bounds.height); var bounds = new OpenSeadragon.Rect(an.bounds.x, an.bounds.y, an.bounds.width, an.bounds.height);
...@@ -875,28 +874,28 @@ CatchAnnotation.prototype = { ...@@ -875,28 +874,28 @@ CatchAnnotation.prototype = {
console.log(an.target.container); console.log(an.target.container);
$('html,body').animate({scrollTop: $("#"+an.target.container).offset().top}, $('html,body').animate({scrollTop: $("#"+an.target.container).offset().top},
'slow'); 'slow');
//signifies a selected annotation once OSD has zoomed in on the // signifies a selected annotation once OSD has zoomed in on the
//appropriate area, it turns the background a bit yellow // appropriate area, it turns the background a bit yellow
an.highlights[0].style.background = "rgba(255,255,10,0.2)"; an.highlights[0].style.background = "rgba(255,255,10,0.2)";
} }
} }
}, },
_onQuoteMediaButton: function(evt){ _onQuoteMediaButton: function(evt){
var quote = $(evt.target).hasClass('quote')?$(evt.target):$(evt.target).parents('.quote:first'), var quote = $(evt.target).hasClass('quote')?$(evt.target):$(evt.target).parents('.quote:first');
id = quote.find('.idAnnotation').html(), var id = quote.find('.idAnnotation').html();
uri = quote.find('.uri').html(); var uri = quote.find('.uri').html();
if (typeof id=='undefined' || id==''){ if (typeof id=='undefined' || id==''){
this.refreshCatch(); this.refreshCatch();
this.checkTotAnnotations(); this.checkTotAnnotations();
id = quote.find('.idAnnotation').html(); id = quote.find('.idAnnotation').html();
//clickPlaySelection(evt); // clickPlaySelection(evt);
} }
if(this.options.externalLink){ if(this.options.externalLink){
uri += (uri.indexOf('?') >= 0)?'&ovaId='+id:'?ovaId='+id; uri += (uri.indexOf('?') >= 0)?'&ovaId='+id:'?ovaId='+id;
location.href = uri; location.href = uri;
}else{ }else{
var allannotations = this.annotator.plugins['Store'].annotations, var allannotations = this.annotator.plugins['Store'].annotations;
ovaId = id; var ovaId = id;
for (var item in allannotations) { for (var item in allannotations) {
var an = allannotations[item]; var an = allannotations[item];
if (typeof an.id!='undefined' && an.id == ovaId){//this is the annotation if (typeof an.id!='undefined' && an.id == ovaId){//this is the annotation
...@@ -909,9 +908,9 @@ CatchAnnotation.prototype = { ...@@ -909,9 +908,9 @@ CatchAnnotation.prototype = {
if(typeof startOffset!='undefined' && typeof endOffset!='undefined'){ if(typeof startOffset!='undefined' && typeof endOffset!='undefined'){
$(an.highlights).parent().find('.annotator-hl').removeClass('api'); $(an.highlights).parent().find('.annotator-hl').removeClass('api');
//change the color // change the color
$(an.highlights).addClass('api'); $(an.highlights).addClass('api');
//animate to the annotation // animate to the annotation
$('html,body').animate({ $('html,body').animate({
scrollTop: $(an.highlights[0]).offset().top}, scrollTop: $(an.highlights[0]).offset().top},
'slow'); 'slow');
...@@ -922,90 +921,90 @@ CatchAnnotation.prototype = { ...@@ -922,90 +921,90 @@ CatchAnnotation.prototype = {
} }
}, },
_refreshReplies: function(evt){ _refreshReplies: function(evt){
var item = $(evt.target).parents('.annotationItem:first'), var item = $(evt.target).parents('.annotationItem:first');
anId = item.attr('annotationId'); var anId = item.attr('annotationId');
var replyElem = $(evt.target).parents('.annotationItem:first').find('.replies'); var replyElem = $(evt.target).parents('.annotationItem:first').find('.replies');
var annotator = this.annotator, var annotator = this.annotator;
loadFromSearchURI = annotator.plugins.Store.options.loadFromSearch.uri, var loadFromSearchURI = annotator.plugins.Store.options.loadFromSearch.uri;
self = this, var self = this;
action='search', var action='search';
loadFromSearch={ var loadFromSearch={
limit:-1, limit:-1,
parentid:anId, parentid:anId,
uri:loadFromSearchURI, uri:loadFromSearchURI,
}, };
onSuccess=function(data){ var onSuccess=function(data){
if (data == null) data = {}; if (data == null) data = {};
annotations = data.rows || []; annotations = data.rows || [];
var _i,_len; var _i,_len;
for (_i = 0, _len = annotations.length; _i < _len; _i++) { for (_i = 0, _len = annotations.length; _i < _len; _i++) {
self._formatCatch(annotations[_i]); self._formatCatch(annotations[_i]);
} }
replyElem.html(self.TEMPLATES.annotationReply({ replyElem.html(self.TEMPLATES.annotationReply({
annotations: annotations annotations: annotations
})); }));
var replyItems = $('.replies .replyItem'); var replyItems = $('.replies .replyItem');
if(typeof replyItems != 'undefined' && replyItems.length > 0){ if(typeof replyItems != 'undefined' && replyItems.length > 0){
annotations.forEach(function(ann){ annotations.forEach(function(ann){
replyItems.each(function(item){ replyItems.each(function(item){
var id = $(replyItems[item]).attr('annotationid'); var id = $(replyItems[item]).attr('annotationid');
if(id == ann.id){ if(id == ann.id){
var perm = self.annotator.plugins.Permissions; var perm = self.annotator.plugins.Permissions;
if(!perm.options.userAuthorize('delete',ann,perm.user)){ if(!perm.options.userAuthorize('delete',ann,perm.user)){
$(replyItems[item]).find('.deleteReply').remove(); $(replyItems[item]).find('.deleteReply').remove();
}else{ }else{
$(replyItems[item]).data('annotation',ann); $(replyItems[item]).data('annotation',ann);
} }
} }
}); });
}); });
} }
}; };
var id, options, request, url, var id, options, request, url;
store = this.annotator.plugins.Store; var store = this.annotator.plugins.Store;
id = loadFromSearch && loadFromSearch.id; id = loadFromSearch && loadFromSearch.id;
url = store._urlFor(action, id); url = store._urlFor(action, id);
options = store._apiRequestOptions(action, loadFromSearch, onSuccess); options = store._apiRequestOptions(action, loadFromSearch, onSuccess);
request = $.ajax(url, options); request = $.ajax(url, options);
request._id = id; request._id = id;
request._action = action; request._action = action;
}, },
_onControlRepliesClick: function(evt){ _onControlRepliesClick: function(evt){
var action = $(evt.target)[0].className; var action = $(evt.target)[0].className;
if(action=='newReply'){ if(action=='newReply'){
var item = $(evt.target).parents('.annotationItem:first'), var item = $(evt.target).parents('.annotationItem:first');
id = item.attr('annotationId'); var id = item.attr('annotationId');
//Pre-show Adder // Pre-show Adder
this.annotator.adder.show(); this.annotator.adder.show();
//Get elements // Get elements
var replyElem = $(evt.target).parents('.annotationItem:first').find('.annotationDetail'), var replyElem = $(evt.target).parents('.annotationItem:first').find('.annotationDetail');
adder =this.annotator.adder, var adder =this.annotator.adder;
wrapper = $('.annotator-wrapper'); var wrapper = $('.annotator-wrapper');
//Calculate Editor position // Calculate Editor position
var positionLeft = videojs.findPosition($(evt.target).parent().find('.newReply')[0]), var positionLeft = videojs.findPosition($(evt.target).parent().find('.newReply')[0]);
positionAnnotator = videojs.findPosition(wrapper[0]), var positionAnnotator = videojs.findPosition(wrapper[0]);
positionAdder = {}; var positionAdder = {};
positionAdder.left = positionLeft.left - positionAnnotator.left; positionAdder.left = positionLeft.left - positionAnnotator.left;
positionAdder.top = positionLeft.top + 20 - positionAnnotator.top; positionAdder.top = positionLeft.top + 20 - positionAnnotator.top;
adder.css(positionAdder); adder.css(positionAdder);
//Open a new annotator dialog // Open a new annotator dialog
this.annotator.onAdderClick(); this.annotator.onAdderClick();
//Set vertical editor // Set vertical editor
this.annotator.editor.resetOrientation(); this.annotator.editor.resetOrientation();
this.annotator.editor.invertY(); this.annotator.editor.invertY();
this.annotator.editor.element.find('.annotator-widget').css('min-width',replyElem.css('width')); this.annotator.editor.element.find('.annotator-widget').css('min-width',replyElem.css('width'));
//set parent // set parent
var parentValue = $(this.annotator.editor.element).find(".reply-item span.parent-annotation"); var parentValue = $(this.annotator.editor.element).find(".reply-item span.parent-annotation");
parentValue.html(id); parentValue.html(id);
var self = this; var self = this;
...@@ -1022,16 +1021,16 @@ CatchAnnotation.prototype = { ...@@ -1022,16 +1021,16 @@ CatchAnnotation.prototype = {
return false; return false;
} }
//search // search
this._refreshReplies(evt); this._refreshReplies(evt);
}else if(action=='deleteAnnotation'){ }else if(action=='deleteAnnotation'){
if(confirm("Would you like to delete the annotation?")){ if(confirm("Would you like to delete the annotation?")){
var annotator = this.annotator, var annotator = this.annotator;
item = $(evt.target).parents('.annotationItem:first'), var item = $(evt.target).parents('.annotationItem:first');
id = item.attr('annotationId'), var id = item.attr('annotationId');
store = annotator.plugins.Store, var store = annotator.plugins.Store;
annotations = store.annotations, var annotations = store.annotations;
permissions = annotator.plugins.Permissions; var permissions = annotator.plugins.Permissions;
var annotation; var annotation;
annotations.forEach(function(ann){ annotations.forEach(function(ann){
if(ann.id == id) if(ann.id == id)
...@@ -1043,12 +1042,12 @@ CatchAnnotation.prototype = { ...@@ -1043,12 +1042,12 @@ CatchAnnotation.prototype = {
} }
}else if(action=='editAnnotation'){ }else if(action=='editAnnotation'){
var annotator = this.annotator, var annotator = this.annotator;
item = $(evt.target).parents('.annotationItem:first'), var item = $(evt.target).parents('.annotationItem:first');
id = item.attr('annotationId'), var id = item.attr('annotationId');
store = annotator.plugins.Store, var store = annotator.plugins.Store;
annotations = store.annotations, var annotations = store.annotations;
permissions = annotator.plugins.Permissions; var permissions = annotator.plugins.Permissions;
var annotation; var annotation;
annotations.forEach(function(ann){ annotations.forEach(function(ann){
if(ann.id == id) if(ann.id == id)
...@@ -1056,17 +1055,17 @@ CatchAnnotation.prototype = { ...@@ -1056,17 +1055,17 @@ CatchAnnotation.prototype = {
}); });
var authorized = permissions.options.userAuthorize('update', annotation,permissions.user); var authorized = permissions.options.userAuthorize('update', annotation,permissions.user);
if(authorized){ if(authorized){
//Get elements // Get elements
var wrapper = $('.annotator-wrapper'); var wrapper = $('.annotator-wrapper');
//Calculate Editor position // Calculate Editor position
var positionLeft = videojs.findPosition($(evt.target).parent().find('.editAnnotation')[0]), var positionLeft = videojs.findPosition($(evt.target).parent().find('.editAnnotation')[0]);
positionAnnotator = videojs.findPosition(wrapper[0]), var positionAnnotator = videojs.findPosition(wrapper[0]);
positionAdder = {}; var positionAdder = {};
positionAdder.left = positionLeft.left - positionAnnotator.left; positionAdder.left = positionLeft.left - positionAnnotator.left;
positionAdder.top = positionLeft.top + 20 - positionAnnotator.top; positionAdder.top = positionLeft.top + 20 - positionAnnotator.top;
var cleanup, offset, update, var cleanup, offset, update;
_this = this.annotator; var _this = this.annotator;
offset = positionAdder; offset = positionAdder;
update = function() { update = function() {
cleanup(); cleanup();
...@@ -1085,31 +1084,27 @@ CatchAnnotation.prototype = { ...@@ -1085,31 +1084,27 @@ CatchAnnotation.prototype = {
}, },
_onShareControlsClick: function(evt) { _onShareControlsClick: function(evt) {
var action = $(evt.target)[0].className; var action = $(evt.target)[0].className;
//TODO- Decide whether privacy or group button
if(action=='privacy_button'){ if(action=='privacy_button'){
//location.href = "index.php?r=video/privacy&id="+videoId;
}else if(action=='groups_button'){ }else if(action=='groups_button'){
alert("Coming soon..."); alert("Coming soon...");
}else if(action=='reply_button'){ }else if(action=='reply_button'){
var item = $(evt.target).parents('.annotationItem:first'), var item = $(evt.target).parents('.annotationItem:first'),
id = item.attr('annotationId'); id = item.attr('annotationId');
//New annotation // New annotation
var an = this.annotator.setupAnnotation(this.annotator.createAnnotation()); var an = this.annotator.setupAnnotation(this.annotator.createAnnotation());
an.text="010"; an.text="010";
an.parent = id; an.parent = id;
//Store the annotation
//this.annotator.plugins.Store.annotationCreated(an);
}else if(action=='share_button'){ }else if(action=='share_button'){
} }
}, },
_onPublicPrivateButtonClick: function(evt) { _onPublicPrivateButtonClick: function(evt) {
var action = $(evt.target).find('span'), var action = $(evt.target).find('span');
userId = ''; var userId = '';
//Get userI // Get userI
switch (action.html()){ switch (action.html()){
case 'public': case 'public':
userId = ''; userId = '';
...@@ -1122,36 +1117,36 @@ CatchAnnotation.prototype = { ...@@ -1122,36 +1117,36 @@ CatchAnnotation.prototype = {
break; break;
} }
this.current_tab = action.html(); this.current_tab = action.html();
//Change userid and refresh // Change userid and refresh
this.changeUserId(userId); this.changeUserId(userId);
}, },
_onSelectionButtonClick: function(evt){ _onSelectionButtonClick: function(evt){
var but = $(evt.target), var but = $(evt.target);
action = but.attr('media'); var action = but.attr('media');
//Get action // Get action
if (action.length<=0) action="text"; //By default if (action.length<=0) action="text"; // By default
//Change media and refresh // Change media and refresh
this.changeMedia(action); this.changeMedia(action);
}, },
_onMoreButtonClick: function(evt){ _onMoreButtonClick: function(evt){
this.clean = false; this.clean = false;
var moreBut = this.element.find('.annotationListButtons .moreButtonCatch'), var moreBut = this.element.find('.annotationListButtons .moreButtonCatch');
isLoading = moreBut.html()=='More'?false:true; var isLoading = moreBut.html()=='More'?false:true;
if(!isLoading) if(!isLoading)
this.loadAnnotations(); this.loadAnnotations();
}, },
_refresh:function(searchtype,searchInput){ _refresh:function(searchtype,searchInput){
var searchtype = searchtype || "", var searchtype = searchtype || "";
searchInput = searchInput || ""; var searchInput = searchInput || "";
this.clean = true; this.clean = true;
this._clearAnnotator(); this._clearAnnotator();
var annotator = this.annotator, var annotator = this.annotator;
loadFromSearch = annotator.plugins.Store.options.loadFromSearch; var loadFromSearch = annotator.plugins.Store.options.loadFromSearch;
loadFromSearch.limit = this.options.pagination; loadFromSearch.limit = this.options.pagination;
loadFromSearch.offset = 0; loadFromSearch.offset = 0;
...@@ -1182,38 +1177,37 @@ CatchAnnotation.prototype = { ...@@ -1182,38 +1177,37 @@ CatchAnnotation.prototype = {
this._refresh('',''); this._refresh('','');
}, },
_clearAnnotator: function(){ _clearAnnotator: function(){
var annotator = this.annotator, var annotator = this.annotator;
store = annotator.plugins.Store, var store = annotator.plugins.Store;
annotations = store.annotations.slice(); var annotations = store.annotations.slice();
annotations.forEach(function(ann){ annotations.forEach(function(ann){
var child, h, _i, _len, _ref; var child, h, _i, _len, _ref;
if (ann.highlights != null) { if (ann.highlights != null) {
_ref = ann.highlights; _ref = ann.highlights;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
h = _ref[_i]; h = _ref[_i];
if (!(h.parentNode != null)) { if (!(h.parentNode != null)) {
continue; continue;
}
child = h.childNodes[0];
$(h).replaceWith(h.childNodes);
} }
child = h.childNodes[0];
$(h).replaceWith(h.childNodes);
}
} }
store.unregisterAnnotation(ann); store.unregisterAnnotation(ann);
}); });
}, },
_onDeleteReplyButtonClick : function(evt){ _onDeleteReplyButtonClick : function(evt){
var annotator = this.annotator, var annotator = this.annotator;
item = $(evt.target).parents('.replyItem:first'), var item = $(evt.target).parents('.replyItem:first');
id = item.attr('annotationid'), var id = item.attr('annotationid');
permissions = annotator.plugins.Permissions, var permissions = annotator.plugins.Permissions;
annotation = item.data('annotation'); var annotation = item.data('annotation');
var authorized = permissions.options.userAuthorize('delete', annotation,permissions.user); var authorized = permissions.options.userAuthorize('delete', annotation,permissions.user);
if(authorized){ if(authorized){
if(confirm('Would you like to delete this reply?')){ if(confirm('Would you like to delete this reply?')){
annotator.plugins['Store']._apiRequest('destroy', annotation, function(){}); annotator.plugins['Store']._apiRequest('destroy', annotation, function(){});
item.remove(); item.remove();
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment