Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -72,20 +72,20 @@ |
73 | 73 | array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ), |
74 | 74 | array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ), |
75 | 75 | array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 27 ), |
76 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 104 ), |
| 76 | + array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 105 ), |
77 | 77 | array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 29 ), |
78 | 78 | array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 47 ), |
79 | 79 | array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 12 ), |
80 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 78 ), |
| 80 | + array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 79 ), |
81 | 81 | array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 10 ), |
82 | 82 | array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 17 ), |
83 | 83 | array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ), |
84 | 84 | ), |
85 | 85 | 'combined' => array( |
86 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 221 ), |
| 86 | + array( 'src' => 'js/plugins.combined.js', 'version' => 222 ), |
87 | 87 | ), |
88 | 88 | 'minified' => array( |
89 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 221 ), |
| 89 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 222 ), |
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js |
— | — | @@ -257,9 +257,13 @@ |
258 | 258 | * @param {Object} context |
259 | 259 | */ |
260 | 260 | update: function( context ) { |
| 261 | + var div = context.fn.beforeSelection( 'wikiEditor-toc-header' ); |
| 262 | + if ( div === null ) { |
| 263 | + // beforeSelection couldn't figure it out, keep the old highlight state |
| 264 | + return; |
| 265 | + } |
| 266 | + |
261 | 267 | $.wikiEditor.modules.toc.fn.unhighlight( context ); |
262 | | - |
263 | | - var div = context.fn.beforeSelection( 'wikiEditor-toc-header' ); |
264 | 268 | var section = div.data( 'section' ) || 0; |
265 | 269 | if ( context.data.outline.length > 0 ) { |
266 | 270 | var sectionLink = context.modules.toc.$toc.find( 'div.section-' + section ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -833,13 +833,13 @@ |
834 | 834 | * Get the first element before the selection that's in a certain class |
835 | 835 | * @param classname Class to match. Defaults to '', meaning any class |
836 | 836 | * @param strict If true, the element the selection starts in cannot match (default: false) |
837 | | - * @return jQuery object |
| 837 | + * @return jQuery object or null if unknown |
838 | 838 | */ |
839 | 839 | 'beforeSelection': function( classname, strict ) { |
840 | 840 | if ( typeof classname == 'undefined' ) { |
841 | 841 | classname = ''; |
842 | 842 | } |
843 | | - var e, offset; |
| 843 | + var e = null, offset = null; |
844 | 844 | if ( context.$iframe[0].contentWindow.getSelection ) { |
845 | 845 | // Firefox and Opera |
846 | 846 | var selection = context.$iframe[0].contentWindow.getSelection(); |
— | — | @@ -850,9 +850,17 @@ |
851 | 851 | e = selection.getRangeAt( 0 ).startContainer; |
852 | 852 | offset = selection.getRangeAt( 0 ).startOffset; |
853 | 853 | } else { |
854 | | - return $( [] ); |
| 854 | + return null; |
855 | 855 | } |
856 | | - } else if ( context.$iframe[0].contentWindow.document.selection ) { |
| 856 | + |
| 857 | + // When the cursor is on an empty line, Opera gives us a bogus range object with |
| 858 | + // startContainer=endContainer=body and startOffset=endOffset=1 |
| 859 | + var body = context.$iframe[0].contentWindow.document.body; |
| 860 | + if ( $.browser.opera && e == body && offset == 1 ) { |
| 861 | + return null; |
| 862 | + } |
| 863 | + } |
| 864 | + if ( !e && context.$iframe[0].contentWindow.document.selection ) { |
857 | 865 | // IE |
858 | 866 | // Because there's nothing like range.startContainer in IE, we need to do a DOM traversal |
859 | 867 | // to find the element the start of the selection is in |
— | — | @@ -864,14 +872,14 @@ |
865 | 873 | try { |
866 | 874 | range2.setEndPoint( 'EndToStart', range ); |
867 | 875 | } catch ( ex ) { |
868 | | - return $( [] ); |
| 876 | + return null; |
869 | 877 | } |
870 | 878 | var seekPos = context.fn.htmlToText( range2.htmlText ).length; |
871 | 879 | var offset = context.fn.getOffset( seekPos ); |
872 | 880 | e = offset ? offset.node : null; |
873 | 881 | offset = offset ? offset.offset : null; |
874 | 882 | if ( !e ) { |
875 | | - return $( [] ); |
| 883 | + return null; |
876 | 884 | } |
877 | 885 | } |
878 | 886 | if ( e.nodeName != '#text' ) { |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -7266,13 +7266,13 @@ |
7267 | 7267 | * Get the first element before the selection that's in a certain class |
7268 | 7268 | * @param classname Class to match. Defaults to '', meaning any class |
7269 | 7269 | * @param strict If true, the element the selection starts in cannot match (default: false) |
7270 | | - * @return jQuery object |
| 7270 | + * @return jQuery object or null if unknown |
7271 | 7271 | */ |
7272 | 7272 | 'beforeSelection': function( classname, strict ) { |
7273 | 7273 | if ( typeof classname == 'undefined' ) { |
7274 | 7274 | classname = ''; |
7275 | 7275 | } |
7276 | | - var e, offset; |
| 7276 | + var e = null, offset = null; |
7277 | 7277 | if ( context.$iframe[0].contentWindow.getSelection ) { |
7278 | 7278 | // Firefox and Opera |
7279 | 7279 | var selection = context.$iframe[0].contentWindow.getSelection(); |
— | — | @@ -7283,9 +7283,17 @@ |
7284 | 7284 | e = selection.getRangeAt( 0 ).startContainer; |
7285 | 7285 | offset = selection.getRangeAt( 0 ).startOffset; |
7286 | 7286 | } else { |
7287 | | - return $( [] ); |
| 7287 | + return null; |
7288 | 7288 | } |
7289 | | - } else if ( context.$iframe[0].contentWindow.document.selection ) { |
| 7289 | + |
| 7290 | + // When the cursor is on an empty line, Opera gives us a bogus range object with |
| 7291 | + // startContainer=endContainer=body and startOffset=endOffset=1 |
| 7292 | + var body = context.$iframe[0].contentWindow.document.body; |
| 7293 | + if ( $.browser.opera && e == body && offset == 1 ) { |
| 7294 | + return null; |
| 7295 | + } |
| 7296 | + } |
| 7297 | + if ( !e && context.$iframe[0].contentWindow.document.selection ) { |
7290 | 7298 | // IE |
7291 | 7299 | // Because there's nothing like range.startContainer in IE, we need to do a DOM traversal |
7292 | 7300 | // to find the element the start of the selection is in |
— | — | @@ -7297,14 +7305,14 @@ |
7298 | 7306 | try { |
7299 | 7307 | range2.setEndPoint( 'EndToStart', range ); |
7300 | 7308 | } catch ( ex ) { |
7301 | | - return $( [] ); |
| 7309 | + return null; |
7302 | 7310 | } |
7303 | 7311 | var seekPos = context.fn.htmlToText( range2.htmlText ).length; |
7304 | 7312 | var offset = context.fn.getOffset( seekPos ); |
7305 | 7313 | e = offset ? offset.node : null; |
7306 | 7314 | offset = offset ? offset.offset : null; |
7307 | 7315 | if ( !e ) { |
7308 | | - return $( [] ); |
| 7316 | + return null; |
7309 | 7317 | } |
7310 | 7318 | } |
7311 | 7319 | if ( e.nodeName != '#text' ) { |
— | — | @@ -9357,9 +9365,13 @@ |
9358 | 9366 | * @param {Object} context |
9359 | 9367 | */ |
9360 | 9368 | update: function( context ) { |
| 9369 | + var div = context.fn.beforeSelection( 'wikiEditor-toc-header' ); |
| 9370 | + if ( div === null ) { |
| 9371 | + // beforeSelection couldn't figure it out, keep the old highlight state |
| 9372 | + return; |
| 9373 | + } |
| 9374 | + |
9361 | 9375 | $.wikiEditor.modules.toc.fn.unhighlight( context ); |
9362 | | - |
9363 | | - var div = context.fn.beforeSelection( 'wikiEditor-toc-header' ); |
9364 | 9376 | var section = div.data( 'section' ) || 0; |
9365 | 9377 | if ( context.data.outline.length > 0 ) { |
9366 | 9378 | var sectionLink = context.modules.toc.$toc.find( 'div.section-' + section ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -496,8 +496,10 @@ |
497 | 497 | return context.$textarea;},'scrollToCaretPosition':function(options){},'scrollToTop':function($element,force){var html=context.$content.closest('html'),body=context.$content.closest('body'),parentHtml=$('html'),parentBody=$('body');var y=$element.offset().top;if(!$.browser.msie&&!$element.is('body')){y=parentHtml.scrollTop()>0?y+html.scrollTop()-parentHtml.scrollTop():y;y=parentBody.scrollTop()>0?y+body.scrollTop()-parentBody.scrollTop():y;} |
498 | 498 | var topBound=html.scrollTop()>body.scrollTop()?html.scrollTop():body.scrollTop(),bottomBound=topBound+context.$iframe.height();if(force||y<topBound||y>bottomBound){html.scrollTop(y);body.scrollTop(y);} |
499 | 499 | $element.trigger('scrollToTop');},'beforeSelection':function(classname,strict){if(typeof classname=='undefined'){classname='';} |
500 | | -var e,offset;if(context.$iframe[0].contentWindow.getSelection){var selection=context.$iframe[0].contentWindow.getSelection();if(selection.baseNode!==null){e=selection.getRangeAt(0).startContainer;offset=selection.getRangeAt(0).startOffset;}else{return $([]);}}else if(context.$iframe[0].contentWindow.document.selection){var range=context.$iframe[0].contentWindow.document.selection.createRange();var range2=context.$iframe[0].contentWindow.document.body.createTextRange();try{range2.setEndPoint('EndToStart',range);}catch(ex){return $([]);} |
501 | | -var seekPos=context.fn.htmlToText(range2.htmlText).length;var offset=context.fn.getOffset(seekPos);e=offset?offset.node:null;offset=offset?offset.offset:null;if(!e){return $([]);}} |
| 500 | +var e=null,offset=null;if(context.$iframe[0].contentWindow.getSelection){var selection=context.$iframe[0].contentWindow.getSelection();if(selection.baseNode!==null){e=selection.getRangeAt(0).startContainer;offset=selection.getRangeAt(0).startOffset;}else{return null;} |
| 501 | +var body=context.$iframe[0].contentWindow.document.body;if($.browser.opera&&e==body&&offset==1){return null;}} |
| 502 | +if(!e&&context.$iframe[0].contentWindow.document.selection){var range=context.$iframe[0].contentWindow.document.selection.createRange();var range2=context.$iframe[0].contentWindow.document.body.createTextRange();try{range2.setEndPoint('EndToStart',range);}catch(ex){return null;} |
| 503 | +var seekPos=context.fn.htmlToText(range2.htmlText).length;var offset=context.fn.getOffset(seekPos);e=offset?offset.node:null;offset=offset?offset.offset:null;if(!e){return null;}} |
502 | 504 | if(e.nodeName!='#text'){var newE=e.firstChild;for(var i=0;i<offset-1&&newE;i++){newE=newE.nextSibling;} |
503 | 505 | while(newE&&newE.lastChild){newE=newE.lastChild;} |
504 | 506 | e=newE||e;} |
— | — | @@ -637,7 +639,8 @@ |
638 | 640 | context.$wikitext.css({'position':'','height':''});context.$ui.find('.wikiEditor-ui-right').css({'marginRight':'','position':'','left':'','right':'','float':'','top':'','height':''});context.$ui.find('.wikiEditor-ui-left').css({'width':'','position':'','left':'','float':'','right':''});} |
639 | 641 | $.wikiEditor.modules.toc.fn.redraw(context,width);},disable:function(context){if(context.modules.toc.$toc.data('collapsed')){context.$ui.find('.wikiEditor-ui-toc-expandControl').hide();}else{if(context.modules.toc.$toc.data('positionMode')=='goofy'){$.wikiEditor.modules.toc.fn.switchLayout(context);} |
640 | 642 | context.$ui.find('.wikiEditor-ui-right').hide();context.$ui.find('.wikiEditor-ui-left').css('marginRight','').children().css('marginRight','');} |
641 | | -context.modules.toc.$toc.data('positionMode','disabled');},enable:function(context){context.modules.toc.$toc.data('positionMode','regular');if(context.modules.toc.$toc.data('collapsed')){context.$ui.find('.wikiEditor-ui-toc-expandControl').show();}else{context.$ui.find('.wikiEditor-ui-right').show();$.wikiEditor.modules.toc.fn.redraw(context,$.wikiEditor.modules.toc.cfg.minimumWidth);context.modules.toc.$toc.find('div').autoEllipsis({'position':'right','tooltip':true,'restoreText':true});}},unhighlight:function(context){if(context){context.modules.toc.$toc.find('div').removeClass('current');}},update:function(context){$.wikiEditor.modules.toc.fn.unhighlight(context);var div=context.fn.beforeSelection('wikiEditor-toc-header');var section=div.data('section')||0;if(context.data.outline.length>0){var sectionLink=context.modules.toc.$toc.find('div.section-'+section);sectionLink.addClass('current');var relTop=sectionLink.offset().top-context.modules.toc.$toc.offset().top;var scrollTop=context.modules.toc.$toc.scrollTop();var divHeight=context.modules.toc.$toc.height();var sectionHeight=sectionLink.height();if(relTop<0) |
| 643 | +context.modules.toc.$toc.data('positionMode','disabled');},enable:function(context){context.modules.toc.$toc.data('positionMode','regular');if(context.modules.toc.$toc.data('collapsed')){context.$ui.find('.wikiEditor-ui-toc-expandControl').show();}else{context.$ui.find('.wikiEditor-ui-right').show();$.wikiEditor.modules.toc.fn.redraw(context,$.wikiEditor.modules.toc.cfg.minimumWidth);context.modules.toc.$toc.find('div').autoEllipsis({'position':'right','tooltip':true,'restoreText':true});}},unhighlight:function(context){if(context){context.modules.toc.$toc.find('div').removeClass('current');}},update:function(context){var div=context.fn.beforeSelection('wikiEditor-toc-header');if(div===null){return;} |
| 644 | +$.wikiEditor.modules.toc.fn.unhighlight(context);var section=div.data('section')||0;if(context.data.outline.length>0){var sectionLink=context.modules.toc.$toc.find('div.section-'+section);sectionLink.addClass('current');var relTop=sectionLink.offset().top-context.modules.toc.$toc.offset().top;var scrollTop=context.modules.toc.$toc.scrollTop();var divHeight=context.modules.toc.$toc.height();var sectionHeight=sectionLink.height();if(relTop<0) |
642 | 645 | context.modules.toc.$toc.scrollTop(scrollTop+relTop);else if(relTop+sectionHeight>divHeight) |
643 | 646 | context.modules.toc.$toc.scrollTop(scrollTop+relTop+sectionHeight-divHeight);}},collapse:function(event){var $this=$(this),context=$this.data('context');if(context.modules.toc.$toc.data('positionMode')=='goofy'){$.wikiEditor.modules.toc.fn.switchLayout(context);} |
644 | 647 | var pT=$this.parent().position().top-1;context.modules.toc.$toc.data('collapsed',true);context.$ui.find('.wikiEditor-ui-left').animate({'marginRight':'-1px'},'fast',function(){$(this).css('marginRight',0);}).children().animate({'marginRight':'1px'},'fast',function(){$(this).css('marginRight',0);});context.$ui.find('.wikiEditor-ui-right').css({'marginTop':'1px','position':'absolute','left':$.wikiEditor.modules.toc.cfg.rtl?0:'auto','right':$.wikiEditor.modules.toc.cfg.rtl?'auto':0,'top':pT}).fadeOut('fast',function(){$(this).hide().css({'marginTop':'0','width':'1px'});context.$ui.find('.wikiEditor-ui-toc-expandControl').fadeIn('fast');context.fn.trigger('tocCollapse');context.fn.trigger('resize');});$.cookie('wikiEditor-'+context.instance+'-toc-width',0);return false;},expand:function(event){var $this=$(this),context=$this.data('context'),openWidth=parseFloat(context.modules.toc.$toc.data('openWidth')),availableSpace=context.$wikitext.width()-parseFloat($.wikiEditor.modules.toc.cfg.textMinimumWidth);if(availableSpace<$.wikiEditor.modules.toc.cfg.textMinmumWidth)return false;context.modules.toc.$toc.data('collapsed',false);if(availableSpace<openWidth)openWidth=availableSpace;context.$ui.find('.wikiEditor-ui-toc-expandControl').hide();context.$ui.find('.wikiEditor-ui-left').animate({'marginRight':(parseFloat(openWidth)*-1)},'fast').children().animate({'marginRight':openWidth},'fast');context.$ui.find('.wikiEditor-ui-right').show().css('marginTop','1px').animate({'width':openWidth},'fast',function(){context.$content.trigger('mouseup');$(this).css({'marginTop':'0','position':'relative','right':'auto','left':'auto','top':'auto'});context.fn.trigger('tocExpand');context.fn.trigger('resize');});$.cookie('wikiEditor-'+context.instance+'-toc-width',context.modules.toc.$toc.data('openWidth'));return false;},build:function(context){function buildStructure(outline,offset,level){if(offset==undefined)offset=0;if(level==undefined)level=1;var sections=[];for(var i=offset;i<outline.length;i++){if(outline[i].nLevel==level){var sub=buildStructure(outline,i+1,level+1);if(sub.length){outline[i].sections=sub;} |