Commit cecc2b1026dd2d89a5c0df9faeb071627a7f2fca
- Diff rendering mode:
- inline
- side by side
swtr/static/js/img_swtr.js
(39 / 16)
  | |||
104 | 104 | swtr.ImgAnnoView = Backbone.View.extend({ | |
105 | 105 | el: $('#img-annotation-wrapper'), | |
106 | 106 | events: { | |
107 | 'change #custom-dropdown': 'getFormValue', | ||
107 | 'keydown .annotorious-editor-button-save': 'getFormValue', | ||
108 | 'mousedown .annotorious-editor-button-save': 'getFormValue', | ||
108 | 109 | 'click #toggle-anno-areas': 'toggleAnnoAreas' | |
109 | 110 | }, | |
110 | 111 | initialize: function(options) { | |
… | … | ||
156 | 156 | updateNewAnno: function(annotation) { | |
157 | 157 | console.log('updateNewAnno()'); | |
158 | 158 | var self = swtr.imgAnnoView; | |
159 | console.log(annotation.text); | ||
159 | 160 | // get the final value/input from the editor | |
160 | var selected = $('select option:selected').text().toLowerCase(); | ||
161 | /* var selected = $('select option:selected').text().toLowerCase(); | ||
161 | 162 | var text_input = $('.annotorious-editor-text').val(); | |
162 | 163 | if( selected === "tags") { | |
163 | 164 | self.new_anno[selected] = $('#tags-input').tags().getTags(); | |
… | … | ||
166 | 166 | else { | |
167 | 167 | // update it in our annotation object | |
168 | 168 | self.new_anno[selected] = text_input; | |
169 | } | ||
169 | }*/ | ||
170 | 170 | // prepare the text field | |
171 | self.new_anno.comment = annotation.text; | ||
171 | 172 | self.new_anno.text = self.createPopupText(self.new_anno); | |
172 | 173 | // update the annotorious annotation object with the new values | |
173 | 174 | if(self.new_anno.comment) { | |
174 | annotation.comment = self.new_anno.comment; | ||
175 | annotation.comment = annotation.text; | ||
175 | 176 | } | |
176 | 177 | if(self.new_anno.link) { | |
177 | 178 | annotation.link = self.new_anno.link; | |
… | … | ||
192 | 192 | console.log('hideOriginalEditor()'); | |
193 | 193 | var self = swtr.imgAnnoView; | |
194 | 194 | self.new_anno = {}; | |
195 | $('#tags-input').tags({ | ||
196 | tagSize: 'md', | ||
197 | promptText: 'Type word (and press enter)..', | ||
198 | caseInsensitive: true, | ||
199 | suggestions: self.tags_suggestions | ||
200 | }); | ||
195 | 201 | self.getSuggestionsForTags(); | |
196 | 202 | //$('.annotorious-editor-text').hide(); | |
197 | 203 | //$('.annotorious-editor').css('width', '100%'); | |
198 | 204 | }, | |
199 | 205 | getFormValue: function(event) { | |
200 | 206 | console.log('getFormValue()'); | |
201 | |||
202 | 207 | var self = swtr.imgAnnoView; | |
203 | 208 | // show the editor field to input text | |
204 | var $anno_form = $('.annotorious-editor-text'); | ||
209 | $('.annotorious-editor-text').each(function(index, element) { | ||
210 | if( index === 0) { | ||
211 | self.new_anno['comment'] = $(element).text(); | ||
212 | console.log(index, $(element).text() ); | ||
213 | } | ||
214 | else if ( index === 1) { | ||
215 | self.new_anno['title'] = $(element).val(); | ||
216 | console.log(index, $(element).val() ); | ||
217 | } | ||
218 | else if (index === 2) { | ||
219 | self.new_anno['link'] = $(element).val(); | ||
220 | console.log(index, $(element).val() ); | ||
221 | } | ||
222 | else { | ||
223 | self.new_anno['tags'] = $(element).tags().getTags(); | ||
224 | console.log(index, $('#tags-input').tags().getTags() ); | ||
225 | } | ||
226 | |||
227 | }); | ||
228 | // show the editor field to input text | ||
229 | /* var $anno_form = $('.annotorious-editor-text'); | ||
205 | 230 | //$anno_form.slideDown(); | |
206 | 231 | // get the previous item entered | |
207 | 232 | var $selected = $('select option:selected'); | |
… | … | ||
245 | 245 | } | |
246 | 246 | ||
247 | 247 | // if the current selected is tags | |
248 | if($selected.text() === 'Tags') { | ||
249 | 248 | $('#tags-input').tags({ | |
250 | 249 | tagSize: 'md', | |
251 | 250 | promptText: 'Type word (and press enter)..', | |
252 | 251 | caseInsensitive: true, | |
253 | 252 | suggestions: self.tags_suggestions | |
254 | 253 | }); | |
255 | $('#tags-input').show(); | ||
256 | $('.annotorious-editor-text').hide(); | ||
257 | } | ||
258 | else { | ||
259 | $('#tags-input').hide(); | ||
260 | $('.annotorious-editor-text').show(); | ||
261 | } | ||
262 | $anno_form.val(''); | ||
254 | |||
255 | |||
256 | /* $anno_form.val(''); | ||
263 | 257 | $anno_form.attr('placeholder', 'Add ' + $selected.text()); | |
264 | console.log(self.new_anno); | ||
258 | console.log(self.new_anno);*/ | ||
259 | |||
265 | 260 | }, | |
266 | 261 | createPopupText: function(annotation) { | |
267 | 262 | // title |
  | |||
1 | 1 | annotorious.plugin.CustomFields = function(opt_config_options) { | |
2 | 2 | ||
3 | 3 | annotorious.plugin.CustomFields.prototype.onInitAnnotator = function(annotorious) { | |
4 | var dropDownTemplate= _.template($('#dropdown-template').html()); // creates the HTML element for dropdown - from template in index.html | ||
4 | var dropDownTemplate= _.template($('#customEdit-template').html()); // creates the HTML element for dropdown - from template in index.html | ||
5 | 5 | annotorious.editor.addField(dropDownTemplate); // add dropdown to editor UI widget | |
6 | 6 | annotorious.popup.addField( function(annotation){ | |
7 | 7 | var popupTemplate = _.template($('#popup-template').html()); //created a popup template - yet to find how to bind it to newanno |
swtr/templates/index.html
(14 / 1)
  | |||
234 | 234 | <p><%= how %></p> | |
235 | 235 | </li> | |
236 | 236 | </script> | |
237 | <script type="text/template" id="dropdown-template"> | ||
237 | <!--script type="text/template" id="dropdown-template"> | ||
238 | 238 | <div id="tags-input"></div> | |
239 | 239 | <select class="form-control" id="custom-dropdown"> | |
240 | 240 | <option value="comment" selected>Comment</option> | |
… | … | ||
242 | 242 | <option value="tags">Tags</option> | |
243 | 243 | <option value="link">Link</option> | |
244 | 244 | </select> | |
245 | </script--> | ||
246 | <script type="text/template" id="customEdit-template"> | ||
247 | <textarea id="title-input" class="annotorious-editor-text goog-textarea" placeholder="Add | ||
248 | Title" tabindex="1" rows="2" style="overflow-y: hidden; overflow-x: | ||
249 | auto; box-sizing: border-box; height: 23px; padding-bottom: | ||
250 | 4px;"></textarea> | ||
251 | <textarea id="link-input" class="annotorious-editor-text goog-textarea" placeholder="Add | ||
252 | Links" tabindex="1" rows="3" style="overflow-y: hidden; overflow-x: auto; | ||
253 | box-sizing: border-box; height: 23px; padding-bottom: 4px;"></textarea> | ||
254 | <div id="tags-input" class="annotorious-editor-text goog-textarea" | ||
255 | placeholder="" tabindex="1" rows="4" style="overflow-y: auto; overflow-x: | ||
256 | hidden; | ||
257 | box-sizing: border-box; height: 23px; padding-bottom: 4px;"></textarea> | ||
245 | 258 | </script> | |
246 | 259 | <script type="text/template" id="popup-template"> | |
247 | 260 | <span class="annotorious-popup-text"> |