summaryrefslogtreecommitdiff
path: root/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js')
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js122
1 files changed, 50 insertions, 72 deletions
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js b/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js
index 29899a38..6322b9e7 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js
@@ -84,7 +84,7 @@ api: {
$.wikiEditor.modules.toolbar.fn.buildBookmark( context, page, data[type][page] )
);
}
- $.wikiEditor.modules.toolbar.fn.updateBookletSelection( context, page, $pages, $index );
+ $.wikiEditor.modules.toolbar.fn.updateBookletSelection( context, data.section, $pages, $index );
smooth = false;
break;
case 'rows':
@@ -175,7 +175,7 @@ api: {
context.modules.toolbar.$toolbar.find( index ).remove();
$.wikiEditor.modules.toolbar.fn.updateBookletSelection(
context,
- null,
+ data.section,
context.modules.toolbar.$toolbar.find( target ),
context.modules.toolbar.$toolbar.find( index )
);
@@ -307,29 +307,28 @@ fn: {
var label = $.wikiEditor.autoMsg( tool, 'label' );
switch ( tool.type ) {
case 'button':
- var src = $.wikiEditor.autoIcon( tool.icon, $.wikiEditor.imgPath + 'toolbar/' );
- var $button = null;
- if ( 'offset' in tool ) {
- var offsetOrIcon = $.wikiEditor.autoIconOrOffset( tool.icon, tool.offset,
- $.wikiEditor.imgPath + 'toolbar/'
- );
- if ( typeof offsetOrIcon === 'object' ) {
- $button = $( '<a>' )
- .attr( {
- 'href': '#',
- 'title': label,
- 'rel': id,
- 'role': 'button',
- 'class': 'tool tool-button wikiEditor-toolbar-spritedButton'
- } )
- .text( label )
- .css( 'backgroundPosition', offsetOrIcon[0] + 'px ' + offsetOrIcon[1] + 'px' );
- }
- }
- if ( !$button ) {
+ var $button, offsetOrIcon;
+
+ offsetOrIcon = $.wikiEditor.autoIconOrOffset(
+ tool.icon,
+ tool.offset,
+ $.wikiEditor.imgPath + 'toolbar/'
+ );
+ if ( typeof offsetOrIcon === 'object' ) {
+ $button = $( '<a>' )
+ .attr( {
+ 'href': '#',
+ 'title': label,
+ 'rel': id,
+ 'role': 'button',
+ 'class': 'tool tool-button wikiEditor-toolbar-spritedButton'
+ } )
+ .text( label )
+ .css( 'backgroundPosition', offsetOrIcon[0] + 'px ' + offsetOrIcon[1] + 'px' );
+ } else {
$button = $( '<img>' )
.attr( {
- 'src': src,
+ 'src': offsetOrIcon,
'width': 22,
'height': 22,
'alt': label,
@@ -430,7 +429,7 @@ fn: {
} )
.click( function ( event ) {
$( this ).parent().parent().find( '.page' ).hide();
- $( this ).parent().parent().find( '.page-' + $( this ).attr( 'rel' ) ).show();
+ $( this ).parent().parent().find( '.page-' + $( this ).attr( 'rel' ) ).show().trigger( 'loadPage' );
$( this ).siblings().removeClass( 'current' );
$( this ).addClass( 'current' );
var section = $( this ).parent().parent().attr( 'rel' );
@@ -445,12 +444,24 @@ fn: {
return false;
} );
},
- buildPage: function ( context, id, page ) {
- var html, i;
+ buildPage: function ( context, id, page, deferLoad ) {
var $page = $( '<div>' ).attr( {
'class': 'page page-' + id,
'rel': id
} );
+ if ( deferLoad ) {
+ $page.addClass( 'loading' ).append( $( '<div>' ).addClass( 'spinner' ) );
+ $page.bind( 'loadPage', function () {
+ $.wikiEditor.modules.toolbar.fn.reallyBuildPage( context, id, page, $page );
+ $page.removeClass( 'loading' );
+ } );
+ } else {
+ $.wikiEditor.modules.toolbar.fn.reallyBuildPage( context, id, page, $page );
+ }
+ return $page;
+ },
+ reallyBuildPage: function ( context, id, page, $page ) {
+ var html, i;
switch ( page.layout ) {
case 'table':
$page.addClass( 'page-table' );
@@ -508,11 +519,10 @@ fn: {
$page.append( $characters );
break;
}
- return $page;
},
buildHeading: function ( context, headings ) {
var html = '<tr>';
- for ( var i = 0; i< headings.length; i++ ) {
+ for ( var i = 0; i < headings.length; i++ ) {
html += '<th>' + $.wikiEditor.autoMsg( headings[i], ['html', 'text'] ) + '</th>';
}
return html + '</tr>';
@@ -615,33 +625,18 @@ fn: {
$( this ).parent().parent().find( 'a' ).removeClass( 'current' );
$sections.css( 'overflow', 'hidden' );
- var animate = function ( $that ) {
- $sections
- .animate( { 'height': $section.outerHeight() }, $section.outerHeight() * 2, function () {
- $that.css( 'overflow', 'visible' ).css( 'height', 'auto' );
- context.fn.trigger( 'resize' );
- } );
- };
if ( show ) {
$section.removeClass( 'section-hidden' )
.attr( 'aria-expanded', 'true' )
.animate( { opacity: 100.0 }, 'fast', 'linear', function () {
$( this ).addClass( 'section-visible' );
} );
-
- if ( $section.hasClass( 'loading' ) ) {
- // Loading of this section was deferred, load it now
- var $that = $( this );
- $that.addClass( 'current loading' );
- setTimeout( function () {
- $section.trigger( 'loadSection' );
- animate( $that );
- $that.removeClass( 'loading' );
- }, 1000 );
- } else {
- animate( $( this ) );
- $( this ).addClass( 'current' );
- }
+ $sections
+ .animate( { 'height': $section.outerHeight() }, $section.outerHeight() * 2, function () {
+ $( this ).css( 'overflow', 'visible' ).css( 'height', 'auto' );
+ context.fn.trigger( 'resize' );
+ } );
+ $( this ).addClass( 'current' );
} else {
$sections
.css( 'height', $section.outerHeight() )
@@ -675,16 +670,7 @@ fn: {
var selected = $.cookie( 'wikiEditor-' + context.instance + '-toolbar-section' );
var show = selected === id;
- if ( section.deferLoad !== undefined && section.deferLoad && id !== 'main' && !show ) {
- // This class shows the spinner and serves as a marker for the click handler in buildTab()
- $section.addClass( 'loading' ).append( $( '<div>' ).addClass( 'spinner' ) );
- $section.bind( 'loadSection', function () {
- $.wikiEditor.modules.toolbar.fn.reallyBuildSection( context, id, section, $section );
- $section.removeClass( 'loading' );
- } );
- } else {
- $.wikiEditor.modules.toolbar.fn.reallyBuildSection( context, id, section, $section );
- }
+ $.wikiEditor.modules.toolbar.fn.reallyBuildSection( context, id, section, $section, section.deferLoad );
// Show or hide section
if ( id !== 'main' ) {
@@ -698,7 +684,7 @@ fn: {
}
return $section;
},
- reallyBuildSection: function ( context, id, section, $section ) {
+ reallyBuildSection: function ( context, id, section, $section, deferLoad ) {
context.$textarea.trigger( 'wikiEditor-toolbar-buildSection-' + $section.attr( 'rel' ), [section] );
switch ( section.type ) {
case 'toolbar':
@@ -716,7 +702,7 @@ fn: {
if ( 'pages' in section ) {
for ( var page in section.pages ) {
$pages.append(
- $.wikiEditor.modules.toolbar.fn.buildPage( context, page, section.pages[page] )
+ $.wikiEditor.modules.toolbar.fn.buildPage( context, page, section.pages[page], deferLoad )
);
$index.append(
$.wikiEditor.modules.toolbar.fn.buildBookmark( context, page, section.pages[page] )
@@ -729,21 +715,19 @@ fn: {
}
},
updateBookletSelection: function ( context, id, $pages, $index ) {
- /*jshint eqnull:true */
var cookie = 'wikiEditor-' + context.instance + '-booklet-' + id + '-page';
var selected = $.cookie( cookie );
// Re-save cookie
- if ( selected != null ) {
+ if ( selected !== null ) {
$.cookie( cookie, selected, { expires: 30, path: '/' } );
}
var $selectedIndex = $index.find( '*[rel="' + selected + '"]' );
- if ( $selectedIndex.size() === 0 ) {
+ if ( $selectedIndex.length === 0 ) {
$selectedIndex = $index.children().eq( 0 );
selected = $selectedIndex.attr( 'rel' );
- $.cookie( cookie, selected, { expires: 30, path: '/' } );
}
$pages.children().hide();
- $pages.find( '*[rel="' + selected + '"]' ).show();
+ $pages.find( '*[rel="' + selected + '"]' ).show().trigger( 'loadPage' );
$index.children().removeClass( 'current' );
$selectedIndex.addClass( 'current' );
},
@@ -770,12 +754,6 @@ fn: {
$.eachAsync( sectionQueue, {
'bulk': 0,
'end': function () {
- // HACK: Opera doesn't seem to want to redraw after these bits
- // are added to the DOM, so we can just FORCE it!
- var oldValue = $( 'body' ).css( 'position' );
- $( 'body' ).css( 'position', 'static' );
- $( 'body' ).css( 'position', oldValue );
-
context.$textarea.trigger( 'wikiEditor-toolbar-doneInitialSections' );
},
'loop': function ( i, s ) {