tests and implementation of the search button for the player. popcorn-port
authorhamidouk
Tue, 25 Oct 2011 17:30:16 +0200
branchpopcorn-port
changeset 145 b477c9430d36
parent 144 5e26770c77f6
child 146 b99527037c89
tests and implementation of the search button for the player.
src/js/widgets/playerWidget.js
unittests/tests/playerWidget.js
--- a/src/js/widgets/playerWidget.js	Tue Oct 25 17:29:57 2011 +0200
+++ b/src/js/widgets/playerWidget.js	Tue Oct 25 17:30:16 2011 +0200
@@ -1,5 +1,8 @@
 IriSP.PlayerWidget = function(Popcorn, config, Serializer) {
   IriSP.Widget.call(this, Popcorn, config, Serializer);
+  
+  this._searchBlockOpen = false;
+  this._searchLastValue = "";
 };
 
 IriSP.PlayerWidget.prototype = new IriSP.Widget();
@@ -9,7 +12,10 @@
   var width = this.width;
 	var height = this.height;
 	var heightS = this.height-20;
-		
+	
+  var searchBox = Mustache.to_html(IriSP.search_template);
+  this.selector.append(searchBox);
+  
 	if (this._config.mode=="radio") {
 
 		//IriSP.jQuery( "#"+this._config.container ).before(IriSP.search_template);
@@ -88,7 +94,8 @@
       //secondary: 'ui-icon-volume-off'
     },
     text: false
-  }).next().button({
+  }).click(function() { _this.searchButtonHandler.call(_this); })
+    .next().button({
     icons: {
       primary: 'ui-icon-volume-on'
     },
@@ -130,8 +137,45 @@
     }
 };
 
+/* updates the slider as time passes */
 IriSP.PlayerWidget.prototype.sliderUpdater = function() {  
   var currentPosition = this._Popcorn.currentTime();   
 	this.selector.find( "#slider-range-min" ).slider( "value", currentPosition);		
 };
 
+IriSP.PlayerWidget.prototype.searchButtonHandler = function() {
+    var self = this;
+
+    /* 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._searchBlockOpen = true;           
+      this.selector.find("#LdtSearchInput").bind('keypress set', null, function() { self.searchHandler.call(self); } );
+      
+	} else {
+      this._searchLastValue = this.selector.find("#LdtSearchInput").attr('value');
+      this.selector.find("#LdtSearchInput").attr('value','');
+      //IriSP.SearchClean();
+      this.selector.find(".ui-icon-search").css("background-position","-160px -112px");
+      //__IriSP.jQuery("#LdtSearch").animate({height:0},250);
+      this.selector.find("#LdtSearch").hide(100);
+      
+      // unbind the watcher event.
+      this.selector.find("#LdtSearchInput").unbind('keypress set');
+      this._searchBlockOpen = false;
+  }
+};
+
+/* 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
--- a/unittests/tests/playerWidget.js	Tue Oct 25 17:29:57 2011 +0200
+++ b/unittests/tests/playerWidget.js	Tue Oct 25 17:30:16 2011 +0200
@@ -73,7 +73,7 @@
     
     IriSP.jQuery("#ldt-CtrlSound").trigger("click");
     ok(!this.Popcorn.muted(), "the player is un muted");         
-    ok(spy_handler.called, "handling function has been called twice");                                                                                                                                        
+    ok(spy_handler.called, "handling function has been called");                                                                                                                                        
   });
 
   test("test slider seeking", function() {    
@@ -90,4 +90,24 @@
   ok(true, "WARNING : slider is not tested");
   });
   
-  };
\ No newline at end of file
+  test("test search button event handler", function() {
+  var player = new IriSP.PlayerWidget(this.Popcorn, this.config, this.ser);
+  
+  var searchTerm = "blah";
+  
+  var spy_callback = this.spy();
+  var spy_handler = sinon.spy(player, "searchButtonHandler");
+  player._Popcorn.listen("IriSP.search", spy_callback);    
+  
+  player.draw();
+     
+  IriSP.jQuery("#ldt-CtrlSearch").trigger("click");
+  IriSP.jQuery("#LdtSearchInput").attr('value', searchTerm); 
+  IriSP.jQuery("#LdtSearchInput").trigger('keypress');
+  
+  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");                                                                                                                                        
+  
+  });
+};
\ No newline at end of file