Index: trunk/extensions/Survey/Survey.php |
— | — | @@ -105,9 +105,8 @@ |
106 | 106 | $wgGroupPermissions['sysop' ]['surveysubmit'] = true; |
107 | 107 | |
108 | 108 | $moduleTemplate = array( |
109 | | - 'localBasePath' => dirname( __FILE__ ), |
110 | | - 'remoteBasePath' => ( $wgExtensionAssetsPath === false ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath ) |
111 | | - . '/Survey/resources' |
| 109 | + 'localBasePath' => dirname( __FILE__ ) . '/resources', |
| 110 | + 'remoteExtPath' => 'Survey/resources' |
112 | 111 | ); |
113 | 112 | |
114 | 113 | $wgResourceModules['ext.survey'] = $moduleTemplate + array( |
— | — | @@ -132,7 +131,7 @@ |
133 | 132 | 'ext.survey.special.survey.js' |
134 | 133 | ), |
135 | 134 | 'styles' => array( |
136 | | - //'ext.survey.special.survey.css' |
| 135 | + 'ext.survey.special.survey.css' |
137 | 136 | ), |
138 | 137 | 'dependencies' => array( 'ext.survey', 'jquery.ui.button' ), |
139 | 138 | 'messages' => array( |
— | — | @@ -140,6 +139,7 @@ |
141 | 140 | 'survey-question-type-number', |
142 | 141 | 'survey-question-type-select', |
143 | 142 | 'survey-question-type-radio', |
| 143 | + 'survey-question-type-textarea', |
144 | 144 | 'survey-question-label-nr', |
145 | 145 | 'survey-special-label-required', |
146 | 146 | 'survey-special-label-type', |
— | — | @@ -151,18 +151,24 @@ |
152 | 152 | ) |
153 | 153 | ); |
154 | 154 | |
| 155 | +$wgResourceModules['ext.survey.numeric'] = $moduleTemplate + array( |
| 156 | + 'scripts' => array( |
| 157 | + 'jquery.numeric.js' |
| 158 | + ) |
| 159 | +); |
| 160 | + |
155 | 161 | $wgResourceModules['ext.survey.jquery'] = $moduleTemplate + array( |
156 | 162 | 'scripts' => array( |
157 | 163 | 'fancybox/jquery.fancybox-1.3.4.js', |
158 | 164 | 'jquery.survey.js' |
159 | 165 | ), |
160 | 166 | 'styles' => array( |
161 | | - // This file makes the RL go mad for some reason, so for now load it the old fashioned way. |
162 | | - //'fancybox/jquery.fancybox-1.3.4.css', |
| 167 | + 'jquery.survey.css', |
| 168 | + 'fancybox/jquery.fancybox-1.3.4.css' |
163 | 169 | ), |
164 | | - 'dependencies' => array( 'ext.survey' ), |
| 170 | + 'dependencies' => array( 'ext.survey', 'jquery.ui.button', 'ext.survey.numeric' ), |
165 | 171 | 'messages' => array( |
166 | | - |
| 172 | + 'survey-jquery-submit', |
167 | 173 | ) |
168 | 174 | ); |
169 | 175 | |
Index: trunk/extensions/Survey/Survey.i18n.php |
— | — | @@ -65,6 +65,7 @@ |
66 | 66 | 'survey-question-type-number' => 'Number', |
67 | 67 | 'survey-question-type-select' => 'Dropdown menu', |
68 | 68 | 'survey-question-type-radio' => 'Radio boxes', |
| 69 | + 'survey-question-type-textarea' => 'Text area', |
69 | 70 | 'survey-question-label-nr' => 'Question #$1', |
70 | 71 | 'survey-special-label-required' => 'Question is required', |
71 | 72 | 'survey-special-label-type' => 'Question type', |
— | — | @@ -74,4 +75,7 @@ |
75 | 76 | 'survey-special-label-header' => 'Text to display above the survey', |
76 | 77 | 'survey-special-label-footer' => 'Text to display below the survey', |
77 | 78 | 'survey-special-label-thanks' => 'Thanks message to display after submission of the survey', |
| 79 | + |
| 80 | + // Survey jQuery |
| 81 | + 'survey-jquery-submit' => 'Submit', |
78 | 82 | ); |
Index: trunk/extensions/Survey/includes/SurveyTag.php |
— | — | @@ -67,12 +67,6 @@ |
68 | 68 | |
69 | 69 | if ( !$loadedJs ) { |
70 | 70 | $parser->getOutput()->addModules( 'ext.survey.jquery' ); |
71 | | - |
72 | | - global $wgExtensionAssetsPath, $wgScriptPath; |
73 | | - $parser->getOutput()->addHeadItem( Html::linkedStyle( |
74 | | - ( $wgExtensionAssetsPath === false ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath ) |
75 | | - . '/Survey/resources/fancybox/jquery.fancybox-1.3.4.css' |
76 | | - ) ); |
77 | 71 | } |
78 | 72 | |
79 | 73 | return Html::element( |
Index: trunk/extensions/Survey/includes/SurveyQuestion.php |
— | — | @@ -17,6 +17,7 @@ |
18 | 18 | public static $TYPE_NUMBER = 1; |
19 | 19 | public static $TYPE_SELECT = 2; |
20 | 20 | public static $TYPE_RADIO = 3; |
| 21 | + public static $TYPE_TEXTAREA = 4; |
21 | 22 | |
22 | 23 | /** |
23 | 24 | * @see SurveyDBClass::getDBTable() |
Index: trunk/extensions/Survey/api/ApiQuerySurveys.php |
— | — | @@ -39,6 +39,13 @@ |
40 | 40 | |
41 | 41 | $this->addTables( 'surveys' ); |
42 | 42 | |
| 43 | + $starPropPosition = array_search( '*', $params['props'] ); |
| 44 | + |
| 45 | + if ( $starPropPosition !== false ) { |
| 46 | + unset( $params['props'][$starPropPosition] ); |
| 47 | + $params['props'] = array_merge( $params['props'], Survey::getFieldNames() ); |
| 48 | + } |
| 49 | + |
43 | 50 | $fields = array_merge( array( 'id' ), $params['props'] ); |
44 | 51 | |
45 | 52 | $this->addFields( Survey::getPrefixedFields( $fields ) ); |
— | — | @@ -125,7 +132,7 @@ |
126 | 133 | ApiBase::PARAM_ISMULTI => true, |
127 | 134 | ), |
128 | 135 | 'props' => array( |
129 | | - ApiBase::PARAM_TYPE => Survey::getFieldNames(), |
| 136 | + ApiBase::PARAM_TYPE => array_merge( Survey::getFieldNames(), array( '*' ) ), |
130 | 137 | ApiBase::PARAM_ISMULTI => true, |
131 | 138 | ApiBase::PARAM_DFLT => 'id|name|enabled' |
132 | 139 | ), |
Index: trunk/extensions/Survey/resources/jquery.survey.css |
— | — | @@ -0,0 +1,5 @@ |
| 2 | +@CHARSET "UTF-8"; |
| 3 | + |
| 4 | +.survey-textarea { |
| 5 | + width: 80% |
| 6 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Survey/resources/jquery.survey.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 7 | + native |
Index: trunk/extensions/Survey/resources/jquery.survey.js |
— | — | @@ -19,7 +19,8 @@ |
20 | 20 | 'format': 'json', |
21 | 21 | 'sunames': options.names.join( '|' ), |
22 | 22 | 'suincquestions': 1, |
23 | | - 'suenabled': 1 |
| 23 | + 'suenabled': 1, |
| 24 | + 'suprops': '*' |
24 | 25 | }, |
25 | 26 | function( data ) { |
26 | 27 | if ( data.surveys ) { |
— | — | @@ -39,9 +40,13 @@ |
40 | 41 | |
41 | 42 | this.submitSurvey = function() { |
42 | 43 | // TODO |
| 44 | + |
| 45 | + // $survey.append( $( '<p />' ).text( surveyData.thanks ) ); |
43 | 46 | }; |
44 | 47 | |
45 | 48 | this.getQuestionInput = function( question ) { |
| 49 | + survey.log( 'getQuestionInput: ' + question.id ); |
| 50 | + |
46 | 51 | var type = survey.question.type; |
47 | 52 | |
48 | 53 | var $input; |
— | — | @@ -50,9 +55,37 @@ |
51 | 56 | case type.TEXT: default: |
52 | 57 | $input = $( '<input />' ).attr( { |
53 | 58 | 'id': 'survey-question-' + question.id, |
| 59 | + 'class': 'survey-question survey-text' |
| 60 | + } ); |
| 61 | + break; |
| 62 | + case type.NUMBER: |
| 63 | + $input = $( '<input />' ).numeric().attr( { |
| 64 | + 'id': 'survey-question-' + question.id, |
| 65 | + 'class': 'survey-question survey-number', |
| 66 | + 'size': 7 |
| 67 | + } ); |
| 68 | + break; |
| 69 | + case type.SELECT: |
| 70 | + $input = survey.htmlSelect( question.answers, 0, { |
| 71 | + 'id': 'survey-question-' + question.id, |
| 72 | + 'class': 'survey-question survey-select' |
| 73 | + } ); |
| 74 | + break; |
| 75 | + case type.RADIO: |
| 76 | + // TODO |
| 77 | + $input = $( '<input />' ).attr( { |
| 78 | + 'id': 'survey-question-' + question.id, |
54 | 79 | 'class': 'survey-question' |
55 | 80 | } ); |
56 | 81 | break; |
| 82 | + case type.TEXTAREA: |
| 83 | + $input = $( '<textarea />' ).attr( { |
| 84 | + 'id': 'survey-question-' + question.id, |
| 85 | + 'class': 'survey-question survey-textarea', |
| 86 | + 'cols': 80, |
| 87 | + 'rows': 2 |
| 88 | + } ); |
| 89 | + break; |
57 | 90 | } |
58 | 91 | |
59 | 92 | return $input; |
— | — | @@ -65,8 +98,6 @@ |
66 | 99 | |
67 | 100 | $q.append( this.getQuestionInput( question ) ) |
68 | 101 | |
69 | | - $q.append( '<hr />' ); |
70 | | - |
71 | 102 | return $q; |
72 | 103 | }; |
73 | 104 | |
— | — | @@ -85,8 +116,14 @@ |
86 | 117 | |
87 | 118 | $survey.append( $( '<h1 />' ).text( surveyData.name ) ); |
88 | 119 | |
| 120 | + $survey.append( $( '<p />' ).text( surveyData.header ) ); |
| 121 | + |
89 | 122 | $survey.append( this.getSurveyQuestions( surveyData.questions ) ); |
90 | 123 | |
| 124 | + $survey.append( $( '<button />' ).button( { label: mw.msg( 'survey-jquery-submit' ) } ) ); |
| 125 | + |
| 126 | + $survey.append( $( '<p />' ).text( surveyData.footer ) ); |
| 127 | + |
91 | 128 | return $survey; |
92 | 129 | }; |
93 | 130 | |
— | — | @@ -97,11 +134,21 @@ |
98 | 135 | |
99 | 136 | $link = $( '<a />' ).attr( { |
100 | 137 | 'href': '#survey-' + surveyData.id, |
101 | | - 'id': 'inline' |
102 | 138 | } ).html( $div ); |
103 | 139 | |
104 | 140 | surveyElement.html( $link ); |
105 | | - $link.fancybox(); |
| 141 | + |
| 142 | + $link.fancybox( { |
| 143 | +// 'width' : '75%', |
| 144 | +// 'height' : '75%', |
| 145 | + 'autoScale' : false, |
| 146 | + 'transitionIn' : 'none', |
| 147 | + 'transitionOut' : 'none', |
| 148 | + 'type' : 'inline', |
| 149 | + 'hideOnOverlayClick': false, |
| 150 | + 'autoDimensions': true |
| 151 | + } ); |
| 152 | + |
106 | 153 | $link.click(); |
107 | 154 | }; |
108 | 155 | |
Index: trunk/extensions/Survey/resources/ext.survey.js |
— | — | @@ -59,6 +59,7 @@ |
60 | 60 | this.NUMBER = 1; |
61 | 61 | this.SELECT = 2; |
62 | 62 | this.RADIO = 3; |
| 63 | + this.TEXTAREA = 4; |
63 | 64 | } ); |
64 | 65 | |
65 | 66 | this.getTypeSelector = function( value, attributes ) { |
— | — | @@ -68,7 +69,8 @@ |
69 | 70 | 'text': survey.question.type.TEXT, |
70 | 71 | 'number': survey.question.type.NUMBER, |
71 | 72 | 'select': survey.question.type.SELECT, |
72 | | - 'radio': survey.question.type.RADIO |
| 73 | + 'radio': survey.question.type.RADIO, |
| 74 | + 'textarea': survey.question.type.TEXTAREA, |
73 | 75 | }; |
74 | 76 | |
75 | 77 | for ( msg in types ) { |
Index: trunk/extensions/Survey/resources/jquery.numeric.js |
— | — | @@ -0,0 +1,279 @@ |
| 2 | +/* |
| 3 | + * |
| 4 | + * Copyright (c) 2006-2011 Sam Collett (http://www.texotela.co.uk) |
| 5 | + * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) |
| 6 | + * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. |
| 7 | + * |
| 8 | + * Version 1.3 |
| 9 | + * Demo: http://www.texotela.co.uk/code/jquery/numeric/ |
| 10 | + * |
| 11 | + */ |
| 12 | +(function($) { |
| 13 | +/* |
| 14 | + * Allows only valid characters to be entered into input boxes. |
| 15 | + * Note: fixes value when pasting via Ctrl+V, but not when using the mouse to paste |
| 16 | + * side-effect: Ctrl+A does not work, though you can still use the mouse to select (or double-click to select all) |
| 17 | + * |
| 18 | + * @name numeric |
| 19 | + * @param config { decimal : "." , negative : true } |
| 20 | + * @param callback A function that runs if the number is not valid (fires onblur) |
| 21 | + * @author Sam Collett (http://www.texotela.co.uk) |
| 22 | + * @example $(".numeric").numeric(); |
| 23 | + * @example $(".numeric").numeric(","); // use , as separater |
| 24 | + * @example $(".numeric").numeric({ decimal : "," }); // use , as separator |
| 25 | + * @example $(".numeric").numeric({ negative : false }); // do not allow negative values |
| 26 | + * @example $(".numeric").numeric(null, callback); // use default values, pass on the 'callback' function |
| 27 | + * |
| 28 | + */ |
| 29 | +$.fn.numeric = function(config, callback) |
| 30 | +{ |
| 31 | + if(typeof config === 'boolean') |
| 32 | + { |
| 33 | + config = { decimal: config }; |
| 34 | + } |
| 35 | + config = config || {}; |
| 36 | + // if config.negative undefined, set to true (default is to allow negative numbers) |
| 37 | + if(typeof config.negative == "undefined") config.negative = true; |
| 38 | + // set decimal point |
| 39 | + var decimal = (config.decimal === false) ? "" : config.decimal || "."; |
| 40 | + // allow negatives |
| 41 | + var negative = (config.negative === true) ? true : false; |
| 42 | + // callback function |
| 43 | + var callback = typeof callback == "function" ? callback : function(){}; |
| 44 | + // set data and methods |
| 45 | + return this.data("numeric.decimal", decimal).data("numeric.negative", negative).data("numeric.callback", callback).keypress($.fn.numeric.keypress).keyup($.fn.numeric.keyup).blur($.fn.numeric.blur); |
| 46 | +} |
| 47 | + |
| 48 | +$.fn.numeric.keypress = function(e) |
| 49 | +{ |
| 50 | + // get decimal character and determine if negatives are allowed |
| 51 | + var decimal = $.data(this, "numeric.decimal"); |
| 52 | + var negative = $.data(this, "numeric.negative"); |
| 53 | + // get the key that was pressed |
| 54 | + var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; |
| 55 | + // allow enter/return key (only when in an input box) |
| 56 | + if(key == 13 && this.nodeName.toLowerCase() == "input") |
| 57 | + { |
| 58 | + return true; |
| 59 | + } |
| 60 | + else if(key == 13) |
| 61 | + { |
| 62 | + return false; |
| 63 | + } |
| 64 | + var allow = false; |
| 65 | + // allow Ctrl+A |
| 66 | + if((e.ctrlKey && key == 97 /* firefox */) || (e.ctrlKey && key == 65) /* opera */) return true; |
| 67 | + // allow Ctrl+X (cut) |
| 68 | + if((e.ctrlKey && key == 120 /* firefox */) || (e.ctrlKey && key == 88) /* opera */) return true; |
| 69 | + // allow Ctrl+C (copy) |
| 70 | + if((e.ctrlKey && key == 99 /* firefox */) || (e.ctrlKey && key == 67) /* opera */) return true; |
| 71 | + // allow Ctrl+Z (undo) |
| 72 | + if((e.ctrlKey && key == 122 /* firefox */) || (e.ctrlKey && key == 90) /* opera */) return true; |
| 73 | + // allow or deny Ctrl+V (paste), Shift+Ins |
| 74 | + if((e.ctrlKey && key == 118 /* firefox */) || (e.ctrlKey && key == 86) /* opera */ |
| 75 | + || (e.shiftKey && key == 45)) return true; |
| 76 | + // if a number was not pressed |
| 77 | + if(key < 48 || key > 57) |
| 78 | + { |
| 79 | + /* '-' only allowed at start and if negative numbers allowed */ |
| 80 | + if(this.value.indexOf("-") != 0 && negative && key == 45 && (this.value.length == 0 || ($.fn.getSelectionStart(this)) == 0)) return true; |
| 81 | + /* only one decimal separator allowed */ |
| 82 | + if(decimal && key == decimal.charCodeAt(0) && this.value.indexOf(decimal) != -1) |
| 83 | + { |
| 84 | + allow = false; |
| 85 | + } |
| 86 | + // check for other keys that have special purposes |
| 87 | + if( |
| 88 | + key != 8 /* backspace */ && |
| 89 | + key != 9 /* tab */ && |
| 90 | + key != 13 /* enter */ && |
| 91 | + key != 35 /* end */ && |
| 92 | + key != 36 /* home */ && |
| 93 | + key != 37 /* left */ && |
| 94 | + key != 39 /* right */ && |
| 95 | + key != 46 /* del */ |
| 96 | + ) |
| 97 | + { |
| 98 | + allow = false; |
| 99 | + } |
| 100 | + else |
| 101 | + { |
| 102 | + // for detecting special keys (listed above) |
| 103 | + // IE does not support 'charCode' and ignores them in keypress anyway |
| 104 | + if(typeof e.charCode != "undefined") |
| 105 | + { |
| 106 | + // special keys have 'keyCode' and 'which' the same (e.g. backspace) |
| 107 | + if(e.keyCode == e.which && e.which != 0) |
| 108 | + { |
| 109 | + allow = true; |
| 110 | + // . and delete share the same code, don't allow . (will be set to true later if it is the decimal point) |
| 111 | + if(e.which == 46) allow = false; |
| 112 | + } |
| 113 | + // or keyCode != 0 and 'charCode'/'which' = 0 |
| 114 | + else if(e.keyCode != 0 && e.charCode == 0 && e.which == 0) |
| 115 | + { |
| 116 | + allow = true; |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + // if key pressed is the decimal and it is not already in the field |
| 121 | + if(decimal && key == decimal.charCodeAt(0)) |
| 122 | + { |
| 123 | + if(this.value.indexOf(decimal) == -1) |
| 124 | + { |
| 125 | + allow = true; |
| 126 | + } |
| 127 | + else |
| 128 | + { |
| 129 | + allow = false; |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + else |
| 134 | + { |
| 135 | + allow = true; |
| 136 | + } |
| 137 | + return allow; |
| 138 | +} |
| 139 | + |
| 140 | +$.fn.numeric.keyup = function(e) |
| 141 | +{ |
| 142 | + var val = this.value; |
| 143 | + if(val.length > 0) |
| 144 | + { |
| 145 | + // get carat (cursor) position |
| 146 | + var carat = $.fn.getSelectionStart(this); |
| 147 | + // get decimal character and determine if negatives are allowed |
| 148 | + var decimal = $.data(this, "numeric.decimal"); |
| 149 | + var negative = $.data(this, "numeric.negative"); |
| 150 | + |
| 151 | + // prepend a 0 if necessary |
| 152 | + if(decimal != "") |
| 153 | + { |
| 154 | + // find decimal point |
| 155 | + var dot = val.indexOf(decimal); |
| 156 | + // if dot at start, add 0 before |
| 157 | + if(dot == 0) |
| 158 | + { |
| 159 | + this.value = "0" + val; |
| 160 | + } |
| 161 | + // if dot at position 1, check if there is a - symbol before it |
| 162 | + if(dot == 1 && val.charAt(0) == "-") |
| 163 | + { |
| 164 | + this.value = "-0" + val.substring(1); |
| 165 | + } |
| 166 | + val = this.value; |
| 167 | + } |
| 168 | + |
| 169 | + // if pasted in, only allow the following characters |
| 170 | + var validChars = [0,1,2,3,4,5,6,7,8,9,'-',decimal]; |
| 171 | + // get length of the value (to loop through) |
| 172 | + var length = val.length; |
| 173 | + // loop backwards (to prevent going out of bounds) |
| 174 | + for(var i = length - 1; i >= 0; i--) |
| 175 | + { |
| 176 | + var ch = val.charAt(i); |
| 177 | + // remove '-' if it is in the wrong place |
| 178 | + if(i != 0 && ch == "-") |
| 179 | + { |
| 180 | + val = val.substring(0, i) + val.substring(i + 1); |
| 181 | + } |
| 182 | + // remove character if it is at the start, a '-' and negatives aren't allowed |
| 183 | + else if(i == 0 && !negative && ch == "-") |
| 184 | + { |
| 185 | + val = val.substring(1); |
| 186 | + } |
| 187 | + var validChar = false; |
| 188 | + // loop through validChars |
| 189 | + for(var j = 0; j < validChars.length; j++) |
| 190 | + { |
| 191 | + // if it is valid, break out the loop |
| 192 | + if(ch == validChars[j]) |
| 193 | + { |
| 194 | + validChar = true; |
| 195 | + break; |
| 196 | + } |
| 197 | + } |
| 198 | + // if not a valid character, or a space, remove |
| 199 | + if(!validChar || ch == " ") |
| 200 | + { |
| 201 | + val = val.substring(0, i) + val.substring(i + 1); |
| 202 | + } |
| 203 | + } |
| 204 | + // remove extra decimal characters |
| 205 | + var firstDecimal = val.indexOf(decimal); |
| 206 | + if(firstDecimal > 0) |
| 207 | + { |
| 208 | + for(var i = length - 1; i > firstDecimal; i--) |
| 209 | + { |
| 210 | + var ch = val.charAt(i); |
| 211 | + // remove decimal character |
| 212 | + if(ch == decimal) |
| 213 | + { |
| 214 | + val = val.substring(0, i) + val.substring(i + 1); |
| 215 | + } |
| 216 | + } |
| 217 | + } |
| 218 | + // set the value and prevent the cursor moving to the end |
| 219 | + this.value = val; |
| 220 | + $.fn.setSelection(this, carat); |
| 221 | + } |
| 222 | +} |
| 223 | + |
| 224 | +$.fn.numeric.blur = function() |
| 225 | +{ |
| 226 | + var decimal = $.data(this, "numeric.decimal"); |
| 227 | + var callback = $.data(this, "numeric.callback"); |
| 228 | + var val = this.value; |
| 229 | + if(val != "") |
| 230 | + { |
| 231 | + var re = new RegExp("^\\d+$|\\d*" + decimal + "\\d+"); |
| 232 | + if(!re.exec(val)) |
| 233 | + { |
| 234 | + callback.apply(this); |
| 235 | + } |
| 236 | + } |
| 237 | +} |
| 238 | + |
| 239 | +$.fn.removeNumeric = function() |
| 240 | +{ |
| 241 | + return this.data("numeric.decimal", null).data("numeric.negative", null).data("numeric.callback", null).unbind("keypress", $.fn.numeric.keypress).unbind("blur", $.fn.numeric.blur); |
| 242 | +} |
| 243 | + |
| 244 | +// Based on code from http://javascript.nwbox.com/cursor_position/ (Diego Perini <dperini@nwbox.com>) |
| 245 | +$.fn.getSelectionStart = function(o) |
| 246 | +{ |
| 247 | + if (o.createTextRange) |
| 248 | + { |
| 249 | + var r = document.selection.createRange().duplicate(); |
| 250 | + r.moveEnd('character', o.value.length); |
| 251 | + if (r.text == '') return o.value.length; |
| 252 | + return o.value.lastIndexOf(r.text); |
| 253 | + } else return o.selectionStart; |
| 254 | +} |
| 255 | + |
| 256 | +// set the selection, o is the object (input), p is the position ([start, end] or just start) |
| 257 | +$.fn.setSelection = function(o, p) |
| 258 | +{ |
| 259 | + // if p is number, start and end are the same |
| 260 | + if(typeof p == "number") p = [p, p]; |
| 261 | + // only set if p is an array of length 2 |
| 262 | + if(p && p.constructor == Array && p.length == 2) |
| 263 | + { |
| 264 | + if (o.createTextRange) |
| 265 | + { |
| 266 | + var r = o.createTextRange(); |
| 267 | + r.collapse(true); |
| 268 | + r.moveStart('character', p[0]); |
| 269 | + r.moveEnd('character', p[1]); |
| 270 | + r.select(); |
| 271 | + } |
| 272 | + else if(o.setSelectionRange) |
| 273 | + { |
| 274 | + o.focus(); |
| 275 | + o.setSelectionRange(p[0], p[1]); |
| 276 | + } |
| 277 | + } |
| 278 | +} |
| 279 | + |
| 280 | +})(jQuery); |
\ No newline at end of file |
Property changes on: trunk/extensions/Survey/resources/jquery.numeric.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 281 | + native |