2 /* ***************************************************************************
3 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 * ***************************************************************************
25 * jQuery Mobile Framework : "textinput" plugin for text inputs, textareas
26 * Copyright (c) jQuery Project
27 * Dual licensed under the MIT or GPL Version 2 licenses.
28 * http://jquery.org/license
29 * Authors: Jinhyuk Jun <jinhyuk.jun@samsung.com>
30 * Wongi Lee <wongi11.lee@samsung.com>
34 * Searchbar can be created using <input> element with type=search
35 * <input type="search" name="search" id="search1" value="" />
37 * Searchbar can be inserted 3 cases
38 * content : seachbar behave same as content element
39 * header : searchbar placed below title(header), It doesn't move when scrolling page
40 * inside optionheader : Searchbar placed inside optionheader, searchbar can be seen only expand optionheader
44 * HTML markup for creating Searchbar
45 * <input type="search"/>
47 * How to make searchbar in content
48 * <input type="search" name="" id="" value="" />
50 * How to make cancel button in searchbar
51 * <div data-role="header" data-position ="fixed" >
53 * <input type="search" data-cancel-btn=true name="" id="" value="" />
56 * How to make icon in front of searchbar
57 * <div data-role="header" data-position ="fixed" >
59 * <input type="search" data-icon="call" name="" id="" value="" />
65 The search bar widget is used to search for page content. This widget can be placed in the header, option header, or page content.
67 To add a search bar widget to the application, use the following code:
69 <label for="search-basic">Search Input:</label>
70 <input type="search" name="search" id="searc-basic" value="" data-mini="true" />
72 Tizen supports many search bar options as described in the jQueryMobile documentation for search bar options.
73 The search bar can define callbacks for events as described in the jQueryMobile documentation for search bar events.
74 You can use methods with the search bar as described in the jQueryMobile documentation for search bar methods.
77 (function ( $, undefined ) {
79 $.widget( "tizen.searchbar", $.mobile.widget, {
82 initSelector: "input[type='search'],:jqmData(type='search'), input[type='tizen-search'],:jqmData(type='tizen-search')"
85 _create: function () {
86 var input = this.element,
88 theme = o.theme || $.mobile.getInheritedTheme( this.element, "c" ),
89 themeclass = " ui-body-" + theme,
101 useCancelBtn = false,
104 $( "label[for='" + input.attr( "id" ) + "']" ).addClass( "ui-input-text" );
106 if ( typeof input[0].autocorrect !== "undefined" && !$.support.touchOverflow ) {
107 // Set the attribute instead of the property just in case there
108 // is code that attempts to make modifications via HTML.
109 input[0].setAttribute( "autocorrect", "off" );
110 input[0].setAttribute( "autocomplete", "off" );
113 focusedEl = input.wrap( "<div class='ui-input-search ui-shadow-inset ui-corner-all ui-btn-shadow" + themeclass + "'></div>" ).parent();
115 if ( $( this.element ).data( "cancel-btn" ) === true ) {
117 focusedEl.addClass( "ui-input-search-default" );
119 if ( $( this.element ).data( "icon" ) != undefined ) {
121 focusedEl.addClass( "ui-search-bar-icon" );
124 clearbtn = $( "<a href='#' class='ui-input-clear' title='clear text'>clear text</a>" )
125 .bind('click', function ( event ) {
126 if ( input.attr( "disabled" ) == "disabled" ) {
132 .trigger( "change" );
133 clearbtn.addClass( "ui-input-clear-hidden" );
134 event.preventDefault();
136 .appendTo( focusedEl )
138 icon: "deleteSearch",
144 function toggleClear() {
145 setTimeout(function () {
146 clearbtn.toggleClass( "ui-input-clear-hidden", !input.val() );
150 function showCancel() {
152 .addClass( "ui-input-search-default" )
153 .removeClass( "ui-input-search-wide" );
155 .addClass( "ui-btn-cancel-show" )
156 .removeClass( "ui-btn-cancel-hide" );
159 function hideCancel() {
161 .addClass( "ui-input-search-wide" )
162 .removeClass( "ui-input-search-default" );
164 .addClass( "ui-btn-cancel-hide" )
165 .removeClass( "ui-btn-cancel-show" );
169 function makeFrontIcon() {
170 var IconStyle = $( input ).jqmData( "icon" ),
171 frontIcon = $( "<div data-role='button' data-style='circle'></div>" );
174 .appendTo( focusedEl.parent() )
181 frontIcon.addClass( "ui-btn-search-front-icon" );
186 input.bind( 'paste cut keyup focus change blur', toggleClear );
188 //SLP --start search bar with cancel button
189 focusedEl.wrapAll( "<div class='input-search-bar'></div>" );
190 searchimage = $("<div class='ui-image-search'></div>").appendTo( focusedEl );
196 if ( useCancelBtn ) {
197 cancelbtn = $( "<div data-role='button' class='ui-input-cancel' title='clear text'>Cancel</div>" )
198 .bind('click', function ( event ) {
199 if ( input.attr( "disabled" ) == "disabled" ) {
202 event.preventDefault();
203 event.stopPropagation();
208 .trigger( "change" );
210 if ( useCancelBtn ) {
214 .appendTo( focusedEl.parent() )
224 .focus( function () {
225 if ( input.attr( "disabled" ) == "disabled" ) {
228 if ( useCancelBtn ) {
231 focusedEl.addClass( $.mobile.focusClass );
234 focusedEl.removeClass( $.mobile.focusClass );
238 defaultText = input.jqmData( "default-text" );
240 if ( ( defaultText != undefined ) && ( defaultText.length > 0 ) ) {
241 defaultTextClass = "ui-input-default-text";
242 trimedText = defaultText.replace(/\s/g, "");
244 /* Make new class for default text string */
245 newClassName = defaultTextClass + "-" + trimedText;
246 newStyle = $( "<style>" + '.' + newClassName + ":after" + "{content:" + "'" + defaultText + "'" + "}" + "</style>" );
247 $( 'html > head' ).append( newStyle );
249 /* Make new empty <DIV> for default text */
250 newDiv = $( "<div></div>" );
252 /* Add class and append new div */
253 newDiv.addClass( defaultTextClass );
254 newDiv.addClass( newClassName );
255 newDiv.tap( function ( event ) {
260 input.parent().append( newDiv );
262 /* When focus, default text will be hide. */
264 .focus( function () {
265 input.parent().find( "div.ui-input-default-text" ).addClass( "ui-input-default-hidden" );
268 var inputedText = input.val();
269 if ( inputedText.length > 0 ) {
270 input.parent().find( "div.ui-input-default-text" ).addClass( "ui-input-default-hidden" );
272 input.parent().find( "div.ui-input-default-text" ).removeClass( "ui-input-default-hidden" );
277 if ( !input.attr("placeholder") ) {
278 input.attr( "placeholder", "Search" );
282 disable: function () {
283 this.element.attr( "disabled", true );
284 this.element.parent().addClass( "ui-disabled" );
285 $( this.element ).blur();
286 this.element.parent().parent().find(".ui-input-cancel").addClass( "ui-disabled" );
289 enable: function () {
290 this.element.attr( "disabled", false );
291 this.element.parent().removeClass( "ui-disabled" );
292 this.element.parent().parent().find(".ui-input-cancel").removeClass( "ui-disabled" );
293 $( this.element ).focus();
297 //auto self-init widgets
298 $( document ).bind( "pagecreate create", function ( e ) {
299 $.tizen.searchbar.prototype.enhanceWithin( e.target );