# HG changeset patch # User hamidouk # Date 1319635172 -7200 # Node ID dc2ff4c874903854c75ec18656edd9d16347ff88 # Parent 40cf046b7049bce9de75d0a53e6aa3b8b606b745 some tweaking to make the search function more user-friendly. diff -r 40cf046b7049 -r dc2ff4c87490 src/js/widgets/playerWidget.js --- a/src/js/widgets/playerWidget.js Wed Oct 26 15:19:13 2011 +0200 +++ b/src/js/widgets/playerWidget.js Wed Oct 26 15:19:32 2011 +0200 @@ -149,15 +149,19 @@ /* show the search field if it is not shown */ if ( this._searchBlockOpen == false ) { this.selector.find( ".ui-icon-search" ).css( "background-position", "-144px -112px" ); - //__IriSP.jQuery("#LdtSearch").animate({height:26},250); this.selector.find("#LdtSearch").show(100); this.selector.find("#LdtSearchInput").css('background-color','#fff'); this.selector.find("#LdtSearchInput").focus(); - this.selector.find("#LdtSearchInput").attr('value', this._searchLastValue); + this.selector.find("#LdtSearchInput").attr('value', this._searchLastValue); + this._Popcorn.trigger("IriSP.search", this._searchLastValue); // trigger the search to make it more natural. + this._searchBlockOpen = true; - this.selector.find("#LdtSearchInput").bind('keypress set', null, function() { self.searchHandler.call(self); } ); + this.selector.find("#LdtSearchInput").bind('keyup', null, function() { self.searchHandler.call(self); } ); + + // tell the world the field is open + this._Popcorn.trigger("IriSP.search.open"); } else { this._searchLastValue = this.selector.find("#LdtSearchInput").attr('value'); @@ -170,12 +174,29 @@ // unbind the watcher event. this.selector.find("#LdtSearchInput").unbind('keypress set'); this._searchBlockOpen = false; + + this._Popcorn.trigger("IriSP.search.closed"); } }; /* this handler is called whenever the content of the search field changes */ IriSP.PlayerWidget.prototype.searchHandler = function() { + this._searchLastValue = this.selector.find("#LdtSearchInput").attr('value'); this._Popcorn.trigger("IriSP.search", this._searchLastValue); -}; \ No newline at end of file +}; + +/* + handler for the IriSP.search.found message, which is sent by some views when they + highlight a match. +*/ +IriSP.PlayerWidget.prototype.searchMatch = function() { + this.selector.find("#LdtSearchInput").css('background-color','#e1ffe1'); +} + +/* the same, except that no value could be found */ +IriSP.PlayerWidget.prototype.searchNoMatch = function() { + this.selector.find("#LdtSearchInput").css('background-color','#e1ffe1'); +} + diff -r 40cf046b7049 -r dc2ff4c87490 unittests/tests/playerWidget.js --- a/unittests/tests/playerWidget.js Wed Oct 26 15:19:13 2011 +0200 +++ b/unittests/tests/playerWidget.js Wed Oct 26 15:19:32 2011 +0200 @@ -96,18 +96,27 @@ var searchTerm = "blah"; var spy_callback = this.spy(); + var spy_open = this.spy(); + var spy_closed = this.spy(); var spy_handler = sinon.spy(player, "searchButtonHandler"); + player._Popcorn.listen("IriSP.search", spy_callback); + player._Popcorn.listen("IriSP.search.open", spy_open); + player._Popcorn.listen("IriSP.search.closed", spy_closed); player.draw(); - IriSP.jQuery("#ldt-CtrlSearch").trigger("click"); - IriSP.jQuery("#LdtSearchInput").attr('value', searchTerm); - IriSP.jQuery("#LdtSearchInput").trigger('keypress'); + player.selector.find("#ldt-CtrlSearch").trigger("click"); + player.selector.find("#LdtSearchInput").attr('value', searchTerm); + player.selector.find("#LdtSearchInput").trigger('keyup'); ok(spy_handler.called, "search button handling function has been called"); - ok(spy_callback.called, "search typeahead function has been called"); - ok(spy_callback.calledWith(searchTerm), "popcorn message sent with the right parameters"); + ok(spy_open.called, "open signal has been sent"); + ok(spy_callback.called, "search typeahead function has been called"); + ok(spy_callback.calledWith(searchTerm), "popcorn message sent with the right parameters"); + + player.selector.find("#ldt-CtrlSearch").trigger("click"); + ok(spy_closed.called, "closed signal has been sent"); }); }; \ No newline at end of file