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 );
if ( typeof $.GollumEditor.WikiLanguage == 'object' ) {
var definition = {};
$.extend(definition, $.GollumEditor.WikiLanguage, definitionObject);
LanguageDefinition._LANG[name] = definition;
} else {
LanguageDefinition._LANG[name] = definitionObject; LanguageDefinition._LANG[name] = definitionObject;
}
}, },
getActiveLanguage: function() { getActiveLanguage: function() {
@@ -779,7 +785,6 @@
_LOADED_HELP_LANGS: [], _LOADED_HELP_LANGS: [],
_HELP: {}, _HELP: {},
/** /**
* Help.define * Help.define
* *
@@ -809,6 +814,12 @@
// generate help menus // generate help menus
Help.generateHelpMenuFor( name ); 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 { } else {
if ( $('#function-help').length ) { if ( $('#function-help').length ) {
@@ -817,7 +828,6 @@
} }
}, },
/** /**
* Help.generateHelpMenuFor * Help.generateHelpMenuFor
* Generates the markup for the main help menu given a context name. * Generates the markup for the main help menu given a context name.
@@ -864,7 +874,6 @@
}, },
/** /**
* Help.generateSubMenu * Help.generateSubMenu
* Generates the markup for the inline help sub-menu given the data * Generates the markup for the inline help sub-menu given the data
@@ -891,15 +900,13 @@
} }
}, },
hide: function() { hide: function() {
if ( $.browser.msie ) { if ( $.browser.msie ) {
$('#gollum-editor-help').css('display', 'none'); $('#gollum-editor-help').css('display', 'none');
} else { } else {
$('#gollum-editor-help').animate({ $('#gollum-editor-help').animate({
opacity: 0 opacity: 0
}, 200, }, 200, function() {
function() {
$('#gollum-editor-help') $('#gollum-editor-help')
.animate({ height: 'hide' }, 200); .animate({ height: 'hide' }, 200);
}); });
@@ -914,15 +921,13 @@
} else { } else {
$('#gollum-editor-help').animate({ $('#gollum-editor-help').animate({
height: 'show' height: 'show'
}, 200, }, 200, function() {
function() {
$('#gollum-editor-help') $('#gollum-editor-help')
.animate({ opacity: 1 }, 300); .animate({ opacity: 1 }, 300);
}); });
} }
}, },
/** /**
* Help.showHelpFor * Help.showHelpFor
* Displays the actual help content given the two menu indexes, which are * Displays the actual help content given the two menu indexes, which are
@@ -938,7 +943,6 @@
$('#gollum-editor-help-content').html(html); $('#gollum-editor-help-content').html(html);
}, },
/** /**
* Help.isLoadedFor * Help.isLoadedFor
* Returns true if help is loaded for a specific markup language, * Returns true if help is loaded for a specific markup language,
@@ -956,12 +960,10 @@
return false; return false;
}, },
isShown: function() { isShown: function() {
return ($('#gollum-editor-help').is(':visible')); return ($('#gollum-editor-help').is(':visible'));
}, },
/** /**
* Help.isValidHelpFormat * Help.isValidHelpFormat
* Does a quick check to make sure that the help definition isn't in a * Does a quick check to make sure that the help definition isn't in a
@@ -978,7 +980,6 @@
helpArr[0].content.length ); helpArr[0].content.length );
}, },
/** /**
* Help.setActiveHelp * Help.setActiveHelp
* Sets the active help definition to the one defined in the argument, * Sets the active help definition to the one defined in the argument,
@@ -1008,7 +1009,6 @@
} }
}, },
/** /**
* Help.evtHelpButtonClick * Help.evtHelpButtonClick
* Event handler for clicking the help button in the function bar. * Event handler for clicking the help button in the function bar.
@@ -1018,11 +1018,18 @@
*/ */
evtHelpButtonClick: function( e ) { evtHelpButtonClick: function( e ) {
e.preventDefault(); e.preventDefault();
if ( Help.isShown() ) { Help.hide(); } 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(); } else { Help.show(); }
}, },
/** /**
* Help.evtParentMenuClick * Help.evtParentMenuClick
* Event handler for clicking on an item in the parent menu. Automatically * Event handler for clicking on an item in the parent menu. Automatically
@@ -1047,7 +1054,6 @@
$($('#gollum-editor-help-list li a').get(0)).click(); $($('#gollum-editor-help-list li a').get(0)).click();
}, },
/** /**
* Help.evtSubMenuClick * Help.evtSubMenuClick
* Event handler for clicking an item in a help submenu. Renders the * Event handler for clicking an item in a help submenu. Renders the
@@ -1068,7 +1074,6 @@
} }
}; };
// Publicly-accessible function to Help.define // Publicly-accessible function to Help.define
$.GollumEditor.defineHelp = Help.define; $.GollumEditor.defineHelp = Help.define;
@@ -11,12 +11,23 @@
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 );
}
});
},
detachEvents: function() {
$('#gollum-dialog-action-ok').unbind('click');
$('#gollum-dialog-action-cancel').unbind('click');
}, },
createFieldMarkup: function( fieldArray ) { createFieldMarkup: function( fieldArray ) {
@@ -70,6 +81,19 @@
createMarkup: function( title, body ) { createMarkup: function( title, body ) {
Dialog.markupCreated = true; 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">' + 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">' +
@@ -85,6 +109,7 @@
'</div>' + '</div>' +
'</div>' + '</div>' +
'</div>'; '</div>';
}
}, },
eventCancel: function( e ) { eventCancel: function( e ) {
@@ -111,6 +136,11 @@
}, },
hide: function() { hide: function() {
if ( $.facebox ) {
Dialog.markupCreated = false;
$(document).trigger('close.facebox');
Dialog.detachEvents();
} else {
if ( $.browser.msie ) { if ( $.browser.msie ) {
$('#gollum-dialog-dialog').hide().removeClass('active'); $('#gollum-dialog-dialog').hide().removeClass('active');
$('select').css('visibility', 'visible'); $('select').css('visibility', 'visible');
@@ -122,6 +152,7 @@
} }
}); });
} }
}
}, },
init: function( argObject ) { init: function( argObject ) {
@@ -149,14 +180,31 @@
} }
if ( Dialog.markupCreated ) { if ( Dialog.markupCreated ) {
if ($.facebox) {
$(document).trigger('close.facebox');
} else {
$('#gollum-dialog-dialog').remove(); $('#gollum-dialog-dialog').remove();
} }
var $dialog = $( Dialog.createMarkup( title, body ) ); }
$('body').append( $dialog );
Dialog.markup = Dialog.createMarkup( title, body );
if ($.facebox) {
$(document).bind('reveal.facebox', function() {
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 && if ( argObject.OK &&
typeof argObject.OK == 'function' ) { typeof argObject.OK == 'function' ) {
Dialog.attachEvents( argObject.OK ); Dialog.attachEvents( argObject.OK );
} }
}
Dialog.show(); Dialog.show();
}, },
@@ -165,6 +213,9 @@
debug('Dialog: No markup to show. Please use init first.'); debug('Dialog: No markup to show. Please use init first.');
} else { } else {
debug('Showing dialog'); 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();
@@ -183,6 +234,7 @@
}); });
} }
} }
}
}, },
position: function() { position: function() {
@@ -191,9 +243,14 @@
.css('height', dialogHeight + 'px') .css('height', dialogHeight + 'px')
.css('margin-top', -1 * parseInt( dialogHeight / 2 )); .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' ) {
+68 -98
View File
@@ -1,86 +1,6 @@
// ua // ua
$(document).ready(function() { $(document).ready(function() {
// ua detection
if ($.browser.mozilla) {
$('body').addClass('ff');
} else if ($.browser.webkit) {
$('body').addClass('webkit');
} else if ($.browser.msie) {
$('body').addClass('ie');
if ($.browser.version == "7.0") {
$('body').addClass('ie7');
} else if ($.browser.version == "8.0") {
$('body').addClass('ie8');
}
}
if ($('#minibutton-new-page').length) {
$('#minibutton-new-page').removeClass('jaws');
$('#minibutton-new-page').click(function(e) {
e.preventDefault();
$.GollumDialog.init({
title: 'Create New Page',
fields: [
{
id: 'name',
name: 'Page Name',
type: 'text'
}
],
OK: function( res ) {
var n = 'New Page';
if ( res['name'] )
var n = res['name'];
n = encodeURIComponent( n );
window.location = '/' + n;
}
});
});
}
if ($('#wiki-wrapper').hasClass('history')) {
$('#wiki-history td.checkbox input').each(function() {
$(this).click(highlightChecked);
if ( $(this).is(':checked') ) {
nodeSelector.checkNode($(this));
}
});
if ($('.history a.action-compare-revision').length) {
$('.history a.action-compare-revision').click(function() {
$("#version-form").submit();
});
}
}
if ($('#searchbar a#search-submit').length) {
$.GollumPlaceholder.add($('#searchbar #search-query'));
$('#searchbar a#search-submit').click(function(e) {
e.preventDefault();
$('#searchbar #search-form')[0].submit();
});
$('#searchbar #search-form').submit(function(e) {
$.GollumPlaceholder.clearAll();
$(this).unbind('submit');
$(this).submit();
});
}
if ($('#gollum-revert-form').length &&
$('.gollum-revert-button').length ) {
$('a.gollum-revert-button').click(function(e) {
e.preventDefault();
$('#gollum-revert-form').submit();
});
}
});
var nodeSelector = { var nodeSelector = {
node1: null, node1: null,
node2: null, node2: null,
@@ -161,31 +81,81 @@ var nodeSelector = {
} }
} }
} }
}; };
function highlightOn() { // ua detection
$(this).parent().parent().animate({ if ($.browser.mozilla) {
backgroundColor: '#ffffea', $('body').addClass('ff');
duration: 400 } else if ($.browser.webkit) {
$('body').addClass('webkit');
} else if ($.browser.msie) {
$('body').addClass('ie');
if ($.browser.version == "7.0") {
$('body').addClass('ie7');
} else if ($.browser.version == "8.0") {
$('body').addClass('ie8');
}
}
if ($('#minibutton-new-page').length) {
$('#minibutton-new-page').removeClass('jaws');
$('#minibutton-new-page').click(function(e) {
e.preventDefault();
$.GollumDialog.init({
title: 'Create New Page',
fields: [
{
id: 'name',
name: 'Page Name',
type: 'text'
}
],
OK: function( res ) {
var n = 'New Page';
if ( res['name'] )
var n = res['name'];
n = encodeURIComponent( n );
window.location = '/' + n;
}
});
}); });
} }
function highlightOff() { if ($('#wiki-wrapper').hasClass('history')) {
var color = '#ebf2f6'; $('#wiki-history td.checkbox input').each(function() {
if ($(this).parent().parent().hasClass('alt-row')) { $(this).click(function() {
color = '#f3f7fa'; nodeSelector.checkNode($(this));
}
$(this).parent().parent().animate({
backgroundColor: color,
duration: 400
}); });
} if ( $(this).is(':checked') ) {
function highlightChecked() {
nodeSelector.checkNode($(this)); nodeSelector.checkNode($(this));
} }
});
function initMathJax() { if ($('.history a.action-compare-revision').length) {
$('.history a.action-compare-revision').click(function() {
$("#version-form").submit();
});
} }
}
if ($('#searchbar a#search-submit').length) {
$.GollumPlaceholder.add($('#searchbar #search-query'));
$('#searchbar a#search-submit').click(function(e) {
e.preventDefault();
$('#searchbar #search-form')[0].submit();
});
$('#searchbar #search-form').submit(function(e) {
$.GollumPlaceholder.clearAll();
$(this).unbind('submit');
$(this).submit();
});
}
if ($('#gollum-revert-form').length &&
$('.gollum-revert-button').length ) {
$('a.gollum-revert-button').click(function(e) {
e.preventDefault();
$('#gollum-revert-form').submit();
});
}
});