image_annotation/commit

move DenichePlugin init to same YUI sandbox as the autocompletion widgets

authorJacco van Ossenbruggen
Mon Jun 30 11:25:22 2014 +0200
committerJacco van Ossenbruggen
Mon Jun 30 11:25:22 2014 +0200
commit3d9ed5322b5e4af4d2835ea7e2f4c177da7c5bb9
tree1e30ec8b131379c777d00926e3e0c536ccb133c5
parentcea401ce42e7e145bbb0ef291b871915f6b16e87
Diff style: patch stat
diff --git a/applications/annotation.pl b/applications/annotation.pl
index 3840c39..2fb572e 100644
--- a/applications/annotation.pl
+++ b/applications/annotation.pl
@@ -420,7 +420,15 @@ yui_script(Options) -->
 	},
 	yui3([json([modules(json(Modules))])],
 	     ['recordset-base'|Includes],
-	     [\js_annotation_fields(Fields, Options)]).
+	     [\js_annotation_fields(Fields, Options),
+	      \js_fragment_plugin(Options)
+	     ]).
+
+js_fragment_plugin(Options) -->
+	{ fragments_enabled(Options), !
+	},
+	html(['anno.addPlugin("DenichePlugin", {yui_sandbox:Y});']).
+js_fragment_plugin(_Options) --> !.
 
 js_module('annotation', json([fullpath(Path),
 				    requires(['recordset-base',
@@ -497,7 +505,7 @@ js_annotation_field(FieldURI, Options) -->
 	  option(image_id(ImageId), Options, null),
 	  option(fields_id(FieldsId), Options, null),
 	  option(lazy(Lazy), Options, false),
-	  option(showTag(ShowTag), Options, mine),
+	  option(showTag(ShowTag), Options, ShowTagDefault),
 	  field_id(FieldURI, Target,  Id),
 	  field_id(NextURI,  Target, Next),
 	  user_url(DefaultUser),
@@ -515,8 +523,8 @@ js_annotation_field(FieldURI, Options) -->
 	  (   rdf(FieldURI, ann_ui:deleteEnabled,   literal(Delete))
 	  ->  true
 	  ;   logged_on(admin)
-	  ->  Delete=always
-	  ;   Delete=mine
+	  ->  Delete=always, ShowTagDefault=always
+	  ;   Delete=mine, ShowTagDefault=mine
 	  ),
 	  ui_labels(FieldURI, Options, UI_labels),
 	  http_location_by_id(http_add_annotation, Add),
diff --git a/web/js/deniche-plugin.js b/web/js/deniche-plugin.js
index dfa3b1a..b5c416b 100644
--- a/web/js/deniche-plugin.js
+++ b/web/js/deniche-plugin.js
@@ -35,7 +35,7 @@
  * */
 
 
-annotorious.plugin.DenichePlugin = function(opt_config_options) { 
+annotorious.plugin.DenichePlugin = function(config) { 
 	/** @public **/
 	this.currentShape = null; // Should be accessible by cpack objects
 
@@ -44,14 +44,15 @@ annotorious.plugin.DenichePlugin = function(opt_config_options) {
 	this._dirtytag = null;	// tag annotorious doesn't know yet
 	this._saveButtons = {};	 // we have multiple buttons if we have multiple images per page
 	this._cancelButtons = {};
-
+	// console.log(config);
+	if (config.yui_sandbox) 
+		this.Y = config.yui_sandbox;
 }
 
 annotorious.plugin.DenichePlugin.states = { EMPTY:'empty', SOME:'some' };
 
 annotorious.plugin.DenichePlugin.prototype.onInitAnnotator = function(annotator) {
     this.annotator = annotator;
-    this.Y = YUI().use('node', 'event');
     // move the cpack editor into the annotorious editor:
     var el =  annotator.element;
     var fieldsId = el.getElementsByTagName('img')[0].getAttribute('fields');
@@ -89,13 +90,13 @@ annotorious.plugin.DenichePlugin.prototype.toggleButtons = function(state, field
 
 annotorious.plugin.DenichePlugin.prototype.filterTags = function(targetId, fieldsId) {
 	var oSelf = this;
-	oSelf.Y.one('.annotorious-editor').detach("key", oSelf.onFragmentCancel, "esc");
-	oSelf.Y.one('.annotorious-editor').on("key", oSelf.onFragmentCancel, "esc", oSelf);
+	var editor = oSelf.Y.one('.annotorious-editor');
+	editor.on("key", oSelf.onFragmentCancel, "esc", oSelf);
 	var selector = '#'+ fieldsId + ' li.tagitem';
 	if (!fieldsId) selector = 'li.tagitem';
 	oSelf.Y.all(selector).each(function(tagNode) {
 		if (targetId == tagNode.getAttribute('targetId')) {
-			oSelf.Y.all('.annotorious-editor').detach("key", oSelf.onFragmentCancel, "esc");
+			editor.detach("key", oSelf.onFragmentCancel, "esc");
 			tagNode.show();
 		} else {
 			tagNode.hide();
@@ -122,6 +123,7 @@ annotorious.plugin.DenichePlugin.prototype.onFragmentCancel = function(ev) {
 }
 
 annotorious.plugin.DenichePlugin.prototype.addAnnotation = function (annotation, update) {
+	// console.log('addAnnotation');
 	var old = this._dirtytag;
 	if (!old) old = this._cleantags[annotation.targetId];
 	if (old) {	
@@ -192,5 +194,3 @@ annotorious.plugin.DenichePlugin.prototype.installHandlers = function() {
 		oSelf.flushDirtyAnnotation(original);
 	});
 }
-
-anno.addPlugin('DenichePlugin', {});