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
var oldAction = $('#gollum-editor form').attr('action');
var $form = $($('#gollum-editor form').get(0));
$form.attr('action', '/preview');
$form.attr('action', this.href || '/preview');
$form.attr('target', '_blank');
$form.submit();
@@ -154,7 +154,13 @@
define: function( name, definitionObject ) {
LanguageDefinition._ACTIVE_LANG = 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;
}
},
getActiveLanguage: function() {
@@ -779,7 +785,6 @@
_LOADED_HELP_LANGS: [],
_HELP: {},
/**
* Help.define
*
@@ -809,6 +814,12 @@
// 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 ) {
@@ -817,7 +828,6 @@
}
},
/**
* Help.generateHelpMenuFor
* Generates the markup for the main help menu given a context name.
@@ -864,7 +874,6 @@
},
/**
* Help.generateSubMenu
* Generates the markup for the inline help sub-menu given the data
@@ -891,15 +900,13 @@
}
},
hide: function() {
if ( $.browser.msie ) {
$('#gollum-editor-help').css('display', 'none');
} else {
$('#gollum-editor-help').animate({
opacity: 0
}, 200,
function() {
}, 200, function() {
$('#gollum-editor-help')
.animate({ height: 'hide' }, 200);
});
@@ -914,15 +921,13 @@
} else {
$('#gollum-editor-help').animate({
height: 'show'
}, 200,
function() {
}, 200, function() {
$('#gollum-editor-help')
.animate({ opacity: 1 }, 300);
});
}
},
/**
* Help.showHelpFor
* Displays the actual help content given the two menu indexes, which are
@@ -938,7 +943,6 @@
$('#gollum-editor-help-content').html(html);
},
/**
* Help.isLoadedFor
* Returns true if help is loaded for a specific markup language,
@@ -956,12 +960,10 @@
return false;
},
isShown: function() {
return ( $('#gollum-editor-help').is(':visible') );
return ($('#gollum-editor-help').is(':visible'));
},
/**
* Help.isValidHelpFormat
* Does a quick check to make sure that the help definition isn't in a
@@ -978,7 +980,6 @@
helpArr[0].content.length );
},
/**
* Help.setActiveHelp
* Sets the active help definition to the one defined in the argument,
@@ -1008,7 +1009,6 @@
}
},
/**
* Help.evtHelpButtonClick
* Event handler for clicking the help button in the function bar.
@@ -1018,11 +1018,18 @@
*/
evtHelpButtonClick: function( e ) {
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(); }
},
/**
* Help.evtParentMenuClick
* 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();
},
/**
* Help.evtSubMenuClick
* Event handler for clicking an item in a help submenu. Renders the
@@ -1068,7 +1074,6 @@
}
};
// Publicly-accessible function to Help.define
$.GollumEditor.defineHelp = Help.define;
@@ -11,12 +11,23 @@
debugOn: false,
markupCreated: false,
markup: '',
attachEvents: function( evtOK ) {
$('#gollum-dialog-action-ok').click(function( e ) {
Dialog.eventOK( e, evtOK );
});
$('#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 ) {
@@ -70,6 +81,19 @@
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-bg">' +
@@ -85,6 +109,7 @@
'</div>' +
'</div>' +
'</div>';
}
},
eventCancel: function( e ) {
@@ -111,6 +136,11 @@
},
hide: function() {
if ( $.facebox ) {
Dialog.markupCreated = false;
$(document).trigger('close.facebox');
Dialog.detachEvents();
} else {
if ( $.browser.msie ) {
$('#gollum-dialog-dialog').hide().removeClass('active');
$('select').css('visibility', 'visible');
@@ -122,6 +152,7 @@
}
});
}
}
},
init: function( argObject ) {
@@ -149,14 +180,31 @@
}
if ( Dialog.markupCreated ) {
if ($.facebox) {
$(document).trigger('close.facebox');
} else {
$('#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 &&
typeof argObject.OK == 'function' ) {
Dialog.attachEvents( argObject.OK );
}
}
Dialog.show();
},
@@ -165,6 +213,9 @@
debug('Dialog: No markup to show. Please use init first.');
} else {
debug('Showing dialog');
if ($.facebox) {
$.facebox( Dialog.markup );
} else {
if ( $.browser.msie ) {
$('#gollum-dialog.dialog').addClass('active');
Dialog.position();
@@ -183,6 +234,7 @@
});
}
}
}
},
position: function() {
@@ -191,9 +243,14 @@
.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) {
if ( Dialog.debugOn
&& typeof console != 'undefined' ) {
+72 -102
View File
@@ -1,86 +1,6 @@
// ua
$(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,
node2: null,
@@ -161,31 +81,81 @@ var nodeSelector = {
}
}
}
};
};
function highlightOn() {
$(this).parent().parent().animate({
backgroundColor: '#ffffea',
duration: 400
});
}
function highlightOff() {
var color = '#ebf2f6';
if ($(this).parent().parent().hasClass('alt-row')) {
color = '#f3f7fa';
// 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;
}
$(this).parent().parent().animate({
backgroundColor: color,
duration: 400
});
}
});
}
function highlightChecked() {
if ($('#wiki-wrapper').hasClass('history')) {
$('#wiki-history td.checkbox input').each(function() {
$(this).click(function() {
nodeSelector.checkNode($(this));
}
});
if ( $(this).is(':checked') ) {
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();
});
}
});