1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Shows searchbar, for text search
4 //>>group: Tizen:Widgets
6 define( [ '../jquery.mobile.tizen.core', 'jquery.mobile.tizen.pagelayout' ], function ( ) {
7 //>>excludeEnd("jqmBuildExclude");
9 /* ***************************************************************************
10 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
29 * ***************************************************************************
32 * jQuery Mobile Framework : "textinput" plugin for text inputs, textareas
33 * Copyright (c) jQuery Project
34 * Dual licensed under the MIT or GPL Version 2 licenses.
35 * http://jquery.org/license
36 * Authors: Jinhyuk Jun <jinhyuk.jun@samsung.com>
37 * Wongi Lee <wongi11.lee@samsung.com>
41 * Searchbar can be created using <input> element with type=search
42 * <input type="search" name="search" id="search1" value="" />
44 * Searchbar can be inserted 3 cases
45 * content : seachbar behave same as content element
46 * header : searchbar placed below title(header), It doesn't move when scrolling page
47 * inside optionheader : Searchbar placed inside optionheader, searchbar can be seen only expand optionheader
51 * HTML markup for creating Searchbar
52 * <input type="search"/>
54 * How to make searchbar in content
55 * <input type="search" name="" id="" value="" />
57 * How to make cancel button in searchbar
58 * <div data-role="header" data-position ="fixed" >
60 * <input type="search" data-cancel-btn=true name="" id="" value="" />
63 * How to make icon in front of searchbar
64 * <div data-role="header" data-position ="fixed" >
66 * <input type="search" data-icon="call" name="" id="" value="" />
72 The search bar widget is used to search for page content. This widget can be placed in the header, option header, or page content.
74 To add a search bar widget to the application, use the following code:
76 <label for="search-basic">Search Input:</label>
77 <input type="search" name="search" id="searc-basic" value="" data-mini="true" />
79 Tizen supports many search bar options as described in the jQueryMobile documentation for search bar options.
80 The search bar can define callbacks for events as described in the jQueryMobile documentation for search bar events.
81 You can use methods with the search bar as described in the jQueryMobile documentation for search bar methods.
84 (function ( $, undefined ) {
86 $.widget( "tizen.searchbar", $.mobile.widget, {
89 initSelector: "input[type='search'],:jqmData(type='search'), input[type='tizen-search'],:jqmData(type='tizen-search')"
92 _create: function () {
93 var input = this.element,
95 theme = o.theme || $.mobile.getInheritedTheme( this.element, "c" ),
96 themeclass = " ui-body-" + theme,
108 useCancelBtn = false,
111 $( "label[for='" + input.attr( "id" ) + "']" ).addClass( "ui-input-text" );
113 if ( typeof input[0].autocorrect !== "undefined" && !$.support.touchOverflow ) {
114 // Set the attribute instead of the property just in case there
115 // is code that attempts to make modifications via HTML.
116 input[0].setAttribute( "autocorrect", "off" );
117 input[0].setAttribute( "autocomplete", "off" );
120 focusedEl = input.wrap( "<div class='ui-input-search ui-shadow-inset ui-corner-all ui-btn-shadow" + themeclass + "'></div>" ).parent();
122 if ( $( this.element ).data( "cancel-btn" ) === true ) {
124 focusedEl.addClass( "ui-input-search-default" );
126 if ( $( this.element ).data( "icon" ) != undefined ) {
128 focusedEl.addClass( "ui-search-bar-icon" );
131 clearbtn = $( "<a href='#' class='ui-input-clear' title='clear text'>clear text</a>" )
132 .bind('click', function ( event ) {
133 if ( input.attr( "disabled" ) == "disabled" ) {
139 .trigger( "change" );
140 clearbtn.addClass( "ui-input-clear-hidden" );
141 event.preventDefault();
143 .appendTo( focusedEl )
145 icon: "deleteSearch",
151 function toggleClear() {
152 setTimeout(function () {
153 clearbtn.toggleClass( "ui-input-clear-hidden", !input.val() );
157 function showCancel() {
159 .addClass( "ui-input-search-default" )
160 .removeClass( "ui-input-search-wide" );
162 .addClass( "ui-btn-cancel-show" )
163 .removeClass( "ui-btn-cancel-hide" );
166 function hideCancel() {
168 .addClass( "ui-input-search-wide" )
169 .removeClass( "ui-input-search-default" );
171 .addClass( "ui-btn-cancel-hide" )
172 .removeClass( "ui-btn-cancel-show" );
176 function makeFrontIcon() {
177 var IconStyle = $( input ).jqmData( "icon" ),
178 frontIcon = $( "<div data-role='button' data-style='circle'></div>" );
181 .appendTo( focusedEl.parent() )
188 frontIcon.addClass( "ui-btn-search-front-icon" );
193 input.bind( 'paste cut keyup focus change blur', toggleClear );
195 //SLP --start search bar with cancel button
196 focusedEl.wrapAll( "<div class='input-search-bar'></div>" );
197 searchimage = $("<div class='ui-image-search'></div>").appendTo( focusedEl );
203 if ( useCancelBtn ) {
204 cancelbtn = $( "<div data-role='button' class='ui-input-cancel' title='clear text'>Cancel</div>" )
205 .bind('click', function ( event ) {
206 if ( input.attr( "disabled" ) == "disabled" ) {
209 event.preventDefault();
210 event.stopPropagation();
215 .trigger( "change" );
217 if ( useCancelBtn ) {
221 .appendTo( focusedEl.parent() )
231 .focus( function () {
232 if ( input.attr( "disabled" ) == "disabled" ) {
235 if ( useCancelBtn ) {
238 focusedEl.addClass( $.mobile.focusClass );
241 focusedEl.removeClass( $.mobile.focusClass );
245 defaultText = input.jqmData( "default-text" );
247 if ( ( defaultText != undefined ) && ( defaultText.length > 0 ) ) {
248 defaultTextClass = "ui-input-default-text";
249 trimedText = defaultText.replace(/\s/g, "");
251 /* Make new class for default text string */
252 newClassName = defaultTextClass + "-" + trimedText;
253 newStyle = $( "<style>" + '.' + newClassName + ":after" + "{content:" + "'" + defaultText + "'" + "}" + "</style>" );
254 $( 'html > head' ).append( newStyle );
256 /* Make new empty <DIV> for default text */
257 newDiv = $( "<div></div>" );
259 /* Add class and append new div */
260 newDiv.addClass( defaultTextClass );
261 newDiv.addClass( newClassName );
262 newDiv.tap( function ( event ) {
267 input.parent().append( newDiv );
269 /* When focus, default text will be hide. */
271 .focus( function () {
272 input.parent().find( "div.ui-input-default-text" ).addClass( "ui-input-default-hidden" );
275 var inputedText = input.val();
276 if ( inputedText.length > 0 ) {
277 input.parent().find( "div.ui-input-default-text" ).addClass( "ui-input-default-hidden" );
279 input.parent().find( "div.ui-input-default-text" ).removeClass( "ui-input-default-hidden" );
284 if ( !input.attr("placeholder") ) {
285 input.attr( "placeholder", "Search" );
289 disable: function () {
290 this.element.attr( "disabled", true );
291 this.element.parent().addClass( "ui-disabled" );
292 $( this.element ).blur();
293 this.element.parent().parent().find(".ui-input-cancel").addClass( "ui-disabled" );
296 enable: function () {
297 this.element.attr( "disabled", false );
298 this.element.parent().removeClass( "ui-disabled" );
299 this.element.parent().parent().find(".ui-input-cancel").removeClass( "ui-disabled" );
300 $( this.element ).focus();
304 //auto self-init widgets
305 $( document ).bind( "pagecreate create", function ( e ) {
306 $.tizen.searchbar.prototype.enhanceWithin( e.target );
311 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
313 //>>excludeEnd("jqmBuildExclude");