diff --git a/app/assets/javascripts/desktop/journal_pages.js.erb b/app/assets/javascripts/desktop/journal_pages.js.erb index 9b7c0a03..f2cdab80 100644 --- a/app/assets/javascripts/desktop/journal_pages.js.erb +++ b/app/assets/javascripts/desktop/journal_pages.js.erb @@ -229,6 +229,8 @@ orbitDesktop.prototype.initializeJournalPapers = function(target,url,cache){ // }) } bindHandlers(); + + } this.initializeJournalPapers.coAuthorformCallback = function(data){ if(data.success){ diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js index dc183d3d..a37154d9 100755 --- a/app/assets/javascripts/orbitdesktop.js +++ b/app/assets/javascripts/orbitdesktop.js @@ -6,6 +6,7 @@ //container=true is the area where the view will be loaded //load = true is used to load the list element by default //response-type = "json"|"script"|"xml|html" default is json +//autocomplete-list = "listname" an array from which autocomplete will be attached to its respective input or textarea $.extend($.expr[':'], { @@ -172,6 +173,7 @@ var orbitDesktop = function(dom){ }) } }); + var $widget_fn = $('.widget_fn'),$fn_des = $('.fn_des'); $widget_fn.hover(function(){ var fn_name = $(this).find('img').attr('alt'),nth = $(this).parents('.d_cate').index(),des_left = $('.dock_child').eq(nth).width(); @@ -181,6 +183,45 @@ var orbitDesktop = function(dom){ $(this).removeClass('thmc1'); $fn_des.stop(true, true).fadeOut(); }); + + var split = function( val ) { + return val.split( /,\s*/ ); + } + var extractLast = function( term ) { + return split( term ).pop(); + } + var autocompleteListName = null; + $("body").on("keydown","*[autocomplete-list]", function( event ) { + autocompleteListName = $(this).attr("autocomplete-list"); + if ( event.keyCode === $.ui.keyCode.TAB && + $( this ).data( "autocomplete" ).menu.active ) { + event.preventDefault(); + } + $(this).autocomplete({ + minLength: 0, + source: function( request, response ) { + // delegate back to autocomplete, but extract the last term + response( $.ui.autocomplete.filter( + window.o[o.data_method][autocompleteListName], extractLast( request.term ) ) ); + }, + focus: function() { + // prevent value inserted on focus + return false; + }, + select: function( event, ui ) { + var terms = split( this.value ); + // remove the current input + terms.pop(); + // add the selected item + terms.push( ui.item.value ); + // add placeholder to get the comma-and-space at the end + terms.push( "" ); + this.value = terms.join( ", " ); + return false; + } + }) + }) + }; this.sub_menu_item = function(dom){ if(!dom.hasClass('active')){ diff --git a/app/assets/stylesheets/desktop.css b/app/assets/stylesheets/desktop.css index 226afb8f..48c2ee6a 100644 --- a/app/assets/stylesheets/desktop.css +++ b/app/assets/stylesheets/desktop.css @@ -6,6 +6,7 @@ *= require bootstrap *= require bootstrap-orbit *= require jquery.miniColors + *= require jquery-ui *= require font-awesome *= require desktopmain *= require desktopmedia diff --git a/app/views/desktop/journal_pages/_form.html.erb b/app/views/desktop/journal_pages/_form.html.erb index 334a6eee..af7b97bf 100644 --- a/app/views/desktop/journal_pages/_form.html.erb +++ b/app/views/desktop/journal_pages/_form.html.erb @@ -52,7 +52,7 @@ <%= f.text_area :paper_title, size: "20x2", placeholder: "Paper Title", class: "s_grid_6 s_grid"%>