Index: trunk/phase3/resources/jquery/jquery.textSelection.js |
— | — | @@ -131,8 +131,58 @@ |
132 | 132 | var isSample = false; |
133 | 133 | if ( this.style.display == 'none' ) { |
134 | 134 | // Do nothing |
| 135 | + } else if ( document.selection && document.selection.createRange ) { |
| 136 | + // IE |
| 137 | + |
| 138 | + // Note that IE9 will trigger the next section unless we check this first. |
| 139 | + // See bug 35201. |
| 140 | + |
| 141 | + activateElementOnIE( this ); |
| 142 | + if ( context ) { |
| 143 | + context.fn.restoreCursorAndScrollTop(); |
| 144 | + } |
| 145 | + if ( options.selectionStart !== undefined ) { |
| 146 | + $(this).textSelection( 'setSelection', { 'start': options.selectionStart, 'end': options.selectionEnd } ); |
| 147 | + } |
| 148 | + |
| 149 | + var selText = $(this).textSelection( 'getSelection' ); |
| 150 | + var scrollTop = this.scrollTop; |
| 151 | + var range = document.selection.createRange(); |
| 152 | + |
| 153 | + checkSelectedText(); |
| 154 | + var insertText = pre + selText + post; |
| 155 | + if ( options.splitlines ) { |
| 156 | + insertText = doSplitLines( selText, pre, post ); |
| 157 | + } |
| 158 | + if ( options.ownline && range.moveStart ) { |
| 159 | + var range2 = document.selection.createRange(); |
| 160 | + range2.collapse(); |
| 161 | + range2.moveStart( 'character', -1 ); |
| 162 | + // FIXME: Which check is correct? |
| 163 | + if ( range2.text != "\r" && range2.text != "\n" && range2.text != "" ) { |
| 164 | + insertText = "\n" + insertText; |
| 165 | + pre += "\n"; |
| 166 | + } |
| 167 | + var range3 = document.selection.createRange(); |
| 168 | + range3.collapse( false ); |
| 169 | + range3.moveEnd( 'character', 1 ); |
| 170 | + if ( range3.text != "\r" && range3.text != "\n" && range3.text != "" ) { |
| 171 | + insertText += "\n"; |
| 172 | + post += "\n"; |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + range.text = insertText; |
| 177 | + if ( isSample && options.selectPeri && range.moveStart ) { |
| 178 | + range.moveStart( 'character', - post.length - selText.length ); |
| 179 | + range.moveEnd( 'character', - post.length ); |
| 180 | + } |
| 181 | + range.select(); |
| 182 | + // Restore the scroll position |
| 183 | + this.scrollTop = scrollTop; |
135 | 184 | } else if ( this.selectionStart || this.selectionStart == '0' ) { |
136 | 185 | // Mozilla/Opera |
| 186 | + |
137 | 187 | $(this).focus(); |
138 | 188 | if ( options.selectionStart !== undefined ) { |
139 | 189 | $(this).textSelection( 'setSelection', { 'start': options.selectionStart, 'end': options.selectionEnd } ); |
— | — | @@ -182,51 +232,6 @@ |
183 | 233 | this.selectionStart = startPos + insertText.length; |
184 | 234 | this.selectionEnd = this.selectionStart; |
185 | 235 | } |
186 | | - } else if ( document.selection && document.selection.createRange ) { |
187 | | - // IE |
188 | | - activateElementOnIE( this ); |
189 | | - if ( context ) { |
190 | | - context.fn.restoreCursorAndScrollTop(); |
191 | | - } |
192 | | - if ( options.selectionStart !== undefined ) { |
193 | | - $(this).textSelection( 'setSelection', { 'start': options.selectionStart, 'end': options.selectionEnd } ); |
194 | | - } |
195 | | - |
196 | | - var selText = $(this).textSelection( 'getSelection' ); |
197 | | - var scrollTop = this.scrollTop; |
198 | | - var range = document.selection.createRange(); |
199 | | - |
200 | | - checkSelectedText(); |
201 | | - var insertText = pre + selText + post; |
202 | | - if ( options.splitlines ) { |
203 | | - insertText = doSplitLines( selText, pre, post ); |
204 | | - } |
205 | | - if ( options.ownline && range.moveStart ) { |
206 | | - var range2 = document.selection.createRange(); |
207 | | - range2.collapse(); |
208 | | - range2.moveStart( 'character', -1 ); |
209 | | - // FIXME: Which check is correct? |
210 | | - if ( range2.text != "\r" && range2.text != "\n" && range2.text != "" ) { |
211 | | - insertText = "\n" + insertText; |
212 | | - pre += "\n"; |
213 | | - } |
214 | | - var range3 = document.selection.createRange(); |
215 | | - range3.collapse( false ); |
216 | | - range3.moveEnd( 'character', 1 ); |
217 | | - if ( range3.text != "\r" && range3.text != "\n" && range3.text != "" ) { |
218 | | - insertText += "\n"; |
219 | | - post += "\n"; |
220 | | - } |
221 | | - } |
222 | | - |
223 | | - range.text = insertText; |
224 | | - if ( isSample && options.selectPeri && range.moveStart ) { |
225 | | - range.moveStart( 'character', - post.length - selText.length ); |
226 | | - range.moveEnd( 'character', - post.length ); |
227 | | - } |
228 | | - range.select(); |
229 | | - // Restore the scroll position |
230 | | - this.scrollTop = scrollTop; |
231 | 236 | } |
232 | 237 | $(this).trigger( 'encapsulateSelection', [ options.pre, options.peri, options.post, options.ownline, |
233 | 238 | options.replace, options.spitlines ] ); |