Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -70,7 +70,7 @@ |
71 | 71 | array( 'src' => 'js/plugins/jquery.color.js', 'version' => 1 ), |
72 | 72 | array( 'src' => 'js/plugins/jquery.cookie.js', 'version' => 4 ), |
73 | 73 | array( 'src' => 'js/plugins/jquery.delayedBind.js', 'version' => 1 ), |
74 | | - array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 14 ), |
| 74 | + array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 15 ), |
75 | 75 | array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 33 ), |
76 | 76 | array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 187 ), |
77 | 77 | array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 53 ), |
— | — | @@ -83,10 +83,10 @@ |
84 | 84 | array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 5 ), |
85 | 85 | ), |
86 | 86 | 'combined' => array( |
87 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 396 ), |
| 87 | + array( 'src' => 'js/plugins.combined.js', 'version' => 397 ), |
88 | 88 | ), |
89 | 89 | 'minified' => array( |
90 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 396 ), |
| 90 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 397 ), |
91 | 91 | ), |
92 | 92 | ), |
93 | 93 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.suggestions.js |
— | — | @@ -258,7 +258,11 @@ |
259 | 259 | context.data.$container.hide(); |
260 | 260 | preventDefault = wasVisible; |
261 | 261 | selected = context.data.$container.find( '.suggestions-result-current' ); |
262 | | - if ( selected.is( '.suggestions-special' ) ) { |
| 262 | + if ( selected.size() == 0 ) { |
| 263 | + // if nothing is selected, cancel any current requests and submit the form |
| 264 | + $.suggestions.cancel( context ); |
| 265 | + context.config.$region.closest( 'form' ).submit(); |
| 266 | + } else if ( selected.is( '.suggestions-special' ) ) { |
263 | 267 | if ( typeof context.config.special.select == 'function' ) { |
264 | 268 | context.config.special.select.call( selected, context.data.$textbox ); |
265 | 269 | } |
— | — | @@ -292,7 +296,7 @@ |
293 | 297 | /* Construction / Loading */ |
294 | 298 | |
295 | 299 | var context = $(this).data( 'suggestions-context' ); |
296 | | - if ( typeof context == 'undefined' ) { |
| 300 | + if ( typeof context == 'undefined' || context == null ) { |
297 | 301 | context = { |
298 | 302 | config: { |
299 | 303 | 'fetch' : function() {}, |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -6009,7 +6009,11 @@ |
6010 | 6010 | context.data.$container.hide(); |
6011 | 6011 | preventDefault = wasVisible; |
6012 | 6012 | selected = context.data.$container.find( '.suggestions-result-current' ); |
6013 | | - if ( selected.is( '.suggestions-special' ) ) { |
| 6013 | + if ( selected.size() == 0 ) { |
| 6014 | + // if nothing is selected, cancel any current requests and submit the form |
| 6015 | + $.suggestions.cancel( context ); |
| 6016 | + context.config.$region.closest( 'form' ).submit(); |
| 6017 | + } else if ( selected.is( '.suggestions-special' ) ) { |
6014 | 6018 | if ( typeof context.config.special.select == 'function' ) { |
6015 | 6019 | context.config.special.select.call( selected, context.data.$textbox ); |
6016 | 6020 | } |
— | — | @@ -6043,7 +6047,7 @@ |
6044 | 6048 | /* Construction / Loading */ |
6045 | 6049 | |
6046 | 6050 | var context = $(this).data( 'suggestions-context' ); |
6047 | | - if ( typeof context == 'undefined' ) { |
| 6051 | + if ( typeof context == 'undefined' || context == null ) { |
6048 | 6052 | context = { |
6049 | 6053 | config: { |
6050 | 6054 | 'fetch' : function() {}, |
— | — | @@ -6685,6 +6689,7 @@ |
6686 | 6690 | 'isSupported': function( module ) { |
6687 | 6691 | // Fallback to the wikiEditor browser map if no special map is provided in the module |
6688 | 6692 | var mod = module && 'browsers' in module ? module : $.wikiEditor; |
| 6693 | + return mod.supported = true; |
6689 | 6694 | // Check for and make use of cached value and early opportunities to bail |
6690 | 6695 | if ( typeof mod.supported !== 'undefined' ) { |
6691 | 6696 | // Cache hit |
— | — | @@ -7018,8 +7023,12 @@ |
7019 | 7024 | 'paste': function( event ) { |
7020 | 7025 | // Save the cursor position to restore it after all this voodoo |
7021 | 7026 | var cursorPos = context.fn.getCaretPosition(); |
7022 | | - var oldLength = context.fn.getContents().length - ( cursorPos[1] - cursorPos[0] ); |
7023 | | - context.$content.find( ':not(.wikiEditor)' ).addClass( 'wikiEditor' ); |
| 7027 | + if ( !context.$content.text() ) { |
| 7028 | + context.$content.empty(); |
| 7029 | + } |
| 7030 | + var oldLength = context.fn.getContents().length; |
| 7031 | + |
| 7032 | + context.$content.find( '*' ).addClass( 'wikiEditor' ); |
7024 | 7033 | if ( $.layout.name !== 'webkit' ) { |
7025 | 7034 | context.$content.addClass( 'pasting' ); |
7026 | 7035 | } |
— | — | @@ -7039,58 +7048,82 @@ |
7040 | 7049 | var outerParent = $(this).parent(); |
7041 | 7050 | outerParent.replaceWith( outerParent.childNodes ); |
7042 | 7051 | } ); |
| 7052 | + |
7043 | 7053 | // Unwrap the span found in webkit copies (Apple Richtext) |
7044 | | - context.$content.find( 'span.Apple-style-span' ).each( function() { |
7045 | | - $(this).replaceWith( this.childNodes ); |
7046 | | - } ); |
| 7054 | + if ( ! $.browser.msie ) { |
| 7055 | + context.$content.find( 'span.Apple-style-span' ).each( function() { |
| 7056 | + $(this).replaceWith( this.childNodes ); |
| 7057 | + } ); |
| 7058 | + } |
7047 | 7059 | |
7048 | | - // If the pasted content is plain text then wrap it in a <p> and adjust the <br> accordingly |
7049 | | - var pasteContent = context.fn.getOffset( cursorPos[0] ).node; |
7050 | | - var removeNextBR = false; |
7051 | | - while ( pasteContent != null && !$( pasteContent ).hasClass( 'wikiEditor' ) ) { |
7052 | | - var currentNode = pasteContent; |
7053 | | - pasteContent = pasteContent.nextSibling; |
7054 | | - if ( currentNode.nodeName == '#text' && currentNode.nodeValue == currentNode.wholeText ) { |
7055 | | - var pWrapper = $( '<p />' ).addClass( 'wikiEditor' ); |
7056 | | - $( currentNode ).wrap( pWrapper ); |
7057 | | - $( currentNode ).addClass( 'wikiEditor' ); |
7058 | | - removeNextBR = true; |
7059 | | - } else if ( currentNode.nodeName == 'BR' && removeNextBR ) { |
7060 | | - $( currentNode ).remove(); |
7061 | | - removeNextBR = false; |
7062 | | - } else { |
7063 | | - removeNextBR = false; |
7064 | | - } |
7065 | | - } |
7066 | 7060 | var $selection = context.$content.find( ':not(.wikiEditor)' ); |
| 7061 | + var $previousElement; |
7067 | 7062 | while ( $selection.length && $selection.length > 0 ) { |
7068 | 7063 | var $currentElement = $selection.eq( 0 ); |
| 7064 | + |
| 7065 | + //go up till we find the first pasted element |
7069 | 7066 | while ( !$currentElement.parent().is( 'body' ) && !$currentElement.parent().is( '.wikiEditor' ) ) { |
7070 | 7067 | $currentElement = $currentElement.parent(); |
7071 | 7068 | } |
| 7069 | + //go to the previous element till we find the first pasted element |
| 7070 | + while ( $currentElement[0] != null && |
| 7071 | + $currentElement[0].previousSibling != null && |
| 7072 | + !$( $currentElement[0].previousSibling ).hasClass( 'wikiEditor' ) ) { |
| 7073 | + $currentElement = $( $currentElement[0].previousSibling ); |
| 7074 | + } |
7072 | 7075 | |
| 7076 | + //each pasted element is always wrapped in a <p> |
7073 | 7077 | var $newElement; |
7074 | | - if ( $currentElement.is( 'p' ) || $currentElement.is( 'div' ) || $currentElement.is( 'pre' ) ) { |
7075 | | - //Convert all <div>, <p> and <pre> that was pasted into a <p> element |
7076 | | - $newElement = $( '<p />' ); |
| 7078 | + var textNode = false; |
| 7079 | + if ( $currentElement[0].nodeName == '#text' ) { |
| 7080 | + $newElement = $( '<p></p>' ); |
| 7081 | + textNode = true; |
| 7082 | + } else if ( $currentElement.is( 'p' ) || $currentElement.is( 'pre' ) || $currentElement.is( 'br' ) ) { |
| 7083 | + $newElement = $( '<p></p>' ); |
7077 | 7084 | } else { |
7078 | | - // everything else becomes a <span> |
7079 | | - $newElement = $( '<span />' ).addClass( 'wikiEditor' ); |
| 7085 | + $newElement = $( '<span></span>' ); |
7080 | 7086 | } |
| 7087 | + var newElementHTML = ''; |
| 7088 | + var currentHTML = ''; |
7081 | 7089 | |
7082 | | - // If the pasted content was html, just convert it into text and <br> |
7083 | | - var pieces = $.trim( $currentElement.text() ).split( '\n' ); |
7084 | | - var newElementHTML = ''; |
| 7090 | + |
| 7091 | + if ( $currentElement[0].nodeName == '#text' ) { |
| 7092 | + //if it is a text node then just append it |
| 7093 | + currentHTML = $currentElement[0].nodeValue; |
| 7094 | + } else { |
| 7095 | + currentHTML = $currentElement.html(); |
| 7096 | + //replace all forms of <p> tags with a \n. All other tags get removed. |
| 7097 | + currentHTML = currentHTML.replace(/(<[\s]*p[^>]*>)|(<[\s]*\/p[^>]*>)|(<[\s]*p[^\/>]*\/>)/gi, '\n'); |
| 7098 | + currentHTML = currentHTML.replace(/(<[^>]*>)|(<[^\>]*\>)/gi, ''); |
| 7099 | + |
| 7100 | + } |
| 7101 | + |
| 7102 | + //wrap each piece in a <p> with a <br> in between. |
| 7103 | + var pieces = currentHTML.split( '\n' ); |
7085 | 7104 | for ( var i = 0; i < pieces.length; i++ ) { |
7086 | 7105 | if ( pieces[i] ) { |
7087 | | - newElementHTML += $.trim( pieces[i] ); |
7088 | | - } else { |
7089 | | - newElementHTML += '<span><br class="wikiEditor" /></span>'; |
| 7106 | + if ( textNode || ! $newElement.is( 'p' ) ) { |
| 7107 | + newElementHTML += '<p class="wikiEditor">' + pieces[i] + '</p>'; |
| 7108 | + } else { |
| 7109 | + newElementHTML += pieces[i]; |
| 7110 | + } |
| 7111 | + } else if ( textNode || ! $newElement.is( 'p' ) ) { |
| 7112 | + newElementHTML += '<br class="wikiEditor" >'; |
7090 | 7113 | } |
| 7114 | + |
| 7115 | + if ( !textNode ) { |
| 7116 | + newElementHTML += '<br class="wikiEditor" >'; |
| 7117 | + } |
7091 | 7118 | } |
7092 | | - $newElement.html( newElementHTML ) |
7093 | | - .addClass( 'wikiEditor' ) |
7094 | | - .insertAfter( $currentElement ); |
| 7119 | + |
| 7120 | + $newElement.html( newElementHTML ).addClass( 'wikiEditor' ); |
| 7121 | + |
| 7122 | + //remove extra <br>s |
| 7123 | + if ( $newElement.is( 'p' ) && $currentElement[0].nextSibling != null && $( $currentElement[0].nextSibling ).is( 'br' ) ) { |
| 7124 | + $( $currentElement[0].nextSibling ).remove(); |
| 7125 | + } |
| 7126 | + //swap out the original content with with newly sanitized one |
| 7127 | + $newElement.insertAfter( $currentElement ); |
7095 | 7128 | $currentElement.remove(); |
7096 | 7129 | |
7097 | 7130 | $selection = context.$content.find( ':not(.wikiEditor)' ); |
— | — | @@ -7101,10 +7134,14 @@ |
7102 | 7135 | context.$content.removeClass( 'pasting' ); |
7103 | 7136 | } |
7104 | 7137 | |
| 7138 | + |
7105 | 7139 | // Restore cursor position |
7106 | 7140 | context.fn.purgeOffsets(); |
7107 | 7141 | var newLength = context.fn.getContents().length; |
7108 | 7142 | var restoreTo = cursorPos[0] + newLength - oldLength; |
| 7143 | + if ( restoreTo > newLength ) { |
| 7144 | + restoreTo = newLength; |
| 7145 | + } |
7109 | 7146 | context.fn.setSelection( { start: restoreTo, end: restoreTo } ); |
7110 | 7147 | }, 0 ); |
7111 | 7148 | return true; |
— | — | @@ -8226,10 +8263,10 @@ |
8227 | 8264 | end = e ? e.offset : null; |
8228 | 8265 | // Don't try to set the selection past the end of a node, causes errors |
8229 | 8266 | // Just put the selection at the end of the node in this case |
8230 | | - if ( sc.nodeName == '#text' && start > sc.nodeValue.length ) { |
| 8267 | + if ( sc != null && sc.nodeName == '#text' && start > sc.nodeValue.length ) { |
8231 | 8268 | start = sc.nodeValue.length - 1; |
8232 | 8269 | } |
8233 | | - if ( ec.nodeName == '#text' && end > ec.nodeValue.length ) { |
| 8270 | + if ( ec != null && ec.nodeName == '#text' && end > ec.nodeValue.length ) { |
8234 | 8271 | end = ec.nodeValue.length - 1; |
8235 | 8272 | } |
8236 | 8273 | } |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -401,9 +401,9 @@ |
402 | 402 | context.data.$textbox.trigger('change');} |
403 | 403 | $.suggestions.special(context);},keypress:function(e,context,key){var wasVisible=context.data.$container.is(':visible');var preventDefault=false;switch(key){case 40:if(wasVisible){$.suggestions.highlight(context,'next',false);}else{$.suggestions.update(context,false);} |
404 | 404 | preventDefault=true;break;case 38:if(wasVisible){$.suggestions.highlight(context,'prev',false);} |
405 | | -preventDefault=wasVisible;break;case 27:context.data.$container.hide();$.suggestions.restore(context);$.suggestions.cancel(context);context.data.$textbox.trigger('change');preventDefault=wasVisible;break;case 13:context.data.$container.hide();preventDefault=wasVisible;selected=context.data.$container.find('.suggestions-result-current');if(selected.is('.suggestions-special')){if(typeof context.config.special.select=='function'){context.config.special.select.call(selected,context.data.$textbox);}}else{if(typeof context.config.result.select=='function'){$.suggestions.highlight(context,selected,true);context.config.result.select.call(selected,context.data.$textbox);}else{$.suggestions.highlight(context,selected,true);}} |
| 405 | +preventDefault=wasVisible;break;case 27:context.data.$container.hide();$.suggestions.restore(context);$.suggestions.cancel(context);context.data.$textbox.trigger('change');preventDefault=wasVisible;break;case 13:context.data.$container.hide();preventDefault=wasVisible;selected=context.data.$container.find('.suggestions-result-current');if(selected.size()==0){$.suggestions.cancel(context);context.config.$region.closest('form').submit();}else if(selected.is('.suggestions-special')){if(typeof context.config.special.select=='function'){context.config.special.select.call(selected,context.data.$textbox);}}else{if(typeof context.config.result.select=='function'){$.suggestions.highlight(context,selected,true);context.config.result.select.call(selected,context.data.$textbox);}else{$.suggestions.highlight(context,selected,true);}} |
406 | 406 | break;default:$.suggestions.update(context,true);break;} |
407 | | -if(preventDefault){e.preventDefault();e.stopImmediatePropagation();}}};$.fn.suggestions=function(){var returnValue=null;var args=arguments;$(this).each(function(){var context=$(this).data('suggestions-context');if(typeof context=='undefined'){context={config:{'fetch':function(){},'cancel':function(){},'special':{},'result':{},'$region':$(this),'suggestions':[],'maxRows':7,'delay':120,'submitOnClick':false}};} |
| 407 | +if(preventDefault){e.preventDefault();e.stopImmediatePropagation();}}};$.fn.suggestions=function(){var returnValue=null;var args=arguments;$(this).each(function(){var context=$(this).data('suggestions-context');if(typeof context=='undefined'||context==null){context={config:{'fetch':function(){},'cancel':function(){},'special':{},'result':{},'$region':$(this),'suggestions':[],'maxRows':7,'delay':120,'submitOnClick':false}};} |
408 | 408 | if(args.length>0){if(typeof args[0]=='object'){for(var key in args[0]){$.suggestions.configure(context,key,args[0][key]);}}else if(typeof args[0]=='string'){if(args.length>1){$.suggestions.configure(context,args[0],args[1]);}else if(returnValue==null){returnValue=(args[0]in context.config?undefined:context.config[args[0]]);}}} |
409 | 409 | if(typeof context.data=='undefined'){context.data={'timerID':null,'prevText':null,'visibleResults':0,'mouseDownOn':$([]),'$textbox':$(this)};context.data.$container=$('<div />').css({'top':Math.round(context.data.$textbox.offset().top+context.data.$textbox.outerHeight()),'left':Math.round(context.data.$textbox.offset().left),'width':context.data.$textbox.outerWidth(),'display':'none'}).addClass('suggestions').append($('<div />').addClass('suggestions-results').mousedown(function(e){context.data.mouseDownOn=$(e.target).closest('.suggestions-results div');}).mouseup(function(e){var $result=$(e.target).closest('.suggestions-results div');var $other=context.data.mouseDownOn;context.data.mouseDownOn=$([]);if($result.get(0)!=$other.get(0)){return;} |
410 | 410 | $.suggestions.highlight(context,$result,true);context.data.$container.hide();if(typeof context.config.result.select=='function'){context.config.result.select.call($result,context.data.$textbox);} |
— | — | @@ -444,7 +444,7 @@ |
445 | 445 | options.endContainer=options.startContainer;break;case'scrollToCaretPosition':options=$.extend({'force':false},options);break;} |
446 | 446 | var context=$(this).data('wikiEditor-context');var hasIframe=context!==undefined&&context.$iframe!==undefined;var needSave=false;if(hasIframe&&context.savedSelection!==null){context.fn.restoreSelection();needSave=true;} |
447 | 447 | retval=(hasIframe?context.fn:fn)[command].call(this,options);if(hasIframe&&needSave){context.fn.saveSelection();} |
448 | | -return retval;};})(jQuery);(function($){$.wikiEditor={'modules':{},'instances':[],'browsers':{'ltr':{'msie':[['>=',7]],'firefox':[['>=',2]],'opera':[['>=',9.6]],'safari':[['>=',3]],'chrome':[['>=',3]],'blackberry':false,'ipod':false,'iphone':false},'rtl':{'msie':[['>=',8]],'firefox':[['>=',2]],'opera':[['>=',9.6]],'safari':[['>=',3]],'chrome':[['>=',3]],'blackberry':false,'ipod':false,'iphone':false}},'imgPath':wgScriptPath+'/extensions/UsabilityInitiative/images/wikiEditor/','isSupported':function(module){var mod=module&&'browsers'in module?module:$.wikiEditor;if(typeof mod.supported!=='undefined'){return mod.supported;} |
| 448 | +return retval;};})(jQuery);(function($){$.wikiEditor={'modules':{},'instances':[],'browsers':{'ltr':{'msie':[['>=',7]],'firefox':[['>=',2]],'opera':[['>=',9.6]],'safari':[['>=',3]],'chrome':[['>=',3]],'blackberry':false,'ipod':false,'iphone':false},'rtl':{'msie':[['>=',8]],'firefox':[['>=',2]],'opera':[['>=',9.6]],'safari':[['>=',3]],'chrome':[['>=',3]],'blackberry':false,'ipod':false,'iphone':false}},'imgPath':wgScriptPath+'/extensions/UsabilityInitiative/images/wikiEditor/','isSupported':function(module){var mod=module&&'browsers'in module?module:$.wikiEditor;return mod.supported=true;if(typeof mod.supported!=='undefined'){return mod.supported;} |
449 | 449 | if(!($.browser.name in mod.browsers[$('body').is('.rtl')?'rtl':'ltr'])){return mod.supported=true;} |
450 | 450 | var browser=mod.browsers[$('body').is('.rtl')?'rtl':'ltr'][$.browser.name];if(typeof browser!='object'){return mod.supported=false;} |
451 | 451 | for(var condition in browser){var op=browser[condition][0];var val=browser[condition][1];if(val===false){return mod.supported=false;}else if(typeof val=='string'){if(!(eval('$.browser.version'+op+'"'+val+'"'))){return mod.supported=false;}}else if(typeof val=='number'){if(!(eval('$.browser.versionNumber'+op+val))){return mod.supported=false;}}} |
— | — | @@ -464,14 +464,20 @@ |
465 | 465 | return true;},'change':function(event){event.data.scope='division';var newHTML=context.$content.html();if(context.oldHTML!=newHTML){context.fn.purgeOffsets();context.oldHTML=newHTML;event.data.scope='realchange';} |
466 | 466 | if(context.$content.children().length==0){context.$content.append('<p></p>');} |
467 | 467 | return true;},'delayedChange':function(event){event.data.scope='division';var newHTML=context.$content.html();if(context.oldDelayedHTML!=newHTML){context.oldDelayedHTML=newHTML;event.data.scope='realchange';var cursorPos=context.fn.getCaretPosition();var t=context.fn.getOffset(cursorPos[0]);if(t&&t.node.nodeName=='#text'&&t.node.parentNode.nodeName.toLowerCase()=='body'){$(t.node).wrap("<p></p>");context.fn.purgeOffsets();context.fn.setSelection({start:cursorPos[0],end:cursorPos[1]});}} |
468 | | -context.fn.updateHistory(event.data.scope=='realchange');return true;},'cut':function(event){setTimeout(function(){context.$content.find('br').each(function(){if($(this).parent().is('body')){$(this).wrap($('<p></p>'));}});},100);return true;},'paste':function(event){var cursorPos=context.fn.getCaretPosition();var oldLength=context.fn.getContents().length-(cursorPos[1]-cursorPos[0]);context.$content.find(':not(.wikiEditor)').addClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.addClass('pasting');} |
469 | | -setTimeout(function(){context.$content.find('script,style,img,input,select,textarea,hr,button,link,meta').remove();context.$content.find('*').each(function(){if($(this).children().length==0&&this.childNodes.length>0){$(this).text($(this).text());}});context.$content.find('p:not(.wikiEditor) p:not(.wikiEditor)').each(function(){var outerParent=$(this).parent();outerParent.replaceWith(outerParent.childNodes);});context.$content.find('span.Apple-style-span').each(function(){$(this).replaceWith(this.childNodes);});var pasteContent=context.fn.getOffset(cursorPos[0]).node;var removeNextBR=false;while(pasteContent!=null&&!$(pasteContent).hasClass('wikiEditor')){var currentNode=pasteContent;pasteContent=pasteContent.nextSibling;if(currentNode.nodeName=='#text'&¤tNode.nodeValue==currentNode.wholeText){var pWrapper=$('<p />').addClass('wikiEditor');$(currentNode).wrap(pWrapper);$(currentNode).addClass('wikiEditor');removeNextBR=true;}else if(currentNode.nodeName=='BR'&&removeNextBR){$(currentNode).remove();removeNextBR=false;}else{removeNextBR=false;}} |
470 | | -var $selection=context.$content.find(':not(.wikiEditor)');while($selection.length&&$selection.length>0){var $currentElement=$selection.eq(0);while(!$currentElement.parent().is('body')&&!$currentElement.parent().is('.wikiEditor')){$currentElement=$currentElement.parent();} |
471 | | -var $newElement;if($currentElement.is('p')||$currentElement.is('div')||$currentElement.is('pre')){$newElement=$('<p />');}else{$newElement=$('<span />').addClass('wikiEditor');} |
472 | | -var pieces=$.trim($currentElement.text()).split('\n');var newElementHTML='';for(var i=0;i<pieces.length;i++){if(pieces[i]){newElementHTML+=$.trim(pieces[i]);}else{newElementHTML+='<span><br class="wikiEditor" /></span>';}} |
473 | | -$newElement.html(newElementHTML).addClass('wikiEditor').insertAfter($currentElement);$currentElement.remove();$selection=context.$content.find(':not(.wikiEditor)');} |
| 468 | +context.fn.updateHistory(event.data.scope=='realchange');return true;},'cut':function(event){setTimeout(function(){context.$content.find('br').each(function(){if($(this).parent().is('body')){$(this).wrap($('<p></p>'));}});},100);return true;},'paste':function(event){var cursorPos=context.fn.getCaretPosition();if(!context.$content.text()){context.$content.empty();} |
| 469 | +var oldLength=context.fn.getContents().length;context.$content.find('*').addClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.addClass('pasting');} |
| 470 | +setTimeout(function(){context.$content.find('script,style,img,input,select,textarea,hr,button,link,meta').remove();context.$content.find('*').each(function(){if($(this).children().length==0&&this.childNodes.length>0){$(this).text($(this).text());}});context.$content.find('p:not(.wikiEditor) p:not(.wikiEditor)').each(function(){var outerParent=$(this).parent();outerParent.replaceWith(outerParent.childNodes);});if(!$.browser.msie){context.$content.find('span.Apple-style-span').each(function(){$(this).replaceWith(this.childNodes);});} |
| 471 | +var $selection=context.$content.find(':not(.wikiEditor)');var $previousElement;while($selection.length&&$selection.length>0){var $currentElement=$selection.eq(0);while(!$currentElement.parent().is('body')&&!$currentElement.parent().is('.wikiEditor')){$currentElement=$currentElement.parent();} |
| 472 | +while($currentElement[0]!=null&&$currentElement[0].previousSibling!=null&&!$($currentElement[0].previousSibling).hasClass('wikiEditor')){$currentElement=$($currentElement[0].previousSibling);} |
| 473 | +var $newElement;var textNode=false;if($currentElement[0].nodeName=='#text'){$newElement=$('<p></p>');textNode=true;}else if($currentElement.is('p')||$currentElement.is('pre')||$currentElement.is('br')){$newElement=$('<p></p>');}else{$newElement=$('<span></span>');} |
| 474 | +var newElementHTML='';var currentHTML='';if($currentElement[0].nodeName=='#text'){currentHTML=$currentElement[0].nodeValue;}else{currentHTML=$currentElement.html();currentHTML=currentHTML.replace(/(<[\s]*p[^>]*>)|(<[\s]*\/p[^>]*>)|(<[\s]*p[^\/>]*\/>)/gi,'\n');currentHTML=currentHTML.replace(/(<[^>]*>)|(<[^\>]*\>)/gi,'');} |
| 475 | +var pieces=currentHTML.split('\n');for(var i=0;i<pieces.length;i++){if(pieces[i]){if(textNode||!$newElement.is('p')){newElementHTML+='<p class="wikiEditor">'+pieces[i]+'</p>';}else{newElementHTML+=pieces[i];}}else if(textNode||!$newElement.is('p')){newElementHTML+='<br class="wikiEditor" >';} |
| 476 | +if(!textNode){newElementHTML+='<br class="wikiEditor" >';}} |
| 477 | +$newElement.html(newElementHTML).addClass('wikiEditor');if($newElement.is('p')&&$currentElement[0].nextSibling!=null&&$($currentElement[0].nextSibling).is('br')){$($currentElement[0].nextSibling).remove();} |
| 478 | +$newElement.insertAfter($currentElement);$currentElement.remove();$selection=context.$content.find(':not(.wikiEditor)');} |
474 | 479 | context.$content.find('.wikiEditor').removeClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.removeClass('pasting');} |
475 | | -context.fn.purgeOffsets();var newLength=context.fn.getContents().length;var restoreTo=cursorPos[0]+newLength-oldLength;context.fn.setSelection({start:restoreTo,end:restoreTo});},0);return true;},'ready':function(event){context.history.push({'html':context.$content.html(),'sel':context.fn.getCaretPosition()});return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};} |
| 480 | +context.fn.purgeOffsets();var newLength=context.fn.getContents().length;var restoreTo=cursorPos[0]+newLength-oldLength;if(restoreTo>newLength){restoreTo=newLength;} |
| 481 | +context.fn.setSelection({start:restoreTo,end:restoreTo});},0);return true;},'ready':function(event){context.history.push({'html':context.$content.html(),'sel':context.fn.getCaretPosition()});return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};} |
476 | 482 | if(typeof event.data=='undefined'){event.data={};} |
477 | 483 | if(name in context.evt){if(!context.evt[name](event)){return false;}} |
478 | 484 | var returnFromModules=null;for(var module in context.modules){if(module in $.wikiEditor.modules&&'evt'in $.wikiEditor.modules[module]&&name in $.wikiEditor.modules[module].evt){var ret=$.wikiEditor.modules[module].evt[name](context,event);if(ret!=null){if(returnFromModules==null){returnFromModules=ret;}else{returnFromModules=returnFromModules&&ret;}}}} |
— | — | @@ -561,8 +567,8 @@ |
562 | 568 | if(periRange.text==periText){rawPeriText+="\r\n";}else{periFinished=true;}}} |
563 | 569 | if(!postFinished){if(postRange.compareEndPoints("StartToEnd",postRange)==0){postFinished=true;}else{postRange.moveEnd("character",-1) |
564 | 570 | if(postRange.text==postText){rawPostText+="\r\n";}else{postFinished=true;}}}}while((!postFinished||!periFinished||!postFinished));startPos=rawPreText.replace(/\r\n/g,"\n").length;endPos=startPos+rawPeriText.replace(/\r\n/g,"\n").length;}catch(e){startPos=endPos=0;}} |
565 | | -return[startPos,endPos];},'setSelection':function(options){var sc=options.startContainer,ec=options.endContainer;sc=sc&&sc.jquery?sc[0]:sc;ec=ec&&ec.jquery?ec[0]:ec;if(context.$iframe[0].contentWindow.getSelection){var start=options.start,end=options.end;if(!sc||!ec){var s=context.fn.getOffset(start);var e=context.fn.getOffset(end);sc=s?s.node:null;ec=e?e.node:null;start=s?s.offset:null;end=e?e.offset:null;if(sc.nodeName=='#text'&&start>sc.nodeValue.length){start=sc.nodeValue.length-1;} |
566 | | -if(ec.nodeName=='#text'&&end>ec.nodeValue.length){end=ec.nodeValue.length-1;}} |
| 571 | +return[startPos,endPos];},'setSelection':function(options){var sc=options.startContainer,ec=options.endContainer;sc=sc&&sc.jquery?sc[0]:sc;ec=ec&&ec.jquery?ec[0]:ec;if(context.$iframe[0].contentWindow.getSelection){var start=options.start,end=options.end;if(!sc||!ec){var s=context.fn.getOffset(start);var e=context.fn.getOffset(end);sc=s?s.node:null;ec=e?e.node:null;start=s?s.offset:null;end=e?e.offset:null;if(sc!=null&&sc.nodeName=='#text'&&start>sc.nodeValue.length){start=sc.nodeValue.length-1;} |
| 572 | +if(ec!=null&&ec.nodeName=='#text'&&end>ec.nodeValue.length){end=ec.nodeValue.length-1;}} |
567 | 573 | if(!sc||!ec){return context.$textarea;} |
568 | 574 | var sel=context.$iframe[0].contentWindow.getSelection();while(sc.firstChild&&sc.nodeName!='#text'){sc=sc.firstChild;} |
569 | 575 | while(ec.firstChild&&ec.nodeName!='#text'){ec=ec.firstChild;} |