First step of context menu to add tag by selecting a part of text in the page.
authorcavaliet
Wed, 09 Nov 2011 17:33:26 +0100
changeset 31 b910b4f7485f
parent 30 d2fba1e3b94b
child 32 38dcd2db04e4
First step of context menu to add tag by selecting a part of text in the page.
Resources/config/doctrine/DocumentTag.orm.yml
Resources/public/css/wikiTag.css
Resources/public/js/wikiTag.js
Resources/views/WikiTag/TagList.html.twig
Resources/views/WikiTag/documentTags.html.twig
Resources/views/WikiTag/javascript.html.twig
--- a/Resources/config/doctrine/DocumentTag.orm.yml	Wed Nov 09 16:25:13 2011 +0100
+++ b/Resources/config/doctrine/DocumentTag.orm.yml	Wed Nov 09 17:33:26 2011 +0100
@@ -20,6 +20,7 @@
     wikipediaRevisionId:
       type: bigint
       column: wikipedia_revision_id
+      nullable: true
   manyToOne:
     tag:
       targetEntity: Tag
--- a/Resources/public/css/wikiTag.css	Wed Nov 09 16:25:13 2011 +0100
+++ b/Resources/public/css/wikiTag.css	Wed Nov 09 17:33:26 2011 +0100
@@ -86,6 +86,19 @@
     padding: 3px;
 }
 
+
+/* Styles for hidden context div, displayed on text selected */
+#wikitag_context_div {
+    width: 260px;
+    border: 2px;
+    background: lightgreen;
+    display: none;
+    float: none;
+    position: absolute;
+}
+
+
+
 /*
 
 
--- a/Resources/public/js/wikiTag.js	Wed Nov 09 16:25:13 2011 +0100
+++ b/Resources/public/js/wikiTag.js	Wed Nov 09 17:33:26 2011 +0100
@@ -214,6 +214,89 @@
     });
 }
 
+function wikitag_init_search_context_events()
+{
+	// We implement the behaviour on text select. Kolich is just an object name, it could be anything
+	if(!window.Kolich){
+	    Kolich = {};
+	}
+	Kolich.Selector = {};
+	Kolich.Selector.getSelected = function(){
+	    var t = '';
+	    if(window.getSelection){
+	        t = window.getSelection();
+	    }else if(document.getSelection){
+	        t = document.getSelection();
+	    }else if(document.selection){
+	        t = document.selection.createRange().text;
+	    }
+	    return t;
+	}
+	Kolich.Selector.mouseup = function(e){
+	  var st = Kolich.Selector.getSelected();
+	  if(st!=''){
+	    // Behaviour after the text was selected
+	    $("#wikitag_context_div").offset({left:e.pageX+10,top:e.pageY});
+	    $("#wikitag_context_div").show();
+	    $("#wikitag_context_div #wikitag_wp_search_context").val(st);
+	    $("#wikitag_context_div #wikitag_wp_search_context").autocomplete("search");
+	  }
+	}
+	$(document).ready(function(){
+	    $(document).bind("mouseup", Kolich.Selector.mouseup);
+	});
+	
+	// Function to close the context window
+	$("#wikitag_context_close").click(function(e){
+	    $("#wikitag_context_div #wikitag_wp_search_context").autocomplete("close");
+	    $("#wikitag_context_div").offset({left:0,top:0});
+	    $("#wikitag_context_div").hide();
+	});
+	
+	// Wikipedia search management (new tag)
+	$("#wikitag_wp_search_context").autocomplete({
+	    source: function( request, response ) {
+	        $.ajax({
+	            url: "http://fr.wikipedia.org/w/api.php",
+	            dataType: "jsonp",
+	            data: {
+	                action: "opensearch",
+	                limit: "20",
+	                namespace: "0",
+	                format: "json",
+	                search: request.term
+	            },
+	            success: function( data ) {
+	                response( $.map( data[1], function( item ) {
+	                    return {
+	                        label: item,
+	                        value: item
+	                    }
+	                }));
+	            }
+	        });
+	    },
+	    select: function(event, ui) { 
+	        // Since the event still did not update wp_search's val, we force it.
+	        $("#wikitag_wp_search_context").val(ui.item.label);
+	        add_tag($("#wikitag_wp_search_context").val());
+	        $("#wikitag_context_close").click();
+	    },
+	    minLength: 2,
+	    open: function() {
+	        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
+	    },
+	    close: function() {
+	        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
+	    }
+	});
+	$('#wikitag_wp_search_context').keyup(function(e){
+	    if((e.keyCode==13) && ($("#wikitag_wp_search_context").val()!="")){
+	        add_tag($("#wikitag_wp_search_context").val());
+	    }
+	});
+}
+
 function wikitag_update_tag(btn)
 {
     new_checked = false;
--- a/Resources/views/WikiTag/TagList.html.twig	Wed Nov 09 16:25:13 2011 +0100
+++ b/Resources/views/WikiTag/TagList.html.twig	Wed Nov 09 17:33:26 2011 +0100
@@ -21,9 +21,6 @@
         <a href="?num_page={{last_page}}&nb_by_page={{nb_by_page}}&sort={{sort}}">&gt;&gt;</a></p>
     {% endif %}</p>
   </div>
-{#<input type="hidden" name="num_page" value="{{num_page}}" id="num_page" />
-<input type="hidden" name="nb_by_page" value="{{nb_by_page}}" id="nb_by_page" />
-<input type="hidden" name="sort" value="{% if sort %}{{sort}}{% endif %}" id="sort" />#}
 </form>
 <div id="wikitag_table_container">
 {% include "WikiTagBundle:WikiTag:TagListTable.html.twig" %}
--- a/Resources/views/WikiTag/documentTags.html.twig	Wed Nov 09 16:25:13 2011 +0100
+++ b/Resources/views/WikiTag/documentTags.html.twig	Wed Nov 09 17:33:26 2011 +0100
@@ -10,4 +10,8 @@
 <div id="wikitag_table_container" style="float:left; width: 100%">
   {% include 'WikiTagBundle:WikiTag:tagTable.html.twig' %}
 </div>
+<div id="wikitag_context_div">
+<p>Choisissez le tag à ajouter<span style="float:right" class="wikitag_hand_cursor" id="wikitag_context_close" ><b>X</b></p>
+<p><input type="text" name="wikitag_wp_search_context" id="wikitag_wp_search_context" size="35" /></p>
+</div>
 {% endblock %}
--- a/Resources/views/WikiTag/javascript.html.twig	Wed Nov 09 16:25:13 2011 +0100
+++ b/Resources/views/WikiTag/javascript.html.twig	Wed Nov 09 17:33:26 2011 +0100
@@ -27,7 +27,12 @@
     var categories_list = '{{ categories|raw }}';
     
     $(document).ready(function(){
-    	wikitag_init_tags_events();
-    	wikitag_init_datasheet_events();
+        wikitag_init_tags_events();
+        wikitag_init_datasheet_events();
+    	
+    {% if tags_list!=true %}
+        wikitag_init_search_context_events();        
+ 	{% endif %}
+    	
     });
 </script>
\ No newline at end of file