diff options
author | Callum Macrae <callum@lynxphp.com> | 2011-07-23 18:58:37 +0100 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2012-03-31 02:09:11 +0200 |
commit | efe872745faf2715b568a503384ea7f198809716 (patch) | |
tree | d20c6cedbe8109d4c00ad44e70b78ea883fb3f4c /phpBB | |
parent | ac8743902d07c299405ae113e9f9f51f9bfec538 (diff) | |
download | forums-efe872745faf2715b568a503384ea7f198809716.tar forums-efe872745faf2715b568a503384ea7f198809716.tar.gz forums-efe872745faf2715b568a503384ea7f198809716.tar.bz2 forums-efe872745faf2715b568a503384ea7f198809716.tar.xz forums-efe872745faf2715b568a503384ea7f198809716.zip |
[feature/ajax] Replaced jQuery selectors with data attributes.
Due to problems that could have been caused by selecting the element using
jQuery selectors, they have been replaced by HTML5 data attributes.
PHPBB3-10270
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/styles/prosilver/template/index_body.html | 2 | ||||
-rw-r--r-- | phpBB/styles/prosilver/template/overall_footer.html | 10 | ||||
-rw-r--r-- | phpBB/styles/prosilver/template/viewforum_body.html | 2 | ||||
-rw-r--r-- | phpBB/styles/prosilver/template/viewtopic_body.html | 4 | ||||
-rw-r--r-- | phpBB/styles/script.js | 90 |
5 files changed, 61 insertions, 47 deletions
diff --git a/phpBB/styles/prosilver/template/index_body.html b/phpBB/styles/prosilver/template/index_body.html index b183cf4372..9269f62769 100644 --- a/phpBB/styles/prosilver/template/index_body.html +++ b/phpBB/styles/prosilver/template/index_body.html @@ -8,7 +8,7 @@ <!-- IF S_DISPLAY_SEARCH --> <li><a href="{U_SEARCH_UNANSWERED}">{L_SEARCH_UNANSWERED}</a><!-- IF S_LOAD_UNREADS --> • <a href="{U_SEARCH_UNREAD}">{L_SEARCH_UNREAD}</a><!-- ENDIF --><!-- IF S_USER_LOGGED_IN --> • <a href="{U_SEARCH_NEW}">{L_SEARCH_NEW}</a><!-- ENDIF --> • <a href="{U_SEARCH_ACTIVE_TOPICS}">{L_SEARCH_ACTIVE_TOPICS}</a></li> <!-- ENDIF --> - <!-- IF not S_IS_BOT and U_MARK_FORUMS --><li class="rightside"><a href="{U_MARK_FORUMS}" accesskey="m">{L_MARK_FORUMS_READ}</a></li><!-- ENDIF --> + <!-- IF not S_IS_BOT and U_MARK_FORUMS --><li class="rightside"><a href="{U_MARK_FORUMS}" accesskey="m" data-ajax="true">{L_MARK_FORUMS_READ}</a></li><!-- ENDIF --> </ul> <!-- ENDIF --> diff --git a/phpBB/styles/prosilver/template/overall_footer.html b/phpBB/styles/prosilver/template/overall_footer.html index 0d2fd4d27a..ffdb27be98 100644 --- a/phpBB/styles/prosilver/template/overall_footer.html +++ b/phpBB/styles/prosilver/template/overall_footer.html @@ -8,12 +8,12 @@ <ul class="linklist"> <li class="icon-home"><a href="{U_INDEX}" accesskey="h">{L_INDEX}</a></li> <!-- IF not S_IS_BOT --> - <!-- IF S_WATCH_FORUM_LINK --><li <!-- IF S_WATCHING_FORUM -->class="icon-unsubscribe"<!-- ELSE -->class="icon-subscribe"<!-- ENDIF -->><a href="{S_WATCH_FORUM_LINK}" title="{S_WATCH_FORUM_TITLE}">{S_WATCH_FORUM_TITLE}</a></li><!-- ENDIF --> - <!-- IF U_WATCH_TOPIC --><li <!-- IF S_WATCHING_TOPIC -->class="icon-unsubscribe"<!-- ELSE -->class="icon-subscribe"<!-- ENDIF -->><a href="{U_WATCH_TOPIC}" title="{L_WATCH_TOPIC}">{L_WATCH_TOPIC}</a></li><!-- ENDIF --> - <!-- IF U_BOOKMARK_TOPIC --><li class="icon-bookmark"><a href="{U_BOOKMARK_TOPIC}" title="{L_BOOKMARK_TOPIC}">{L_BOOKMARK_TOPIC}</a></li><!-- ENDIF --> - <!-- IF U_BUMP_TOPIC --><li class="icon-bump"><a href="{U_BUMP_TOPIC}" title="{L_BUMP_TOPIC}">{L_BUMP_TOPIC}</a></li><!-- ENDIF --> + <!-- IF S_WATCH_FORUM_LINK --><li <!-- IF S_WATCHING_FORUM -->class="icon-unsubscribe"<!-- ELSE -->class="icon-subscribe"<!-- ENDIF -->><a href="{S_WATCH_FORUM_LINK}" title="{S_WATCH_FORUM_TITLE}" data-ajax="forum_<!-- IF S_WATCHING_FORUM -->un<!-- ENDIF -->subscribe">{S_WATCH_FORUM_TITLE}</a></li><!-- ENDIF --> + <!-- IF U_WATCH_TOPIC --><li <!-- IF S_WATCHING_TOPIC -->class="icon-unsubscribe"<!-- ELSE -->class="icon-subscribe"<!-- ENDIF -->><a href="{U_WATCH_TOPIC}" title="{L_WATCH_TOPIC}" data-ajax="topic_<!-- IF S_WATCHING_TOPIC -->un<!-- ENDIF -->subscribe">{L_WATCH_TOPIC}</a></li><!-- ENDIF --> + <!-- IF U_BOOKMARK_TOPIC --><li class="icon-bookmark"><a href="{U_BOOKMARK_TOPIC}" title="{L_BOOKMARK_TOPIC}" data-ajax="bookmark">{L_BOOKMARK_TOPIC}</a></li><!-- ENDIF --> + <!-- IF U_BUMP_TOPIC --><li class="icon-bump"><a href="{U_BUMP_TOPIC}" title="{L_BUMP_TOPIC}" data-ajax="true">{L_BUMP_TOPIC}</a></li><!-- ENDIF --> <!-- ENDIF --> - <li class="rightside"><!-- IF U_TEAM --><a href="{U_TEAM}">{L_THE_TEAM}</a> • <!-- ENDIF --><!-- IF not S_IS_BOT --><a href="{U_DELETE_COOKIES}">{L_DELETE_COOKIES}</a> • <!-- ENDIF -->{S_TIMEZONE}</li> + <li class="rightside"><!-- IF U_TEAM --><a href="{U_TEAM}">{L_THE_TEAM}</a> • <!-- ENDIF --><!-- IF not S_IS_BOT --><a href="{U_DELETE_COOKIES}" data-ajax="true" data-refresh="true">{L_DELETE_COOKIES}</a> • <!-- ENDIF -->{S_TIMEZONE}</li> </ul> <span class="corners-bottom"><span></span></span></div> diff --git a/phpBB/styles/prosilver/template/viewforum_body.html b/phpBB/styles/prosilver/template/viewforum_body.html index 385d3eed71..d17203efa0 100644 --- a/phpBB/styles/prosilver/template/viewforum_body.html +++ b/phpBB/styles/prosilver/template/viewforum_body.html @@ -57,7 +57,7 @@ <!-- IF PAGINATION or TOTAL_POSTS or TOTAL_TOPICS --> <div class="pagination"> - <!-- IF not S_IS_BOT and U_MARK_TOPICS --><a href="{U_MARK_TOPICS}" accesskey="m">{L_MARK_TOPICS_READ}</a> • <!-- ENDIF --><!-- IF TOTAL_TOPICS -->{TOTAL_TOPICS}<!-- ENDIF --> + <!-- IF not S_IS_BOT and U_MARK_TOPICS --><a href="{U_MARK_TOPICS}" accesskey="m" data-ajax="true">{L_MARK_TOPICS_READ}</a> • <!-- ENDIF --><!-- IF TOTAL_TOPICS -->{TOTAL_TOPICS}<!-- ENDIF --> <!-- IF PAGE_NUMBER --> <!-- IF PAGINATION --> • <a href="#" onclick="jumpto(); return false;" title="{L_JUMP_TO_PAGE}">{PAGE_NUMBER}</a> • <span>{PAGINATION}</span><!-- ELSE --> • {PAGE_NUMBER}<!-- ENDIF --> <!-- ENDIF --> diff --git a/phpBB/styles/prosilver/template/viewtopic_body.html b/phpBB/styles/prosilver/template/viewtopic_body.html index 9e333cf5ec..8559b6fd9e 100644 --- a/phpBB/styles/prosilver/template/viewtopic_body.html +++ b/phpBB/styles/prosilver/template/viewtopic_body.html @@ -122,7 +122,7 @@ <!-- IF postrow.U_EDIT or postrow.U_DELETE or postrow.U_REPORT or postrow.U_WARN or postrow.U_INFO or postrow.U_QUOTE --> <ul class="profile-icons"> <!-- IF postrow.U_EDIT --><li class="edit-icon"><a href="{postrow.U_EDIT}" title="{L_EDIT_POST}"><span>{L_EDIT_POST}</span></a></li><!-- ENDIF --> - <!-- IF postrow.U_DELETE --><li class="delete-icon"><a href="{postrow.U_DELETE}" title="{L_DELETE_POST}"><span>{L_DELETE_POST}</span></a></li><!-- ENDIF --> + <!-- IF postrow.U_DELETE --><li class="delete-icon"><a href="{postrow.U_DELETE}" title="{L_DELETE_POST}" data-ajax="post_delete"<!-- IF postrow.POST_NUMBER == 1 --> data-refresh="true"<!-- ENDIF -->><span>{L_DELETE_POST}</span></a></li><!-- ENDIF --> <!-- IF postrow.U_REPORT --><li class="report-icon"><a href="{postrow.U_REPORT}" title="{L_REPORT_POST}"><span>{L_REPORT_POST}</span></a></li><!-- ENDIF --> <!-- IF postrow.U_WARN --><li class="warn-icon"><a href="{postrow.U_WARN}" title="{L_WARN_USER}"><span>{L_WARN_USER}</span></a></li><!-- ENDIF --> <!-- IF postrow.U_INFO --><li class="info-icon"><a href="{postrow.U_INFO}" title="{L_INFORMATION}"><span>{L_INFORMATION}</span></a></li><!-- ENDIF --> @@ -135,7 +135,7 @@ <p class="author"><!-- IF S_IS_BOT -->{postrow.MINI_POST_IMG}<!-- ELSE --><a href="{postrow.U_MINI_POST}">{postrow.MINI_POST_IMG}</a><!-- ENDIF -->{L_POST_BY_AUTHOR} <strong>{postrow.POST_AUTHOR_FULL}</strong> » {postrow.POST_DATE} </p> <!-- IF postrow.S_POST_UNAPPROVED or postrow.S_POST_REPORTED --> - <form method="post" class="mcp_approve" action="{postrow.U_APPROVE_ACTION}"> + <form method="post" class="mcp_approve" action="{postrow.U_APPROVE_ACTION}" data-ajax="post_approve"> <p class="rules"> <!-- IF postrow.S_POST_UNAPPROVED --> {UNAPPROVED_IMG} <strong>{L_POST_UNAPPROVED}</strong> diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 3f4aa0f34e..99a73769b4 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -53,10 +53,6 @@ phpbb.confirm = function(msg, callback) { return div; } -/** - * Works out what to do with the refresh. Don't use this. - */ - /** * Makes a link use AJAX instead of loading an entire page. @@ -94,9 +90,17 @@ phpbb.ajaxify = function(options, refresh, callback) { } var selector = (typeof options === 'string') ? options : options.selector; - var is_form = $(selector).is('form'); - $(selector + ((is_form) ? ' input:submit' : '')).click(function() { + if (is_form && typeof selector === 'object') + { + selector = $(selector).find('input:submit'); + } + else if (is_form) + { + selector += ' input:submit'; + } + + $(selector).click(function() { var act, data, path, that = this; if (typeof options.exception !== 'undefined') @@ -117,9 +121,10 @@ phpbb.ajaxify = function(options, refresh, callback) { * It is a standard link, no confirm_box required. */ var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - if (typeof callback !== 'undefined') + callback = phpbb.ajax_callbacks[callback]; + if (typeof callback === 'function') { - callback(that, res); + callback(that, (is_form) ? act : null); } handle_refresh(res.REFRESH_DATA, refresh, alert); } @@ -136,9 +141,10 @@ phpbb.ajaxify = function(options, refresh, callback) { $.post(path, data + '&confirm=' + res.YES_VALUE, function(res) { res = JSON.parse(res); var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - if (typeof callback !== 'undefined') + callback = phpbb.ajax_callbacks[callback]; + if (typeof callback === 'function') { - callback(that, (is_form) ? act : null); + callback(that, res, (is_form) ? act : null); } handle_refresh(res.REFRESH_DATA, refresh, alert); }); @@ -168,45 +174,53 @@ phpbb.ajaxify = function(options, refresh, callback) { return false; }); + return this; } - -//bind the confirm_boxes -var refresh = function(url) { - return (url.indexOf('t=') === -1); +phpbb.ajax_callbacks = {}; +phpbb.add_ajax_callback = function(id, callback) +{ + if (typeof callback === 'function') + { + phpbb.ajax_callbacks[id] = callback; + } + return this; } -phpbb.ajaxify('.delete-icon a', refresh, function(el) { - var pid = el.href.split('&p=')[1]; - $(el).parents('div #p' + pid).fadeOut(function() { - $(this).remove(); - }); -}); -phpbb.ajaxify('#page-footer a[href$="ucp.php?mode=delete_cookies"]', true); -//AJAXify some links -phpbb.ajaxify('#page-footer a[href*="&bookmark=1"]', false, function(el, res) { +phpbb.add_ajax_callback('post_delete', function(el) { + if ($(this).data('refresh') === undefined) + { + var pid = el.href.split('&p=')[1]; + $(el).parents('div #p' + pid).fadeOut(function() { + $(this).remove(); + }); + } +}).add_ajax_callback('bookmark', function(el, res) { var text = (res.MESSAGE_TEXT.indexOf('Removed') === -1); text = (text) ? 'Remove from bookmarks' : 'Bookmark topic'; $(el).text(el.title = text); -}); -phpbb.ajaxify('#page-footer a[href*="watch=topic"]', false, function(el, res) { - var text = (res.MESSAGE_TEXT.indexOf('no longer subscribed') === -1); - text = (text) ? 'Unsubscribe topic' : 'Subscribe topic'; - $(el).text(el.title = text); -}); -phpbb.ajaxify('#page-footer a[href*="watch=forum"]', false, function(el, res) { - var text = (res.MESSAGE_TEXT.indexOf('no longer subscribed') === -1); - text = (text) ? 'Unsubscribe forum' : 'Subscribe forum'; - $(el).text(el.title = text); -}); -phpbb.ajaxify('#page-footer a[href*="mode=bump"]'); -phpbb.ajaxify('.rightside a[href*="mark="]'); //captures topics and forums - -phpbb.ajaxify('.mcp_approve', false, function(el, act) { +}).add_ajax_callback('topic_subscribe', function(el) { + $(el).text(el.title = 'Unsubscribe topic'); +}).add_ajax_callback('topic_unsubscribe', function(el) { + $(el).text(el.title = 'Subscribe forum'); +}).add_ajax_callback('forum_subscribe', function(el) { + $(el).text(el.title = 'Unsubscribe topic'); +}).add_ajax_callback('forum_unsubscribe', function(el) { + $(el).text(el.title = 'Subscribe forum'); +}).add_ajax_callback('post_approve', function(el, res, act) { $(el).parents((act === 'approve') ? '.rules' : '.post').fadeOut(function() { $(this).remove(); }); }); + + +$('[data-ajax]').each(function() { + var fn = ($(this).data('ajax') !== 'true') ? $(this).data('ajax') : null; + phpbb.ajaxify({selector: this}, $(this).data('refresh') !== undefined, fn); +}); + + + phpbb.ajaxify('#quickmodform'); |