Commit fbfc2aff5372332dd0684ad7d9cfb07e89e7c8d0

Custome options - Popup display, editor style changes
  
11/** Global item styles **/
2.custom-style-popup {
3 list-style: none;
4 padding-left: 0px;
5}
26
7.custom-popup-line {
8 border-top: 1px solid #ccc;
9 line-height: 200%;
10 font-size:14px;
11 font-family: Arial, Verdana, Sans;
12 color: #000;
13
14}
315.annotorious-opacity-fade {
416 -moz-transition-property: opacity;
517 -moz-transition-duration: 0.5s;
169169}
170170
171171.annotorious-popup-field {
172 border-top:1px solid #ccc;
172 /*border-top:1px solid #ccc;*/
173173 margin:6px 0px 0px 0px;
174174 padding-top:2px;
175175}
198198 border-color:#ccc;
199199 line-height: normal;
200200 background-color:#fff;
201 width:240px;
201 width:100%;
202202 height:50px;
203203 outline:none;
204204 font-family:Verdana, Arial;
  
11annotorious.plugin.CustomFields = function(opt_config_options) {
22
3
43annotorious.plugin.CustomFields.prototype.onInitAnnotator = function(annotorious) {
5 var textTemplate= _.template($('#button-template').html());
6 annotorious.editor.addField(textTemplate);
7 var popupTemplate = _.template($('#popup-template').html());
8 annotorious.popup.addField(function(annotation){
9 var container = document.createElement('div');
10 var el = document.createElement('span');
11 el.href = '#';
12 el.className = 'annotorious-popup-text';
13 console.log(annotation.text);
14 el.innerHTML= annotation.text;
15 container.appendChild(el);
16 return container;
17
4 var dropDownTemplate= _.template($('#dropdown-template').html()); // creates the HTML element for dropdown - from template in index.html
5 annotorious.editor.addField(dropDownTemplate); // add dropdown to editor UI widget
6 annotorious.popup.addField( function(annotation){
7 var popupTemplate = _.template($('#popup-template').html()); //created a popup template - yet to find how to bind it to newanno
8 if(annotation.text1 != undefined) {
9 //console.log(annotation.text1.Comment); annotation.text is Obj - can
10 //access each element Comment, tags, links..
11 return popupTemplate(annotation.text1);
12 }
13 else {
14 return '';
15 }
1816 });
1917 }
2018}
  
151151 _.each(swtr.sweets.models, function(swt) {
152152 if(!_.has(swt.get('how'), 'editable')) {
153153 swt.get('how')['editable'] = false;
154 swt.get('how').text += '\n - by ' + swt.get('who');
154 console.log(swt.get('how').text.Comment);
155 swt.get('how').text += '\n - by ' + swt.get('who');
155156 }
156157 console.log(swt.get('how'));
157158 anno.addAnnotation(swt.get('how'));
182182 'click #sweet': 'sweet',
183183 'click #signin-credentials': 'getSignInCredentials',
184184 'click #setbox': 'showHide',
185 'change .form-control': 'button_custom',
186 'mouseup .annotorious-editor-button-save': 'add_new_anno'
185 'change #custom-dropdown ': 'getFormValue',
186 'mouseup .annotorious-editor-button-save': 'addNewAnno'
187187 },
188188 initialize: function() {
189189 //var allElements = $('body *');
190190 this.helpview = new HelpView();
191191 this.sweetsview = new SweetsView({collection: swtr.sweets});
192192 anno.addHandler('onAnnotationCreated', this.showSwtHelp);
193 anno.addHandler('onannotationupdated', this.showswthelp);
193 anno.addHandler('onannotationupdated', this.showSwtHelp);
194194 anno.addHandler('onSelectionStarted', function(annotation) {
195195 anno.hideAnnotations();});
196196 anno.addHandler('onSelectionCompleted', function(annotation) {
197197 anno.showAnnotations();
198198 });
199 anno.addPlugin('CustomFields', this.showSwtHelp);
200 anno.addHandler('onSelectionCompleted', this.setShape);
199 anno.addPlugin('CustomFields', this.showSwtHelp);
200 anno.addHandler('onSelectionCompleted', this.getShape);
201201 this.$overlay = $('#app-overlay');
202202 this.$img = $('#annotatable-img');
203203 this.imgURL = this.$img.attr('src');
240240 swtr.sweets.add(data);
241241 _.each(data, function(swt) {
242242 swt.how['editable'] = false;
243 swt.how.text += '\n - by ' + swt.who;
243 if(typeof swt.how.text === 'object') {
244 swt.how.text1 = swt.how.text;
245 swt.how.text = '\n - by ' + swt.who;
246 } else {
247 swt.how.text1 = undefined;
248 swt.how.text += '\n -by ' + swt.who;
249 }
250
244251 anno.addAnnotation(swt.how);
245 console.log('swt.how = ', swt.how);
246252 });
247253 swtr.appView.$overlay.hide();
248254 swtr.appView.helpview.step(2);
277277 swtr.sweets.add({
278278 who: swtr.who,
279279 where: anno.src,
280 how: newanno //mysterious link to create the sweet with new anno attributes, tags, links, labels
280 how: anno //mysterious link to create the sweet with new anno attributes, tags, links, labels
281281 });
282282 });
283283 },
304304//to obtain shapes object, declaring annotation in global scope - TODO refactor
305305//code to find better way to do this.
306306
307 setShape: function(annotation) {
308 $('.annotorious-editor-text').hide();
309 $('.annotorious-editor').css("width", "100%");
310 window.annotation=annotation;
311 annotation.text = [];
307 getShape: function(annotation) {
308 $('.annotorious-editor-text').slideUp();
309 $('.annotorious-editor').css("width", "100%");
310 window.annotation=annotation; // to use annotation.shape in newanno
311 annotation.text = {}; // creating new text object - to contain comments, labels, links and tags
312312 },
313313//to create new annotation object
314 inputStore: function(opt) {
315 var temp = opt;
314 annoTemplate: function(opt) {
315 var annoText = opt;
316316 var src = $('#img-url-input').val();
317 this.newanno = {'src':src, 'text':temp, 'shapes': [{'type':annotation.shape.type, 'geometry':{'x':annotation.shape.geometry.x, 'y':annotation.shape.geometry.y, 'width':annotation.shape.geometry.width, 'height':annotation.shape.geometry.height}},], 'context':window.location.origin};
318
317 this.newanno = {'src':src, 'text':annoText, 'shapes': [{'type':annotation.shape.type, 'geometry':{'x':annotation.shape.geometry.x, 'y':annotation.shape.geometry.y, 'width':annotation.shape.geometry.width, 'height':annotation.shape.geometry.height}},], 'context':window.location.origin};
319318 },
320319
321320//to add the final annotation
322
323321//save button - event bind
324 add_new_anno: function(event){
325 var $selected = $('select option:selected');
326 var tempinput = $selected.text()+': '+$('.annotorious-editor textarea').val();
327 this.newanno.text.push(tempinput);
328 var newinput = this.newanno.text.toString();
329 this.newanno.text = newinput;
330 console.log('this.newanno = ', this.newanno);
331 //this.to_Add(this.newanno);
322 addNewAnno: function(event){
323 var $selected = $('select option:selected').text();
324 var textInput = $('.annotorious-editor textarea').val();
325 this.newanno.text[$selected] = textInput;
332326 var newanno = this.newanno;
333 window.newanno = newanno;
327 anno.addAnnotation(newanno);
334328 },
329 /*addNewAnno: function(event){ // function for form input UI
330 var tags = $('#tags').val();
331 var label = $('#label').val();
332 var link = $('#links').val();
333 var text = $('.annotorious-editor textarea').val();
334 var finalInput = ' Label: '+label+' Comment: '+text+' Tags: '+tags+' Links: '+link;
335 //this.annoTemplate(label, text, tags, link);
336 // this.annoTemplate(label, text, tags, link);
337 var src = $('#img-url-input').val();
338 var newanno = {'src':src, 'text':finalInput, 'shapes': [{'type':annotation.shape.type, 'geometry':{'x':annotation.shape.geometry.x, 'y':annotation.shape.geometry.y, 'width':annotation.shape.geometry.width, 'height':annotation.shape.geometry.height}},], 'context':window.location.origin};
339 console.log(newanno);
340 anno.addAnnotation(newanno);
341 },*/
335342//dropdown event
336 button_custom: function(event) {
337 $('.annotorious-editor-text').show();
343 getFormValue: function(event) {
344 var annoForm = $('.annotorious-editor-text');
345 annoForm.slideDown();
338346 var $selected = $('select option:selected');
339 var tempinput = $selected.prev().text()+ ': '+$('.annotorious-editor-text').val();
340 if(tempinput === "Choose an Option: "){
341 console.log('');
347 var textInput = annoForm.val();
348 if(textInput) {
349 annotation.text[$selected.prev().text()] = textInput;
342350 }
343 else {
344 annotation.text.push(tempinput);
345 }
346 this.inputStore(annotation.text);
347 $('.annotorious-editor-text:first').val("");
348 $('.annotorious-editor-text:first').attr('placeholder', 'Add a '+$selected.text());
351 this.annoTemplate(annotation.text);
352 annoForm.val('');
353 annoForm.attr('placeholder', 'Add '+$selected.text());
349354 },
350355
351356
  
9393 <input type="password" class="form-control" id="password" placeholder="Password">
9494 </div>
9595 </script>
96 <script type="text/template" id="button-template">
97 <select class="form-control">
96 <script type="text/template" id="dropdown-template">
97 <select class="form-control" id="custom-dropdown">
9898 <option id="">Choose an Option</option>
9999 <option id="comment" >Comment</option>
100 <option id="label" >Label</option>
100 <option id="title" >Title</option>
101101 <option id="tags">Tags</option>
102102 <option id="links">Links</option>
103103 </select>
104104 </script>
105 <!-- script type="text/template" id="dropdown-template">
106 <form class="form-control" id="custom-dropdown">
107 <textarea class="annotorious-editor-text goog-textarea"
108 placeholder="Add Label" id="label"></textarea>
109 <textarea class="annotorious-editor-text goog-textarea"
110 placeholder="Add Tags" id="tags"></textarea>
111 <textarea class="annotorious-editor-text goog-textarea"
112 placeholder="Add Links" id="links"></textarea>
113 </form>
114 </script-->
105115 <script type="text/template" id="popup-template">
106 <span class="annotorious-popup-text"> </span>
116 <span class="annotorious-popup-text">
117 <ul class="custom-style-popup">
118 <li class="custom-popup-line" ><span>Label: </span><%= Label %></li>
119 <li class="custom-popup-line"><span>Comment: </span><%= Comment %></li>
120 <li class="custom-popup-line"><span>Tags: </span><%= Tags %></li>
121 <li class="custom-popup-line"><span>Related Links: </span><%= Links %></li>
122 </ul>
123 </span>
107124 </script>
108125 </body>
109126</html>