Index: trunk/phase3/resources/jquery/jquery.placeholder.js |
— | — | @@ -0,0 +1,48 @@ |
| 2 | +/** |
| 3 | + * HTML5 placeholder emulation for jQuery plugin |
| 4 | + * |
| 5 | + * This will automatically use the HTML5 placeholder attribute if supported, or emulate this behavior if not. |
| 6 | + * |
| 7 | + * @author Trevor Parscal <tparscal@wikimedia.org> |
| 8 | + * @version 0.1.0 |
| 9 | + * @license GPL v2 |
| 10 | + */ |
| 11 | + |
| 12 | +jQuery.fn.placeholder = function( text ) { |
| 13 | + // If the HTML5 placeholder attribute is supported, use it |
| 14 | + if ( 'placeholder' in document.createElement( 'input' ) ) { |
| 15 | + jQuery(this).attr( 'placeholder', text ); |
| 16 | + } |
| 17 | + // Otherwise, use a combination of blur and focus event handlers and a placeholder class |
| 18 | + else { |
| 19 | + jQuery(this).each( function() { |
| 20 | + $input = jQuery(this); |
| 21 | + $input |
| 22 | + // Show on blur if empty |
| 23 | + .bind( 'blur', function() { |
| 24 | + if ( $input.val().length == 0 ) { |
| 25 | + $input |
| 26 | + .val( text ) |
| 27 | + .addClass( 'placeholder' ); |
| 28 | + } |
| 29 | + } ) |
| 30 | + // Hide on focus |
| 31 | + .bind( 'focus', function() { |
| 32 | + if ( $input.hasClass( 'placeholder' ) ) { |
| 33 | + $input |
| 34 | + .val( '' ) |
| 35 | + .removeClass( 'placeholder' ); |
| 36 | + } |
| 37 | + } ) |
| 38 | + // Blank on submit -- prevents submitting with unintended value |
| 39 | + .parents( 'form' ) |
| 40 | + .bind( 'submit', function() { |
| 41 | + $input.trigger( 'focus' ); |
| 42 | + } ); |
| 43 | + // Show initially, if empty |
| 44 | + if ( $input.val() == '' ) { |
| 45 | + $input.trigger( 'blur' ); |
| 46 | + } |
| 47 | + } ); |
| 48 | + } |
| 49 | +}; |
Property changes on: trunk/phase3/resources/jquery/jquery.placeholder.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 50 | + native |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -48,6 +48,9 @@ |
49 | 49 | 'jquery.highlightText' => new ResourceLoaderFileModule( |
50 | 50 | array( 'scripts' => 'resources/jquery/jquery.highlightText.js' ) |
51 | 51 | ), |
| 52 | + 'jquery.placeholder' => new ResourceLoaderFileModule( |
| 53 | + array( 'scripts' => 'resources/jquery/jquery.placeholder.js' ) |
| 54 | + ), |
52 | 55 | 'jquery.suggestions' => new ResourceLoaderFileModule( |
53 | 56 | array( |
54 | 57 | 'scripts' => 'resources/jquery/jquery.suggestions.js', |
Index: trunk/extensions/Vector/modules/ext.vector.simpleSearch.js |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | /* JavaScript for SimpleSearch extension */ |
3 | 3 | |
4 | | -// Disable mwsuggest.js's effect on searchInput |
| 4 | +// XXX: Disable mwsuggest.js's effect on searchInput |
5 | 5 | if ( typeof os_autoload_inputs !== 'undefined' && os_autoload_forms !== 'undefined' ) { |
6 | 6 | os_autoload_inputs = []; |
7 | 7 | os_autoload_forms = []; |
— | — | @@ -8,6 +8,7 @@ |
9 | 9 | |
10 | 10 | $( document ).ready( function() { |
11 | 11 | |
| 12 | + // Compatibility map |
12 | 13 | var map = { |
13 | 14 | 'browsers': { |
14 | 15 | // Left-to-right languages |
— | — | @@ -33,81 +34,56 @@ |
34 | 35 | return true; |
35 | 36 | } |
36 | 37 | |
37 | | - // Placeholder text |
38 | | - // if the placeholder attribute is supported, use it |
39 | | - if ( 'placeholder' in document.createElement( 'input' ) ) { |
40 | | - $( 'div#simpleSearch > input#searchInput' ) |
41 | | - .attr( 'placeholder', mediaWiki.msg.get( 'vector-simplesearch-search' ) ); |
42 | | - } else { |
43 | | - $( 'div#simpleSearch > input#searchInput' ) |
44 | | - .each( function() { |
45 | | - var $input = $( this ); |
46 | | - $input |
47 | | - .bind( 'blur', function() { |
48 | | - if ( $input.val().length == 0 ) { |
49 | | - $input |
50 | | - .val( mediaWiki.msg.get( 'vector-simplesearch-search' ) ) |
51 | | - .addClass( 'placeholder' ); |
52 | | - } |
53 | | - } ) |
54 | | - .bind( 'focus', function() { |
55 | | - if ( $input.hasClass( 'placeholder' ) ) { |
56 | | - $input.val( '' ).removeClass( 'placeholder' ); |
57 | | - } |
58 | | - } ) |
59 | | - .parents( 'form' ) |
60 | | - .bind( 'submit', function() { |
61 | | - $input.trigger( 'focus' ); |
62 | | - } ); |
63 | | - if ( $input.val() == '' ) { |
64 | | - $input.trigger( 'blur' ); |
| 38 | + // Placeholder text for SimpleSearch box |
| 39 | + $( 'div#simpleSearch > input#searchInput' ).placeholder( mediaWiki.msg.get( 'vector-simplesearch-search' ) ); |
| 40 | + |
| 41 | + // General suggestions functionality for all search boxes |
| 42 | + $( '#searchInput, #searchInput2, #powerSearchText, #searchText' ) |
| 43 | + .suggestions( { |
| 44 | + fetch: function( query ) { |
| 45 | + var $this = $(this); |
| 46 | + var request = $.ajax( { |
| 47 | + url: wgScriptPath + '/api.php', |
| 48 | + data: { |
| 49 | + 'action': 'opensearch', |
| 50 | + 'search': query, |
| 51 | + 'namespace': 0, |
| 52 | + 'suggest': '' |
| 53 | + }, |
| 54 | + dataType: 'json', |
| 55 | + success: function( data ) { |
| 56 | + $this.suggestions( 'suggestions', data[1] ); |
| 57 | + } |
| 58 | + }); |
| 59 | + $(this).data( 'request', request ); |
| 60 | + }, |
| 61 | + cancel: function () { |
| 62 | + var request = $(this).data( 'request' ); |
| 63 | + // If the delay setting has caused the fetch to have not even happend yet, the request object will |
| 64 | + // have never been set |
| 65 | + if ( request && typeof request.abort == 'function' ) { |
| 66 | + request.abort(); |
| 67 | + $(this).removeData( 'request' ); |
65 | 68 | } |
66 | | - } ); |
67 | | - } |
68 | | - $( '#searchInput, #searchInput2, #powerSearchText, #searchText' ).suggestions( { |
69 | | - fetch: function( query ) { |
70 | | - var $this = $(this); |
71 | | - var request = $.ajax( { |
72 | | - url: wgScriptPath + '/api.php', |
73 | | - data: { |
74 | | - 'action': 'opensearch', |
75 | | - 'search': query, |
76 | | - 'namespace': 0, |
77 | | - 'suggest': '' |
78 | | - }, |
79 | | - dataType: 'json', |
80 | | - success: function( data ) { |
81 | | - $this.suggestions( 'suggestions', data[1] ); |
| 69 | + }, |
| 70 | + result: { |
| 71 | + select: function( $input ) { |
| 72 | + $input.closest( 'form' ).submit(); |
82 | 73 | } |
83 | | - }); |
84 | | - $(this).data( 'request', request ); |
85 | | - }, |
86 | | - cancel: function () { |
87 | | - var request = $(this).data( 'request' ); |
88 | | - // If the delay setting has caused the fetch to have not even happend yet, the request object will |
89 | | - // have never been set |
90 | | - if ( request && typeof request.abort == 'function' ) { |
91 | | - request.abort(); |
92 | | - $(this).removeData( 'request' ); |
93 | | - } |
94 | | - }, |
95 | | - result: { |
96 | | - select: function( $textbox ) { |
97 | | - $textbox.closest( 'form' ).submit(); |
98 | | - } |
99 | | - }, |
100 | | - delay: 120, |
101 | | - positionFromLeft: $( 'body' ).is( '.rtl' ), |
102 | | - highlightInput: true |
103 | | - } ) |
| 74 | + }, |
| 75 | + delay: 120, |
| 76 | + positionFromLeft: $( 'body' ).is( '.rtl' ), |
| 77 | + highlightInput: true |
| 78 | + } ) |
104 | 79 | .bind( 'paste cut', function( e ) { |
105 | 80 | // make sure paste and cut events from the mouse trigger the keypress handler and cause the suggestions to update |
106 | 81 | $( this ).trigger( 'keypress' ); |
107 | 82 | } ); |
| 83 | + // Special suggestions functionality for skin-provided search box |
108 | 84 | $( '#searchInput' ).suggestions( { |
109 | 85 | result: { |
110 | | - select: function( $textbox ) { |
111 | | - $textbox.closest( 'form' ).submit(); |
| 86 | + select: function( $input ) { |
| 87 | + $input.closest( 'form' ).submit(); |
112 | 88 | } |
113 | 89 | }, |
114 | 90 | special: { |
— | — | @@ -130,11 +106,11 @@ |
131 | 107 | .autoEllipsis(); |
132 | 108 | } |
133 | 109 | }, |
134 | | - select: function( $textbox ) { |
135 | | - $textbox.closest( 'form' ).append( |
| 110 | + select: function( $input ) { |
| 111 | + $input.closest( 'form' ).append( |
136 | 112 | $( '<input />' ).attr( { 'type': 'hidden', 'name': 'fulltext', 'value': 1 } ) |
137 | 113 | ); |
138 | | - $textbox.closest( 'form' ).submit(); |
| 114 | + $input.closest( 'form' ).submit(); |
139 | 115 | } |
140 | 116 | }, |
141 | 117 | $region: $( '#simpleSearch' ) |
Index: trunk/extensions/Vector/Vector.hooks.php |
— | — | @@ -64,6 +64,7 @@ |
65 | 65 | 'jquery.client', |
66 | 66 | 'jquery.suggestions', |
67 | 67 | 'jquery.autoEllipsis', |
| 68 | + 'jquery.placeholder', |
68 | 69 | ), |
69 | 70 | 'group' => 'ext.vector', |
70 | 71 | ), |