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" );
105 function hideCancel() {
107 .addClass( "ui-input-search-wide" )
108 .removeClass( "ui-input-search-default" );
110 .addClass( "ui-btn-cancel-hide" )
111 .removeClass( "ui-btn-cancel-show" );
113 if ( input.val() == "" ) {
120 $( "label[for='" + input.attr( "id" ) + "']" ).addClass( "ui-input-text" );
122 focusedEl = input.addClass( "ui-input-text ui-body-" + theme );
124 // XXX: Temporary workaround for issue 785 (Apple bug 8910589).
125 // Turn off autocorrect and autocomplete on non-iOS 5 devices
126 // since the popup they use can't be dismissed by the user. Note
127 // that we test for the presence of the feature by looking for
128 // the autocorrect property on the input element. We currently
129 // have no test for iOS 5 or newer so we're temporarily using
130 // the touchOverflow support flag for jQM 1.0. Yes, I feel dirty. - jblas
131 if ( typeof input[0].autocorrect !== "undefined" && !$.support.touchOverflow ) {
132 // Set the attribute instead of the property just in case there
133 // is code that attempts to make modifications via HTML.
134 input[0].setAttribute( "autocorrect", "off" );
135 input[0].setAttribute( "autocomplete", "off" );
138 focusedEl = input.wrap( "<div class='ui-input-search ui-shadow-inset ui-corner-all ui-btn-shadow" + themeclass + "'></div>" ).parent();
139 clearbtn = $( "<a href='#' class='ui-input-clear' title='clear text'>clear text</a>" )
140 .bind('click', function ( event ) {
141 if ( input.attr( "disabled" ) == "disabled" ) {
147 .trigger( "change" );
148 clearbtn.addClass( "ui-input-clear-hidden" );
149 event.preventDefault();
151 .appendTo( focusedEl )
153 icon: "deleteSearch",
162 input.bind( 'paste cut keyup focus change blur', toggleClear );
164 //SLP --start search bar with cancel button
165 focusedEl.wrapAll( "<div class='input-search-bar'></div>" );
167 searchicon = $("<div class='ui-image-search ui-image-searchfield'></div>")
168 .bind('click', function ( event ) {
169 if ( input.attr( "disabled" ) == "disabled" ) {
178 .appendTo( focusedEl );
180 cancelbtn = $( "<a href='#' class='ui-input-cancel' title='clear text'>Cancel</a>" )
181 .bind('click', function ( event ) {
182 if ( input.attr( "disabled" ) == "disabled" ) {
185 event.preventDefault();
186 event.stopPropagation();
191 .trigger( "change" );
195 .appendTo( focusedEl.parent() )
204 .focus( function () {
205 if ( input.attr( "disabled" ) == "disabled" ) {
209 focusedEl.addClass( $.mobile.focusClass );
212 focusedEl.removeClass( $.mobile.focusClass );
216 /* When user touch on page, it's same to blur */
217 /* FIXME : if there is no problem, please remove this codes..
218 $( "div.input-search-bar" ).tap( function ( event ) {
219 if ( input.attr( "disabled" ) == "disabled" ) {
223 event.stopPropagation();
226 var currentPage = input.closest( ".ui-page" );
227 $( currentPage ).bind("tap", function ( e ) {
228 if ( input.attr( "disabled" ) == "disabled" ) {
232 if ( $( input ).is( ":focus" ) ) {
233 focusedEl.removeClass( "ui-focus" );
240 defaultText = input.jqmData( "default-text" );
242 if ( ( defaultText != undefined ) && ( defaultText.length > 0 ) ) {
243 defaultTextClass = "ui-input-default-text";
244 trimedText = defaultText.replace(/\s/g, "");
246 /* Make new class for default text string */
247 newClassName = defaultTextClass + "-" + trimedText;
248 newStyle = $( "<style>" + '.' + newClassName + ":after" + "{content:" + "'" + defaultText + "'" + "}" + "</style>" );
249 $( 'html > head' ).append( newStyle );
251 /* Make new empty <DIV> for default text */
252 newDiv = $( "<div></div>" );
254 /* Add class and append new div */
255 newDiv.addClass( defaultTextClass );
256 newDiv.addClass( newClassName );
257 newDiv.tap( function ( event ) {
262 input.parent().append( newDiv );
264 /* When focus, default text will be hide. */
266 .focus( function () {
267 input.parent().find( "div.ui-input-default-text" ).addClass( "ui-input-default-hidden" );
270 var inputedText = input.val();
271 if ( inputedText.length > 0 ) {
272 input.parent().find( "div.ui-input-default-text" ).addClass( "ui-input-default-hidden" );
274 input.parent().find( "div.ui-input-default-text" ).removeClass( "ui-input-default-hidden" );
284 disable: function () {
285 this.element.attr( "disabled", true );
286 this.element.parent().addClass( "ui-disabled" );
287 this.element.parent().parent().find(".ui-input-cancel").addClass( "ui-disabled" );
288 $( this.element ).blur();
291 enable: function () {
292 this.element.attr( "disabled", false );
293 this.element.parent().removeClass( "ui-disabled" );
294 this.element.parent().parent().find(".ui-input-cancel").removeClass( "ui-disabled" );
295 $( this.element ).focus();
299 //auto self-init widgets
300 $( document ).bind( "pagecreate create", function ( e ) {
301 $.tizen.searchbar.prototype.enhanceWithin( e.target );