1 /* ***************************************************************************
2 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 * ***************************************************************************
24 * jQuery Mobile Framework : "textinput" plugin for text inputs, textareas
25 * Copyright (c) jQuery Project
26 * Dual licensed under the MIT or GPL Version 2 licenses.
27 * http://jquery.org/license
28 * Authors: Jinhyuk Jun <jinhyuk.jun@samsung.com>
29 * Wongi Lee <wongi11.lee@samsung.com>
33 * Searchbar can be created using <input> element with type=search
34 * <input type="search" name="search" id="search1" value="" />
36 * Searchbar can be inserted 3 cases
37 * content : seachbar behave same as content element
38 * header : searchbar placed below title(header), It doesn't move when scrolling page
39 * inside optionheader : Searchbar placed inside optionheader, searchbar can be seen only expand optionheader
43 * HTML markup for creating Searchbar
44 * <input type="search"/>
46 * How to make searchbar in content
47 * <input type="search" name="" id="" value="" />
49 * How to make searchbar in title
50 * <div data-role="header" data-position ="fixed" >
52 * <input type="search" name="" id="" value="" />
55 * How to make searchbar inside optionheader
56 * <div data-role="header" data-position ="fixed" >
58 * <div id="myoptionheader2" data-role="optionheader">
59 * <input type="search" name="" id="" value="" />
64 (function ( $, undefined ) {
66 $.widget( "tizen.searchbar", $.mobile.widget, {
69 initSelector: "input[type='search'],:jqmData(type='search'), input[type='tizen-search'],:jqmData(type='tizen-search')"
72 _create: function () {
73 var input = this.element,
75 theme = o.theme || $.mobile.getInheritedTheme( this.element, "c" ),
76 themeclass = " ui-body-" + theme,
89 function toggleClear() {
90 setTimeout(function () {
91 clearbtn.toggleClass( "ui-input-clear-hidden", !input.val() );
95 function showCancel() {
97 .addClass( "ui-input-search-default" )
98 .removeClass( "ui-input-search-wide" );
100 .addClass( "ui-btn-cancel-show" )
101 .removeClass( "ui-btn-cancel-hide" );
104 function hideCancel() {
106 .addClass( "ui-input-search-wide" )
107 .removeClass( "ui-input-search-default" );
109 .addClass( "ui-btn-cancel-hide" )
110 .removeClass( "ui-btn-cancel-show" );
115 $( "label[for='" + input.attr( "id" ) + "']" ).addClass( "ui-input-text" );
117 focusedEl = input.addClass( "ui-input-text ui-body-" + theme );
119 // XXX: Temporary workaround for issue 785 (Apple bug 8910589).
120 // Turn off autocorrect and autocomplete on non-iOS 5 devices
121 // since the popup they use can't be dismissed by the user. Note
122 // that we test for the presence of the feature by looking for
123 // the autocorrect property on the input element. We currently
124 // have no test for iOS 5 or newer so we're temporarily using
125 // the touchOverflow support flag for jQM 1.0. Yes, I feel dirty. - jblas
126 if ( typeof input[0].autocorrect !== "undefined" && !$.support.touchOverflow ) {
127 // Set the attribute instead of the property just in case there
128 // is code that attempts to make modifications via HTML.
129 input[0].setAttribute( "autocorrect", "off" );
130 input[0].setAttribute( "autocomplete", "off" );
133 focusedEl = input.wrap( "<div class='ui-input-search ui-shadow-inset ui-corner-all ui-btn-shadow" + themeclass + "'></div>" ).parent();
134 clearbtn = $( "<a href='#' class='ui-input-clear' title='clear text'>clear text</a>" )
135 .bind('click', function ( event ) {
136 if ( input.attr( "disabled" ) == "disabled" ) {
142 .trigger( "change" );
143 clearbtn.addClass( "ui-input-clear-hidden" );
144 event.preventDefault();
146 .appendTo( focusedEl )
148 icon: "deleteSearch",
157 input.bind( 'paste cut keyup focus change blur', toggleClear );
159 //SLP --start search bar with cancel button
160 focusedEl.wrapAll( "<div class='input-search-bar'></div>" );
162 cancelbtn = $( "<a href='#' class='ui-input-cancel' title='clear text'>Cancel</a>" )
163 .bind('click', function ( event ) {
164 if ( input.attr( "disabled" ) == "disabled" ) {
167 event.preventDefault();
168 event.stopPropagation();
173 .trigger( "change" );
177 .appendTo( focusedEl.parent() )
184 searchimage = $("<div class='ui-image-search'></div>").appendTo( focusedEl );
188 .focus( function () {
189 if ( input.attr( "disabled" ) == "disabled" ) {
193 focusedEl.addClass( $.mobile.focusClass );
196 focusedEl.removeClass( $.mobile.focusClass );
200 defaultText = input.jqmData( "default-text" );
202 if ( ( defaultText != undefined ) && ( defaultText.length > 0 ) ) {
203 defaultTextClass = "ui-input-default-text";
204 trimedText = defaultText.replace(/\s/g, "");
206 /* Make new class for default text string */
207 newClassName = defaultTextClass + "-" + trimedText;
208 newStyle = $( "<style>" + '.' + newClassName + ":after" + "{content:" + "'" + defaultText + "'" + "}" + "</style>" );
209 $( 'html > head' ).append( newStyle );
211 /* Make new empty <DIV> for default text */
212 newDiv = $( "<div></div>" );
214 /* Add class and append new div */
215 newDiv.addClass( defaultTextClass );
216 newDiv.addClass( newClassName );
217 newDiv.tap( function ( event ) {
222 input.parent().append( newDiv );
224 /* When focus, default text will be hide. */
226 .focus( function () {
227 input.parent().find( "div.ui-input-default-text" ).addClass( "ui-input-default-hidden" );
230 var inputedText = input.val();
231 if ( inputedText.length > 0 ) {
232 input.parent().find( "div.ui-input-default-text" ).addClass( "ui-input-default-hidden" );
234 input.parent().find( "div.ui-input-default-text" ).removeClass( "ui-input-default-hidden" );
239 if ( !input.attr("placeholder") ) {
240 input.attr( "placeholder", "Search" );
244 disable: function () {
245 this.element.attr( "disabled", true );
246 this.element.parent().addClass( "ui-disabled" );
247 this.element.parent().parent().find(".ui-input-cancel").addClass( "ui-disabled" );
248 $( this.element ).blur();
251 enable: function () {
252 this.element.attr( "disabled", false );
253 this.element.parent().removeClass( "ui-disabled" );
254 this.element.parent().parent().find(".ui-input-cancel").removeClass( "ui-disabled" );
255 $( this.element ).focus();
259 //auto self-init widgets
260 $( document ).bind( "pagecreate create", function ( e ) {
261 $.tizen.searchbar.prototype.enhanceWithin( e.target );