Merge pull request #206 from github/backport-js

Backport JS
This commit is contained in:
Joshua Peek
2011-09-28 13:44:27 -07:00
3 changed files with 594 additions and 562 deletions
@@ -62,7 +62,7 @@
// get form fields // get form fields
var oldAction = $('#gollum-editor form').attr('action'); var oldAction = $('#gollum-editor form').attr('action');
var $form = $($('#gollum-editor form').get(0)); var $form = $($('#gollum-editor form').get(0));
$form.attr('action', '/preview'); $form.attr('action', this.href || '/preview');
$form.attr('target', '_blank'); $form.attr('target', '_blank');
$form.submit(); $form.submit();
@@ -154,7 +154,13 @@
define: function( name, definitionObject ) { define: function( name, definitionObject ) {
LanguageDefinition._ACTIVE_LANG = name; LanguageDefinition._ACTIVE_LANG = name;
LanguageDefinition._LOADED_LANGS.push( name ); LanguageDefinition._LOADED_LANGS.push( name );
LanguageDefinition._LANG[name] = definitionObject; if ( typeof $.GollumEditor.WikiLanguage == 'object' ) {
var definition = {};
$.extend(definition, $.GollumEditor.WikiLanguage, definitionObject);
LanguageDefinition._LANG[name] = definition;
} else {
LanguageDefinition._LANG[name] = definitionObject;
}
}, },
getActiveLanguage: function() { getActiveLanguage: function() {
@@ -776,226 +782,221 @@
var Help = { var Help = {
_ACTIVE_HELP: '', _ACTIVE_HELP: '',
_LOADED_HELP_LANGS: [], _LOADED_HELP_LANGS: [],
_HELP: {}, _HELP: {},
/**
* Help.define
*
* Defines a new help context and enables the help function if it
* exists in the Gollum Function Bar.
*
* @param string name The name you're giving to this help context.
* Generally, this should match the language name.
* @param object definitionObject The definition object being loaded from a
* language / help definition file.
* @return void
*/
define: function( name, definitionObject ) {
if ( Help.isValidHelpFormat( definitionObject ) ) {
debug('help is a valid format');
Help._ACTIVE_HELP_LANG = name;
Help._LOADED_HELP_LANGS.push( name );
Help._HELP[name] = definitionObject;
if ( $("#function-help").length ) {
if ( $('#function-help').hasClass('disabled') ) {
$('#function-help').removeClass('disabled');
}
$('#function-help').unbind('click');
$('#function-help').click( Help.evtHelpButtonClick );
// generate help menus
Help.generateHelpMenuFor( name );
if ( $('#gollum-editor-help').length &&
typeof $('#gollum-editor-help').attr('data-autodisplay') !== 'undefined' &&
$('#gollum-editor-help').attr('data-autodisplay') === 'true' ) {
Help.show();
}
}
} else {
if ( $('#function-help').length ) {
$('#function-help').addClass('disabled');
}
}
},
/**
* Help.generateHelpMenuFor
* Generates the markup for the main help menu given a context name.
*
* @param string name The context name.
* @return void
*/
generateHelpMenuFor: function( name ) {
if ( !Help._HELP[name] ) {
debug('Help is not defined for ' + name.toString());
return false;
}
var helpData = Help._HELP[name];
if ( EditorHas.mathJax() && Help.isLoadedFor('mathjax') ) {
debug('Adding MathJax support to help');
// TODO
}
// clear this shiz out
$('#gollum-editor-help-parent').html('');
$('#gollum-editor-help-list').html('');
$('#gollum-editor-help-content').html('');
// go go inefficient algorithm
for ( var i=0; i < helpData.length; i++ ) {
if ( typeof helpData[i] != 'object' ) {
break;
}
var $newLi = $('<li><a href="#" rel="' + i + '">' +
helpData[i].menuName + '</a></li>');
$('#gollum-editor-help-parent').append( $newLi );
if ( i === 0 ) {
// select on first run
$newLi.children('a').addClass('selected');
}
$newLi.children('a').click( Help.evtParentMenuClick );
}
// generate parent submenu on first run
Help.generateSubMenu( helpData[0], 0 );
$($('#gollum-editor-help-list li a').get(0)).click();
},
/**
* Help.generateSubMenu
* Generates the markup for the inline help sub-menu given the data
* object for the submenu and the array index to start at.
*
* @param object subData The data for the sub-menu.
* @param integer index The index clicked on (parent menu index).
* @return void
*/
generateSubMenu: function( subData, index ) {
$('#gollum-editor-help-list').html('');
$('#gollum-editor-help-content').html('');
for ( var i=0; i < subData.content.length; i++ ) {
if ( typeof subData.content[i] != 'object' ) {
break;
}
var $subLi = $('<li><a href="#" rel="' + index + ':' + i + '">' +
subData.content[i].menuName + '</a></li>');
/** $('#gollum-editor-help-list').append( $subLi );
* Help.define $subLi.children('a').click( Help.evtSubMenuClick );
* }
* Defines a new help context and enables the help function if it },
* exists in the Gollum Function Bar.
*
* @param string name The name you're giving to this help context.
* Generally, this should match the language name.
* @param object definitionObject The definition object being loaded from a
* language / help definition file.
* @return void
*/
define: function( name, definitionObject ) {
if ( Help.isValidHelpFormat( definitionObject ) ) {
debug('help is a valid format');
Help._ACTIVE_HELP_LANG = name; hide: function() {
Help._LOADED_HELP_LANGS.push( name ); if ( $.browser.msie ) {
Help._HELP[name] = definitionObject; $('#gollum-editor-help').css('display', 'none');
} else {
$('#gollum-editor-help').animate({
opacity: 0
}, 200, function() {
$('#gollum-editor-help')
.animate({ height: 'hide' }, 200);
});
}
},
if ( $("#function-help").length ) { show: function() {
if ( $('#function-help').hasClass('disabled') ) { if ( $.browser.msie ) {
$('#function-help').removeClass('disabled'); // bypass effects for internet explorer, since it does weird crap
} // to text antialiasing with opacity animations
$('#function-help').unbind('click'); $('#gollum-editor-help').css('display', 'block');
$('#function-help').click( Help.evtHelpButtonClick ); } else {
$('#gollum-editor-help').animate({
height: 'show'
}, 200, function() {
$('#gollum-editor-help')
.animate({ opacity: 1 }, 300);
});
}
},
// generate help menus /**
Help.generateHelpMenuFor( name ); * Help.showHelpFor
} * Displays the actual help content given the two menu indexes, which are
} else { * rendered in the rel="" attributes of the help menus
if ( $('#function-help').length ) { *
$('#function-help').addClass('disabled'); * @param integer index1 parent index
} * @param integer index2 submenu index
} * @return void
}, */
showHelpFor: function( index1, index2 ) {
var html =
Help._HELP[Help._ACTIVE_HELP_LANG][index1].content[index2].data;
$('#gollum-editor-help-content').html(html);
},
/**
* Help.isLoadedFor
* Returns true if help is loaded for a specific markup language,
* false otherwise.
*
* @param string name The name of the markup language.
* @return boolean
*/
isLoadedFor: function( name ) {
for ( var i=0; i < Help._LOADED_HELP_LANGS.length; i++ ) {
if ( name == Help._LOADED_HELP_LANGS[i] ) {
return true;
}
}
return false;
},
/** isShown: function() {
* Help.generateHelpMenuFor return ($('#gollum-editor-help').is(':visible'));
* Generates the markup for the main help menu given a context name. },
*
* @param string name The context name.
* @return void
*/
generateHelpMenuFor: function( name ) {
if ( !Help._HELP[name] ) {
debug('Help is not defined for ' + name.toString());
return false;
}
var helpData = Help._HELP[name];
if ( EditorHas.mathJax() && Help.isLoadedFor('mathjax') ) { /**
debug('Adding MathJax support to help'); * Help.isValidHelpFormat
// TODO * Does a quick check to make sure that the help definition isn't in a
} * completely messed-up format.
*
* @param object (Array) helpArr The help definition array.
* @return boolean
*/
isValidHelpFormat: function( helpArr ) {
return ( typeof helpArr == 'object' &&
helpArr.length &&
typeof helpArr[0].menuName == 'string' &&
typeof helpArr[0].content == 'object' &&
helpArr[0].content.length );
},
// clear this shiz out /**
$('#gollum-editor-help-parent').html(''); * Help.setActiveHelp
$('#gollum-editor-help-list').html(''); * Sets the active help definition to the one defined in the argument,
$('#gollum-editor-help-content').html(''); * re-rendering the help menu to match the new definition.
*
// go go inefficient algorithm * @param string name The name of the help definition.
for ( var i=0; i < helpData.length; i++ ) { * @return void
if ( typeof helpData[i] != 'object' ) { */
break; setActiveHelp: function( name ) {
} if ( !Help.isLoadedFor( name ) ) {
if ( $('#function-help').length ) {
var $newLi = $('<li><a href="#" rel="' + i + '">' + $('#function-help').addClass('disabled');
helpData[i].menuName + '</a></li>'); }
$('#gollum-editor-help-parent').append( $newLi ); if ( Help.isShown() ) {
if ( i === 0 ) { Help.hide();
// select on first run }
$newLi.children('a').addClass('selected'); } else {
}
$newLi.children('a').click( Help.evtParentMenuClick );
}
// generate parent submenu on first run
Help.generateSubMenu( helpData[0], 0 );
$($('#gollum-editor-help-list li a').get(0)).click();
},
/**
* Help.generateSubMenu
* Generates the markup for the inline help sub-menu given the data
* object for the submenu and the array index to start at.
*
* @param object subData The data for the sub-menu.
* @param integer index The index clicked on (parent menu index).
* @return void
*/
generateSubMenu: function( subData, index ) {
$('#gollum-editor-help-list').html('');
$('#gollum-editor-help-content').html('');
for ( var i=0; i < subData.content.length; i++ ) {
if ( typeof subData.content[i] != 'object' ) {
break;
}
var $subLi = $('<li><a href="#" rel="' + index + ':' + i + '">' +
subData.content[i].menuName + '</a></li>');
$('#gollum-editor-help-list').append( $subLi );
$subLi.children('a').click( Help.evtSubMenuClick );
}
},
hide: function() {
if ( $.browser.msie ) {
$('#gollum-editor-help').css('display', 'none');
} else {
$('#gollum-editor-help').animate({
opacity: 0
}, 200,
function() {
$('#gollum-editor-help')
.animate({ height: 'hide' }, 200);
});
}
},
show: function() {
if ( $.browser.msie ) {
// bypass effects for internet explorer, since it does weird crap
// to text antialiasing with opacity animations
$('#gollum-editor-help').css('display', 'block');
} else {
$('#gollum-editor-help').animate({
height: 'show'
}, 200,
function() {
$('#gollum-editor-help')
.animate({ opacity: 1 }, 300);
});
}
},
/**
* Help.showHelpFor
* Displays the actual help content given the two menu indexes, which are
* rendered in the rel="" attributes of the help menus
*
* @param integer index1 parent index
* @param integer index2 submenu index
* @return void
*/
showHelpFor: function( index1, index2 ) {
var html =
Help._HELP[Help._ACTIVE_HELP_LANG][index1].content[index2].data;
$('#gollum-editor-help-content').html(html);
},
/**
* Help.isLoadedFor
* Returns true if help is loaded for a specific markup language,
* false otherwise.
*
* @param string name The name of the markup language.
* @return boolean
*/
isLoadedFor: function( name ) {
for ( var i=0; i < Help._LOADED_HELP_LANGS.length; i++ ) {
if ( name == Help._LOADED_HELP_LANGS[i] ) {
return true;
}
}
return false;
},
isShown: function() {
return ( $('#gollum-editor-help').is(':visible') );
},
/**
* Help.isValidHelpFormat
* Does a quick check to make sure that the help definition isn't in a
* completely messed-up format.
*
* @param object (Array) helpArr The help definition array.
* @return boolean
*/
isValidHelpFormat: function( helpArr ) {
return ( typeof helpArr == 'object' &&
helpArr.length &&
typeof helpArr[0].menuName == 'string' &&
typeof helpArr[0].content == 'object' &&
helpArr[0].content.length );
},
/**
* Help.setActiveHelp
* Sets the active help definition to the one defined in the argument,
* re-rendering the help menu to match the new definition.
*
* @param string name The name of the help definition.
* @return void
*/
setActiveHelp: function( name ) {
if ( !Help.isLoadedFor( name ) ) {
if ( $('#function-help').length ) {
$('#function-help').addClass('disabled');
}
if ( Help.isShown() ) {
Help.hide();
}
} else {
Help._ACTIVE_HELP_LANG = name; Help._ACTIVE_HELP_LANG = name;
if ( $("#function-help").length ) { if ( $("#function-help").length ) {
if ( $('#function-help').hasClass('disabled') ) { if ( $('#function-help').hasClass('disabled') ) {
@@ -1005,80 +1006,84 @@
$('#function-help').click( Help.evtHelpButtonClick ); $('#function-help').click( Help.evtHelpButtonClick );
Help.generateHelpMenuFor( name ); Help.generateHelpMenuFor( name );
} }
} }
}, },
/**
* Help.evtHelpButtonClick
* Event handler for clicking the help button in the function bar.
*
* @param jQuery.Event e The jQuery event object.
* @return void
*/
evtHelpButtonClick: function( e ) {
e.preventDefault();
if ( Help.isShown() ) {
// turn off autodisplay if it's on
if ( $('#gollum-editor-help').length &&
$('#gollum-editor-help').attr('data-autodisplay') !== 'undefined' &&
$('#gollum-editor-help').attr('data-autodisplay') === 'true' ) {
$.post('/wiki/help?_method=delete');
$('#gollum-editor-help').attr('data-autodisplay', '');
}
Help.hide(); }
else { Help.show(); }
},
/** /**
* Help.evtHelpButtonClick * Help.evtParentMenuClick
* Event handler for clicking the help button in the function bar. * Event handler for clicking on an item in the parent menu. Automatically
* * renders the submenu for the parent menu as well as the first result for
* @param jQuery.Event e The jQuery event object. * the actual plain text.
* @return void *
*/ * @param jQuery.Event e The jQuery event object.
evtHelpButtonClick: function( e ) { * @return void
e.preventDefault(); */
if ( Help.isShown() ) { Help.hide(); } evtParentMenuClick: function( e ) {
else { Help.show(); } e.preventDefault();
}, // short circuit if we've selected this already
if ( $(this).hasClass('selected') ) { return; }
// populate from help data for this
var helpIndex = $(this).attr('rel');
var subData = Help._HELP[Help._ACTIVE_HELP_LANG][helpIndex];
/** $('#gollum-editor-help-parent li a').removeClass('selected');
* Help.evtParentMenuClick $(this).addClass('selected');
* Event handler for clicking on an item in the parent menu. Automatically Help.generateSubMenu( subData, helpIndex );
* renders the submenu for the parent menu as well as the first result for $($('#gollum-editor-help-list li a').get(0)).click();
* the actual plain text. },
*
* @param jQuery.Event e The jQuery event object.
* @return void
*/
evtParentMenuClick: function( e ) {
e.preventDefault();
// short circuit if we've selected this already
if ( $(this).hasClass('selected') ) { return; }
// populate from help data for this /**
var helpIndex = $(this).attr('rel'); * Help.evtSubMenuClick
var subData = Help._HELP[Help._ACTIVE_HELP_LANG][helpIndex]; * Event handler for clicking an item in a help submenu. Renders the
* appropriate text for the submenu link.
*
* @param jQuery.Event e The jQuery event object.
* @return void
*/
evtSubMenuClick: function( e ) {
e.preventDefault();
if ( $(this).hasClass('selected') ) { return; }
$('#gollum-editor-help-parent li a').removeClass('selected'); // split index rel data
$(this).addClass('selected'); var rawIndex = $(this).attr('rel').split(':');
Help.generateSubMenu( subData, helpIndex ); $('#gollum-editor-help-list li a').removeClass('selected');
$($('#gollum-editor-help-list li a').get(0)).click(); $(this).addClass('selected');
}, Help.showHelpFor( rawIndex[0], rawIndex[1] );
}
};
// Publicly-accessible function to Help.define
$.GollumEditor.defineHelp = Help.define;
/** // Dialog exists as its own thing now
* Help.evtSubMenuClick $.GollumEditor.Dialog = $.GollumDialog;
* Event handler for clicking an item in a help submenu. Renders the $.GollumEditor.replaceSelection = function( repText ) {
* appropriate text for the submenu link. FunctionBar.replaceFieldSelection( $('#gollum-editor-body'), repText );
* };
* @param jQuery.Event e The jQuery event object.
* @return void
*/
evtSubMenuClick: function( e ) {
e.preventDefault();
if ( $(this).hasClass('selected') ) { return; }
// split index rel data // Placeholder exists as its own thing now
var rawIndex = $(this).attr('rel').split(':'); $.GollumEditor.Placeholder = $.GollumPlaceholder;
$('#gollum-editor-help-list li a').removeClass('selected');
$(this).addClass('selected');
Help.showHelpFor( rawIndex[0], rawIndex[1] );
}
};
// Publicly-accessible function to Help.define
$.GollumEditor.defineHelp = Help.define;
// Dialog exists as its own thing now
$.GollumEditor.Dialog = $.GollumDialog;
$.GollumEditor.replaceSelection = function( repText ) {
FunctionBar.replaceFieldSelection( $('#gollum-editor-body'), repText );
};
// Placeholder exists as its own thing now
$.GollumEditor.Placeholder = $.GollumPlaceholder;
})(jQuery); })(jQuery);
@@ -7,74 +7,98 @@
(function($) { (function($) {
var Dialog = { var Dialog = {
debugOn: false, debugOn: false,
markupCreated: false, markupCreated: false,
markup: '',
attachEvents: function( evtOK ) { attachEvents: function( evtOK ) {
$('#gollum-dialog-action-ok').click(function( e ) { $('#gollum-dialog-action-ok').click(function( e ) {
Dialog.eventOK( e, evtOK ); Dialog.eventOK( e, evtOK );
}); });
$('#gollum-dialog-action-cancel').click( Dialog.eventCancel ); $('#gollum-dialog-action-cancel').click( Dialog.eventCancel );
}, $('#gollum-dialog-dialog input[type="text"]').keydown(function( e ) {
if ( e.keyCode == 13 ) {
Dialog.eventOK( e, evtOK );
}
});
},
createFieldMarkup: function( fieldArray ) { detachEvents: function() {
var fieldMarkup = '<fieldset>'; $('#gollum-dialog-action-ok').unbind('click');
for ( var i=0; i < fieldArray.length; i++ ) { $('#gollum-dialog-action-cancel').unbind('click');
if ( typeof fieldArray[i] == 'object' ) { },
fieldMarkup += '<div class="field">';
switch ( fieldArray[i].type ) {
// only text is supported for now createFieldMarkup: function( fieldArray ) {
case 'text': var fieldMarkup = '<fieldset>';
fieldMarkup += Dialog.createFieldText( fieldArray[i] ); for ( var i=0; i < fieldArray.length; i++ ) {
break; if ( typeof fieldArray[i] == 'object' ) {
fieldMarkup += '<div class="field">';
switch ( fieldArray[i].type ) {
default: // only text is supported for now
break; case 'text':
fieldMarkup += Dialog.createFieldText( fieldArray[i] );
break;
} default:
fieldMarkup += '</div>'; break;
}
} }
fieldMarkup += '</fieldset>'; fieldMarkup += '</div>';
return fieldMarkup; }
},
createFieldText: function( fieldAttributes ) { }
var html = ''; fieldMarkup += '</fieldset>';
return fieldMarkup;
},
if ( fieldAttributes.name ) { createFieldText: function( fieldAttributes ) {
html += '<label'; var html = '';
if ( fieldAttributes.id ) {
html += ' for="' + fieldAttributes.name + '"';
}
html += '>' + fieldAttributes.name + '</label>';
}
html += '<input type="text"'; if ( fieldAttributes.name ) {
html += '<label';
if ( fieldAttributes.id ) {
html += ' for="' + fieldAttributes.name + '"';
}
html += '>' + fieldAttributes.name + '</label>';
}
if ( fieldAttributes.id ) { html += '<input type="text"';
html += ' name="' + fieldAttributes.id + '"'
if ( fieldAttributes.type == 'code' ) {
html+= ' class="code"';
}
html += ' id="gollum-dialog-dialog-generated-field-' +
fieldAttributes.id + '">';
}
return html; if ( fieldAttributes.id ) {
}, html += ' name="' + fieldAttributes.id + '"'
if ( fieldAttributes.type == 'code' ) {
html+= ' class="code"';
}
html += ' id="gollum-dialog-dialog-generated-field-' +
fieldAttributes.id + '">';
}
createMarkup: function( title, body ) { return html;
Dialog.markupCreated = true; },
return '<div id="gollum-dialog-dialog">' +
createMarkup: function( title, body ) {
Dialog.markupCreated = true;
if ($.facebox) {
return '<div id="gollum-dialog-dialog">' +
'<div id="gollum-dialog-dialog-title"><h4>' +
title +'</h4></div>' +
'<div id="gollum-dialog-dialog-body">' + body + '</div>' +
'<div id="gollum-dialog-dialog-buttons">' +
'<a href="#" title="Cancel" id="gollum-dialog-action-cancel" ' +
'class="gollum-minibutton">Cancel</a>' +
'<a href="#" title="OK" id="gollum-dialog-action-ok" '+
'class="gollum-minibutton">OK</a>' +
'</div>' +
'</div>';
} else {
return '<div id="gollum-dialog-dialog">' +
'<div id="gollum-dialog-dialog-inner">' + '<div id="gollum-dialog-dialog-inner">' +
'<div id="gollum-dialog-dialog-bg">' + '<div id="gollum-dialog-dialog-bg">' +
'<div id="gollum-dialog-dialog-title"><h4>' + '<div id="gollum-dialog-dialog-title"><h4>' +
title +'</h4></div>' + title +'</h4></div>' +
'<div id="gollum-dialog-dialog-body">' + body + '</div>' + '<div id="gollum-dialog-dialog-body">' + body + '</div>' +
'<div id="gollum-dialog-dialog-buttons">' + '<div id="gollum-dialog-dialog-buttons">' +
'<a href="#" title="Cancel" id="gollum-dialog-action-cancel" ' + '<a href="#" title="Cancel" id="gollum-dialog-action-cancel" ' +
@@ -85,86 +109,113 @@
'</div>' + '</div>' +
'</div>' + '</div>' +
'</div>'; '</div>';
}, }
},
eventCancel: function( e ) { eventCancel: function( e ) {
e.preventDefault(); e.preventDefault();
debug('Cancelled dialog.'); debug('Cancelled dialog.');
Dialog.hide(); Dialog.hide();
}, },
eventOK: function( e, evtOK ) { eventOK: function( e, evtOK ) {
e.preventDefault(); e.preventDefault();
var results = []; var results = [];
// get the results from each field and build them into the object // get the results from each field and build them into the object
$('#gollum-dialog-dialog-body input').each(function() { $('#gollum-dialog-dialog-body input').each(function() {
results[$(this).attr('name')] = $(this).val(); results[$(this).attr('name')] = $(this).val();
}); });
// pass them to evtOK if it exists (which it should) // pass them to evtOK if it exists (which it should)
if ( evtOK && if ( evtOK &&
typeof evtOK == 'function' ) { typeof evtOK == 'function' ) {
evtOK( results ); evtOK( results );
} }
Dialog.hide(); Dialog.hide();
}, },
hide: function() { hide: function() {
if ( $.browser.msie ) { if ( $.facebox ) {
$('#gollum-dialog-dialog').hide().removeClass('active'); Dialog.markupCreated = false;
$('select').css('visibility', 'visible'); $(document).trigger('close.facebox');
} else { Dialog.detachEvents();
$('#gollum-dialog-dialog').animate({ opacity: 0 }, { } else {
if ( $.browser.msie ) {
$('#gollum-dialog-dialog').hide().removeClass('active');
$('select').css('visibility', 'visible');
} else {
$('#gollum-dialog-dialog').animate({ opacity: 0 }, {
duration: 200, duration: 200,
complete: function() { complete: function() {
$('#gollum-dialog-dialog').removeClass('active'); $('#gollum-dialog-dialog').removeClass('active');
} }
}); });
} }
}, }
},
init: function( argObject ) { init: function( argObject ) {
var title = ''; var title = '';
var body = ''; var body = '';
// bail out if necessary // bail out if necessary
if ( !argObject || if ( !argObject ||
typeof argObject != 'object' ) { typeof argObject != 'object' ) {
debug('Editor Dialog: Cannot init; invalid init object'); debug('Editor Dialog: Cannot init; invalid init object');
return; return;
} }
if ( argObject.body && typeof argObject.body == 'string' ) { if ( argObject.body && typeof argObject.body == 'string' ) {
body = '<p>' + argObject.body + '</p>'; body = '<p>' + argObject.body + '</p>';
} }
// alright, build out fields // alright, build out fields
if ( argObject.fields && typeof argObject.fields == 'object' ) { if ( argObject.fields && typeof argObject.fields == 'object' ) {
body += Dialog.createFieldMarkup( argObject.fields ); body += Dialog.createFieldMarkup( argObject.fields );
} }
if ( argObject.title && typeof argObject.title == 'string' ) { if ( argObject.title && typeof argObject.title == 'string' ) {
title = argObject.title; title = argObject.title;
} }
if ( Dialog.markupCreated ) { if ( Dialog.markupCreated ) {
$('#gollum-dialog-dialog').remove(); if ($.facebox) {
} $(document).trigger('close.facebox');
var $dialog = $( Dialog.createMarkup( title, body ) ); } else {
$('body').append( $dialog ); $('#gollum-dialog-dialog').remove();
if ( argObject.OK && }
typeof argObject.OK == 'function' ) { }
Dialog.attachEvents( argObject.OK );
}
Dialog.show();
},
show: function() { Dialog.markup = Dialog.createMarkup( title, body );
if ( !Dialog.markupCreated ) {
debug('Dialog: No markup to show. Please use init first.'); if ($.facebox) {
} else { $(document).bind('reveal.facebox', function() {
debug('Showing dialog'); if ( argObject.OK &&
typeof argObject.OK == 'function' ) {
Dialog.attachEvents( argObject.OK );
$($('#facebox input[type="text"]').get(0)).focus();
}
});
} else {
$('body').append( Dialog.markup );
if ( argObject.OK &&
typeof argObject.OK == 'function' ) {
Dialog.attachEvents( argObject.OK );
}
}
Dialog.show();
},
show: function() {
if ( !Dialog.markupCreated ) {
debug('Dialog: No markup to show. Please use init first.');
} else {
debug('Showing dialog');
if ($.facebox) {
$.facebox( Dialog.markup );
} else {
if ( $.browser.msie ) { if ( $.browser.msie ) {
$('#gollum-dialog.dialog').addClass('active'); $('#gollum-dialog.dialog').addClass('active');
Dialog.position(); Dialog.position();
@@ -177,23 +228,29 @@
$('#gollum-dialog-dialog').css('display', 'block'); $('#gollum-dialog-dialog').css('display', 'block');
Dialog.position(); // position this thing Dialog.position(); // position this thing
$('#gollum-dialog-dialog').animate({ opacity: 1 }, { $('#gollum-dialog-dialog').animate({ opacity: 1 }, {
duration: 500 duration: 500
}); });
} }
}); });
} }
} }
}, }
},
position: function() {
var dialogHeight = $('#gollum-dialog-dialog-inner').height();
$('#gollum-dialog-dialog-inner')
.css('height', dialogHeight + 'px')
.css('margin-top', -1 * parseInt( dialogHeight / 2 ));
}
position: function() {
var dialogHeight = $('#gollum-dialog-dialog-inner').height();
$('#gollum-dialog-dialog-inner')
.css('height', dialogHeight + 'px')
.css('margin-top', -1 * parseInt( dialogHeight / 2 ));
}
}; };
if ($.facebox) {
$(document).bind('reveal.facebox', function() {
$('#facebox img.close_image').remove();
});
}
var debug = function(m) { var debug = function(m) {
if ( Dialog.debugOn if ( Dialog.debugOn
&& typeof console != 'undefined' ) { && typeof console != 'undefined' ) {
+85 -115
View File
@@ -1,5 +1,87 @@
// ua // ua
$(document).ready(function() { $(document).ready(function() {
var nodeSelector = {
node1: null,
node2: null,
selectNodeRange: function( n1, n2 ) {
if ( nodeSelector.node1 && nodeSelector.node2 ) {
$('#wiki-history td.selected').removeClass('selected');
nodeSelector.node1.addClass('selected');
nodeSelector.node2.addClass('selected');
// swap the nodes around if they went in reverse
if ( nodeSelector.nodeComesAfter( nodeSelector.node1,
nodeSelector.node2 ) ) {
var n = nodeSelector.node1;
nodeSelector.node1 = nodeSelector.node2;
nodeSelector.node2 = n;
}
var s = true;
var $nextNode = nodeSelector.node1.next();
while ( $nextNode ) {
$nextNode.addClass('selected');
if ( $nextNode[0] == nodeSelector.node2[0] ) {
break;
}
$nextNode = $nextNode.next();
}
}
},
nodeComesAfter: function ( n1, n2 ) {
var s = false;
$(n1).prevAll().each(function() {
if ( $(this)[0] == $(n2)[0] ) {
s = true;
}
});
return s;
},
checkNode: function( nodeCheckbox ) {
var $nodeCheckbox = nodeCheckbox;
var $node = $(nodeCheckbox).parent().parent();
// if we're unchecking
if ( !$nodeCheckbox.is(':checked') ) {
// remove the range, since we're breaking it
$('#wiki-history tr.selected').each(function() {
if ( $(this).find('td.checkbox input').is(':checked') ) {
return;
}
$(this).removeClass('selected');
});
// no longer track this
if ( $node[0] == nodeSelector.node1[0] ) {
nodeSelector.node1 = null;
if ( nodeSelector.node2 ) {
nodeSelector.node1 = nodeSelector.node2;
nodeSelector.node2 = null;
}
} else if ( $node[0] == nodeSelector.node2[0] ) {
nodeSelector.node2 = null;
}
} else {
if ( !nodeSelector.node1 ) {
nodeSelector.node1 = $node;
nodeSelector.node1.addClass('selected');
} else if ( !nodeSelector.node2 ) {
// okay, we don't have a node 2 but have a node1
nodeSelector.node2 = $node;
nodeSelector.node2.addClass('selected');
nodeSelector.selectNodeRange( nodeSelector.node1,
nodeSelector.node2 );
} else {
// we have two selected already
$nodeCheckbox[0].checked = false;
}
}
}
};
// ua detection // ua detection
if ($.browser.mozilla) { if ($.browser.mozilla) {
@@ -41,7 +123,9 @@ $(document).ready(function() {
if ($('#wiki-wrapper').hasClass('history')) { if ($('#wiki-wrapper').hasClass('history')) {
$('#wiki-history td.checkbox input').each(function() { $('#wiki-history td.checkbox input').each(function() {
$(this).click(highlightChecked); $(this).click(function() {
nodeSelector.checkNode($(this));
});
if ( $(this).is(':checked') ) { if ( $(this).is(':checked') ) {
nodeSelector.checkNode($(this)); nodeSelector.checkNode($(this));
} }
@@ -54,8 +138,6 @@ $(document).ready(function() {
} }
} }
if ($('#searchbar a#search-submit').length) { if ($('#searchbar a#search-submit').length) {
$.GollumPlaceholder.add($('#searchbar #search-query')); $.GollumPlaceholder.add($('#searchbar #search-query'));
$('#searchbar a#search-submit').click(function(e) { $('#searchbar a#search-submit').click(function(e) {
@@ -76,116 +158,4 @@ $(document).ready(function() {
$('#gollum-revert-form').submit(); $('#gollum-revert-form').submit();
}); });
} }
}); });
var nodeSelector = {
node1: null,
node2: null,
selectNodeRange: function( n1, n2 ) {
if ( nodeSelector.node1 && nodeSelector.node2 ) {
$('#wiki-history td.selected').removeClass('selected');
nodeSelector.node1.addClass('selected');
nodeSelector.node2.addClass('selected');
// swap the nodes around if they went in reverse
if ( nodeSelector.nodeComesAfter( nodeSelector.node1,
nodeSelector.node2 ) ) {
var n = nodeSelector.node1;
nodeSelector.node1 = nodeSelector.node2;
nodeSelector.node2 = n;
}
var s = true;
var $nextNode = nodeSelector.node1.next();
while ( $nextNode ) {
$nextNode.addClass('selected');
if ( $nextNode[0] == nodeSelector.node2[0] ) {
break;
}
$nextNode = $nextNode.next();
}
}
},
nodeComesAfter: function ( n1, n2 ) {
var s = false;
$(n1).prevAll().each(function() {
if ( $(this)[0] == $(n2)[0] ) {
s = true;
}
});
return s;
},
checkNode: function( nodeCheckbox ) {
var $nodeCheckbox = nodeCheckbox;
var $node = $(nodeCheckbox).parent().parent();
// if we're unchecking
if ( !$nodeCheckbox.is(':checked') ) {
// remove the range, since we're breaking it
$('#wiki-history tr.selected').each(function() {
if ( $(this).find('td.checkbox input').is(':checked') ) {
return;
}
$(this).removeClass('selected');
});
// no longer track this
if ( $node[0] == nodeSelector.node1[0] ) {
nodeSelector.node1 = null;
if ( nodeSelector.node2 ) {
nodeSelector.node1 = nodeSelector.node2;
nodeSelector.node2 = null;
}
} else if ( $node[0] == nodeSelector.node2[0] ) {
nodeSelector.node2 = null;
}
} else {
if ( !nodeSelector.node1 ) {
nodeSelector.node1 = $node;
nodeSelector.node1.addClass('selected');
} else if ( !nodeSelector.node2 ) {
// okay, we don't have a node 2 but have a node1
nodeSelector.node2 = $node;
nodeSelector.node2.addClass('selected');
nodeSelector.selectNodeRange( nodeSelector.node1,
nodeSelector.node2 );
} else {
// we have two selected already
$nodeCheckbox[0].checked = false;
}
}
}
};
function highlightOn() {
$(this).parent().parent().animate({
backgroundColor: '#ffffea',
duration: 400
});
}
function highlightOff() {
var color = '#ebf2f6';
if ($(this).parent().parent().hasClass('alt-row')) {
color = '#f3f7fa';
}
$(this).parent().parent().animate({
backgroundColor: color,
duration: 400
});
}
function highlightChecked() {
nodeSelector.checkNode($(this));
}
function initMathJax() {
}