Skip to content

Commit

Permalink
Merge pull request #49 from marc1706/ticket/48
Browse files Browse the repository at this point in the history
[ticket/48] Improve quickedit.js code
  • Loading branch information
marc1706 committed Jan 24, 2015
2 parents 7e55e24 + 8b98400 commit be1f9e0
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions styles/prosilver/template/quickedit.js
Expand Up @@ -10,7 +10,9 @@ phpbb.edit_button_event = [];
* edited. It will also ajaxify the cancel button.
*/
phpbb.addAjaxCallback('quickedit_post', function(res) {
if (typeof res.POST_ID !== 'undefined' && res.POST_ID > 0 && !$('#quickeditbox').length) {
var $quickeditBox = $('#quickeditbox');

if (res.POST_ID !== 'undefined' && res.POST_ID > 0 && !$quickeditBox.length) {
$('#p' + res.POST_ID +' .content').hide();
$(res.MESSAGE).insertAfter('#p' + res.POST_ID +' .author');
var edit_link = $('#p' + res.POST_ID +' a.edit-icon');
Expand All @@ -19,7 +21,7 @@ phpbb.addAjaxCallback('quickedit_post', function(res) {
});

// Cancel button will show post again
$('#quickeditbox input[name="cancel"]').click(function () {
$quickeditBox.find('input[name="cancel"]').click(function () {
$('#quickeditbox').remove();
$('#p' + res.POST_ID + ' .content').show();

Expand All @@ -35,14 +37,14 @@ phpbb.addAjaxCallback('quickedit_post', function(res) {
// Remove last click event. This should be the
// one we added
edit_button.each(function() {
var event_handlers = $._data(this, 'events')['click'];
var event_handlers = $._data(this, 'events').click;
event_handlers.pop();
});
});

// Add edit button click event for quickedit back
edit_link.each(function() {
var event_handlers = $._data(this, 'events')['click'];
var event_handlers = $._data(this, 'events').click;
event_handlers.splice(0, 0, phpbb.edit_button_event);
// Remove full editor click event
event_handlers.pop();
Expand All @@ -53,8 +55,8 @@ phpbb.addAjaxCallback('quickedit_post', function(res) {

// Edit button will redirect to full editor
edit_link.bind('click', function () {
if (typeof $('#quickeditbox input[name="preview"]') !== 'undefined') {
$('#quickeditbox input[name="preview"]').click();
if ($quickeditBox.find('input[name="preview"]') !== 'undefined') {
$quickeditBox.find('input[name="preview"]').click();
}
return false;
});
Expand All @@ -69,22 +71,22 @@ phpbb.addAjaxCallback('quickedit_post', function(res) {
var edit_button = $(edit_button_id + ' a.edit-icon');

edit_button.bind('click', function() {
$('#quickeditbox input[name="cancel"]').trigger('click');
$quickeditBox.find('input[name="cancel"]').trigger('click');
});
});

// Remove edit button click event for quickedit
edit_link.each(function() {
var event_handlers = $._data(this, 'events')['click'];
var event_handlers = $._data(this, 'events').click;
phpbb.edit_button_event = event_handlers.shift();
});
}
});

$(document).ready(function() {
var allow_quickedit_div = $('div[data-allow-quickedit]');
var allowQuickeditDiv = $('div[data-allow-quickedit]');

if (typeof allow_quickedit_div !== 'undefined' && allow_quickedit_div.attr('data-allow-quickedit') === '1')
if (allowQuickeditDiv !== 'undefined' && allowQuickeditDiv.attr('data-allow-quickedit') === '1')
{
var edit_buttons = $('div[id^="p"]').filter(function() {
return this.id.match(/^p+(?:([0-9]+))/);
Expand Down

0 comments on commit be1f9e0

Please sign in to comment.