Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toolbar.js |
— | — | @@ -456,6 +456,9 @@ |
457 | 457 | .attr( 'href', '#' ) |
458 | 458 | .text( $.wikiEditor.autoMsg( section, 'label' ) ) |
459 | 459 | .data( 'context', context ) |
| 460 | + .bind( 'mouseup', function( e ) { |
| 461 | + $(this).blur(); |
| 462 | + } ) |
460 | 463 | .bind( 'mousedown', function( e ) { |
461 | 464 | // Only act when the primary mouse button was pressed |
462 | 465 | if ( e.button !== 0 ) { |
— | — | @@ -464,7 +467,6 @@ |
465 | 468 | var $sections = $(this).data( 'context' ).$ui.find( '.sections' ); |
466 | 469 | var $section = |
467 | 470 | $(this).data( 'context' ).$ui.find( '.section-' + $(this).parent().attr( 'rel' ) ); |
468 | | - $(this).blur(); |
469 | 471 | var show = $section.css( 'display' ) == 'none'; |
470 | 472 | $previousSections = $section.parent().find( '.section:visible' ); |
471 | 473 | $previousSections.css( 'position', 'absolute' ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -2101,11 +2101,17 @@ |
2102 | 2102 | .attr( 'href', '#' ) |
2103 | 2103 | .text( $.wikiEditor.autoMsg( section, 'label' ) ) |
2104 | 2104 | .data( 'context', context ) |
2105 | | - .bind( 'mousedown', function() { |
| 2105 | + .bind( 'mouseup', function( e ) { |
| 2106 | + $(this).blur(); |
| 2107 | + } ) |
| 2108 | + .bind( 'mousedown', function( e ) { |
| 2109 | + // Only act when the primary mouse button was pressed |
| 2110 | + if ( e.button !== 0 ) { |
| 2111 | + return true; |
| 2112 | + } |
2106 | 2113 | var $sections = $(this).data( 'context' ).$ui.find( '.sections' ); |
2107 | 2114 | var $section = |
2108 | 2115 | $(this).data( 'context' ).$ui.find( '.section-' + $(this).parent().attr( 'rel' ) ); |
2109 | | - $(this).blur(); |
2110 | 2116 | var show = $section.css( 'display' ) == 'none'; |
2111 | 2117 | $previousSections = $section.parent().find( '.section:visible' ); |
2112 | 2118 | $previousSections.css( 'position', 'absolute' ); |
— | — | @@ -2510,3 +2516,106 @@ |
2511 | 2517 | width: "13em" |
2512 | 2518 | } |
2513 | 2519 | } ) ( jQuery ); |
| 2520 | +/** |
| 2521 | + * Code Module for wikiEditor |
| 2522 | + */ |
| 2523 | +( function( $ ) { $.wikiEditor.modules.code = { |
| 2524 | + |
| 2525 | +/** |
| 2526 | + * API accessible functions |
| 2527 | + */ |
| 2528 | +api: { |
| 2529 | + // |
| 2530 | +}, |
| 2531 | +/** |
| 2532 | + * Internally used functions |
| 2533 | + */ |
| 2534 | +fn: { |
| 2535 | + // Create the iframe and set things up |
| 2536 | + create: function( context, config ) { |
| 2537 | + context.$iframe = $( '<iframe></iframe>' ) |
| 2538 | + .attr( 'frameborder', 0 ) |
| 2539 | + .css( { |
| 2540 | + 'backgroundColor': 'white', |
| 2541 | + 'width': '100%', |
| 2542 | + 'height': context.$textarea.height(), |
| 2543 | + 'display': 'none' |
| 2544 | + }) |
| 2545 | + .insertAfter( context.$textarea ); |
| 2546 | + context.$iframe[0].contentWindow.document.open(); |
| 2547 | + context.$iframe[0].contentWindow.document.write( |
| 2548 | + '<html><head><title>wikiEditor</title></head><body style="margin:0;padding:0;width:100%;height:100%;">' + |
| 2549 | + '<pre style="margin:0;padding:0;width:100%;height:100%;white-space:pre-wrap;"></pre></body></html>' |
| 2550 | + ); |
| 2551 | + context.$iframe[0].contentWindow.document.close(); |
| 2552 | + context.$iframe[0].contentWindow.document.designMode = 'on'; |
| 2553 | + context.modules.code = { |
| 2554 | + 'editor': { |
| 2555 | + 'container': context.$iframe.contents().find( 'body > pre' ), |
| 2556 | + 'active': false, |
| 2557 | + 'config': {} |
| 2558 | + } |
| 2559 | + }; |
| 2560 | + // Make it happen! |
| 2561 | + $.wikiEditor.modules.code.fn.active( context, true ); |
| 2562 | + }, |
| 2563 | + // Set config / get config |
| 2564 | + config: function( context, config ) { |
| 2565 | + if ( config != undefined ) { |
| 2566 | + $.extend( context.modules.code.editor.config, config ); |
| 2567 | + } else { |
| 2568 | + return context.modules.code.editor.config; |
| 2569 | + } |
| 2570 | + }, |
| 2571 | + // Set code / get code to whichever control (textarea or iframe) is active |
| 2572 | + code: function( context, code ) { |
| 2573 | + if ( code !== undefined ) { |
| 2574 | + // Set |
| 2575 | + context.modules.code.editor.active ? |
| 2576 | + context.modules.code.editor.container.text( code ) : context.$textarea.val( code ); |
| 2577 | + } else { |
| 2578 | + // Get |
| 2579 | + context.modules.code.editor.active ? |
| 2580 | + context.modules.code.editor.container.text() : context.$textarea.val(); |
| 2581 | + } |
| 2582 | + }, |
| 2583 | + // Lock / unlock / get locked state of all editing controls |
| 2584 | + locked: function( context, value ) { |
| 2585 | + if ( value !== undefined ) { |
| 2586 | + if ( value ) { |
| 2587 | + context.$textarea.attr( 'readonly', true ); |
| 2588 | + if ( context.$iframe.css( 'display' ) != 'none' ) { // prevent exception on FF + iframe with display:none |
| 2589 | + context.$iframe.attr( 'readonly', true ); |
| 2590 | + } |
| 2591 | + } else { |
| 2592 | + context.$textarea.attr( 'readonly', false ); |
| 2593 | + if ( context.$iframe.css( 'display' ) != 'none' ) { // prevent exception on FF + iframe with display:none |
| 2594 | + context.$iframe.attr( 'readonly', false ); |
| 2595 | + } |
| 2596 | + } |
| 2597 | + } else { |
| 2598 | + return context.modules.code.editor.active ? |
| 2599 | + context.$iframe.attr( 'readonly' ) : context.$textarea.attr( 'readonly' ); |
| 2600 | + } |
| 2601 | + }, |
| 2602 | + // Activate / deactivate / get active state of the iframe |
| 2603 | + active: function( context, value ) { |
| 2604 | + if ( value !== undefined ) { |
| 2605 | + if ( value && !context.modules.code.editor.active ) { |
| 2606 | + context.$textarea.attr( 'disabled', true ); |
| 2607 | + context.modules.code.editor.container.text( context.$textarea.val() ); |
| 2608 | + context.$textarea.hide(); |
| 2609 | + context.$iframe.show(); |
| 2610 | + } else if ( !value && context.modules.code.editor.active ) { |
| 2611 | + context.$textarea.attr( 'disabled', false ); |
| 2612 | + context.$textarea.val( context.modules.code.editor.container.text() ); |
| 2613 | + context.$textarea.show(); |
| 2614 | + context.$iframe.hide(); |
| 2615 | + } |
| 2616 | + } else { |
| 2617 | + return context.modules.code.editor.active; |
| 2618 | + } |
| 2619 | + } |
| 2620 | +} |
| 2621 | + |
| 2622 | +}; } ) ( jQuery ); |
\ No newline at end of file |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -132,7 +132,8 @@ |
133 | 133 | return html;},buildRow:function(context,row){var html='<tr>';for(cell in row){html+='<td class="cell cell-'+cell+'" valign="top"><span>'+ |
134 | 134 | $.wikiEditor.autoMsg(row[cell],['html','text'])+'</span></td>';} |
135 | 135 | html+='</tr>';return html;},buildCharacter:function(character,actions){if(typeof character=='string'){character={'label':character,'action':{'type':'encapsulate','options':{'pre':character}}};}else if(0 in character&&1 in character){character={'label':character[0],'action':{'type':'encapsulate','options':{'pre':character[1]}}};} |
136 | | -if('action'in character&&'label'in character){actions[character.label]=character.action;return'<a rel="'+character.label+'" href="#">'+character.label+'</a>';}},buildTab:function(context,id,section){var selected=$.cookie('wikiEditor-'+context.instance+'-toolbar-section');return $('<span />').attr({'class':'tab tab-'+id,'rel':id}).append($('<a />').addClass(selected==id?'current':null).attr('href','#').text($.wikiEditor.autoMsg(section,'label')).data('context',context).bind('mousedown',function(){var $sections=$(this).data('context').$ui.find('.sections');var $section=$(this).data('context').$ui.find('.section-'+$(this).parent().attr('rel'));$(this).blur();var show=$section.css('display')=='none';$previousSections=$section.parent().find('.section:visible');$previousSections.css('position','absolute');$previousSections.fadeOut('fast',function(){$(this).css('position','relative');});$(this).parent().parent().find('a').removeClass('current');$sections.css('overflow','hidden');if(show){$section.fadeIn('fast');$sections.animate({'height':$section.outerHeight()},$section.outerHeight()*2,function(){$(this).css('overflow','visible').css('height','auto');});$(this).addClass('current');}else{$sections.css('height',$section.outerHeight()).animate({'height':0},$section.outerHeight()*2,function(){$(this).css('overflow','visible');});} |
| 136 | +if('action'in character&&'label'in character){actions[character.label]=character.action;return'<a rel="'+character.label+'" href="#">'+character.label+'</a>';}},buildTab:function(context,id,section){var selected=$.cookie('wikiEditor-'+context.instance+'-toolbar-section');return $('<span />').attr({'class':'tab tab-'+id,'rel':id}).append($('<a />').addClass(selected==id?'current':null).attr('href','#').text($.wikiEditor.autoMsg(section,'label')).data('context',context).bind('mouseup',function(e){$(this).blur();}).bind('mousedown',function(e){if(e.button!==0){return true;} |
| 137 | +var $sections=$(this).data('context').$ui.find('.sections');var $section=$(this).data('context').$ui.find('.section-'+$(this).parent().attr('rel'));var show=$section.css('display')=='none';$previousSections=$section.parent().find('.section:visible');$previousSections.css('position','absolute');$previousSections.fadeOut('fast',function(){$(this).css('position','relative');});$(this).parent().parent().find('a').removeClass('current');$sections.css('overflow','hidden');if(show){$section.fadeIn('fast');$sections.animate({'height':$section.outerHeight()},$section.outerHeight()*2,function(){$(this).css('overflow','visible').css('height','auto');});$(this).addClass('current');}else{$sections.css('height',$section.outerHeight()).animate({'height':0},$section.outerHeight()*2,function(){$(this).css('overflow','visible');});} |
137 | 138 | if($.trackAction!=undefined){$.trackAction($section.attr('rel')+'.'+(show?'show':'hide'));} |
138 | 139 | $.cookie('wikiEditor-'+$(this).data('context').instance+'-toolbar-section',show?$section.attr('rel'):null);}).click(function(){return false;}));},buildSection:function(context,id,section){context.$textarea.trigger('wikiEditor-toolbar-buildSection-'+id,[section]);var selected=$.cookie('wikiEditor-'+context.instance+'-toolbar-section');var $section;switch(section.type){case'toolbar':var $section=$('<div />').attr({'class':'toolbar section section-'+id,'rel':id});if('groups'in section){for(group in section.groups){$section.append($.wikiEditor.modules.toolbar.fn.buildGroup(context,group,section.groups[group]));}} |
139 | 140 | break;case'booklet':var $pages=$('<div />').addClass('pages');var $index=$('<div />').addClass('index');if('pages'in section){for(page in section.pages){$pages.append($.wikiEditor.modules.toolbar.fn.buildPage(context,page,section.pages[page]));$index.append($.wikiEditor.modules.toolbar.fn.buildBookmark(context,page,section.pages[page]));}} |
— | — | @@ -164,4 +165,4 @@ |
165 | 166 | if(nLevel<=0){nLevel=1;} |
166 | 167 | outline[i].nLevel=nLevel;lastLevel=outline[i].level;} |
167 | 168 | var structure=buildStructure(outline);if($('input[name=wpSection]').val()==''){structure.unshift({'text':wgPageName.replace(/_/g,' '),'level':1,'index':0,'position':0});} |
168 | | -context.modules.$toc.html(buildList(structure));if(wgNavigableTOCCollapseEnable)context.modules.$toc.append(buildCollapseBar());context.modules.$toc.find('div').autoEllipse({'position':'right','tooltip':true});context.data.outline=outline;}}};$.wikiEditor.modules.toc.defaults={width:"13em"}})(jQuery); |
\ No newline at end of file |
| 169 | +context.modules.$toc.html(buildList(structure));if(wgNavigableTOCCollapseEnable)context.modules.$toc.append(buildCollapseBar());context.modules.$toc.find('div').autoEllipse({'position':'right','tooltip':true});context.data.outline=outline;}}};$.wikiEditor.modules.toc.defaults={width:"13em"}})(jQuery);(function($){$.wikiEditor.modules.code={api:{},fn:{create:function(context,config){context.$iframe=$('<iframe></iframe>').attr('frameborder',0).css({'backgroundColor':'white','width':'100%','height':context.$textarea.height(),'display':'none'}).insertAfter(context.$textarea);context.$iframe[0].contentWindow.document.open();context.$iframe[0].contentWindow.document.write('<html><head><title>wikiEditor</title></head><body style="margin:0;padding:0;width:100%;height:100%;">'+'<pre style="margin:0;padding:0;width:100%;height:100%;white-space:pre-wrap;"></pre></body></html>');context.$iframe[0].contentWindow.document.close();context.$iframe[0].contentWindow.document.designMode='on';context.modules.code={'editor':{'container':context.$iframe.contents().find('body > pre'),'active':false,'config':{}}};$.wikiEditor.modules.code.fn.active(context,true);},config:function(context,config){if(config!=undefined){$.extend(context.modules.code.editor.config,config);}else{return context.modules.code.editor.config;}},code:function(context,code){if(code!==undefined){context.modules.code.editor.active?context.modules.code.editor.container.text(code):context.$textarea.val(code);}else{context.modules.code.editor.active?context.modules.code.editor.container.text():context.$textarea.val();}},locked:function(context,value){if(value!==undefined){if(value){context.$textarea.attr('readonly',true);if(context.$iframe.css('display')!='none'){context.$iframe.attr('readonly',true);}}else{context.$textarea.attr('readonly',false);if(context.$iframe.css('display')!='none'){context.$iframe.attr('readonly',false);}}}else{return context.modules.code.editor.active?context.$iframe.attr('readonly'):context.$textarea.attr('readonly');}},active:function(context,value){if(value!==undefined){if(value&&!context.modules.code.editor.active){context.$textarea.attr('disabled',true);context.modules.code.editor.container.text(context.$textarea.val());context.$textarea.hide();context.$iframe.show();}else if(!value&&context.modules.code.editor.active){context.$textarea.attr('disabled',false);context.$textarea.val(context.modules.code.editor.container.text());context.$textarea.show();context.$iframe.hide();}}else{return context.modules.code.editor.active;}}}};})(jQuery); |
\ No newline at end of file |