# HG changeset patch # User cavaliet # Date 1320856406 -3600 # Node ID b910b4f7485fe9cc9c3663d4f7236f315c256be2 # Parent d2fba1e3b94b958bf762c43dc0bcd8184437675a First step of context menu to add tag by selecting a part of text in the page. diff -r d2fba1e3b94b -r b910b4f7485f Resources/config/doctrine/DocumentTag.orm.yml --- 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 diff -r d2fba1e3b94b -r b910b4f7485f Resources/public/css/wikiTag.css --- 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; +} + + + /* diff -r d2fba1e3b94b -r b910b4f7485f Resources/public/js/wikiTag.js --- 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; diff -r d2fba1e3b94b -r b910b4f7485f Resources/views/WikiTag/TagList.html.twig --- 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 @@ >>

{% endif %}

-{# - -#}
{% include "WikiTagBundle:WikiTag:TagListTable.html.twig" %} diff -r d2fba1e3b94b -r b910b4f7485f Resources/views/WikiTag/documentTags.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 @@
{% include 'WikiTagBundle:WikiTag:tagTable.html.twig' %}
+
+

Choisissez le tag à ajouterX

+

+
{% endblock %} diff -r d2fba1e3b94b -r b910b4f7485f Resources/views/WikiTag/javascript.html.twig --- 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 %} + }); \ No newline at end of file