Good art is a taste, good design is an opinion.


Come as guest, stay as family.
Board Index

Come as guest, stay as family.


You are not connected. Please login or register

Foto

[JavaScript] Automatic post when moving topic



View previous topic View next topic Go down Message [Page 1 of 1]

1
Offline

  Daemon

avatar
Punbb Rookie
Punbb Rookie

[JavaScript] Automatic post when moving topic Alerte10

Tutorial: Automatic post when moving topic

--> Tutorials, tips and tricks <--
Automatic post when moving topic


JavaScript code:

PunBB:
Code:
jQuery(document).ready(function() {
if(window.location.href.search('mode=move') >= 0) {
      var jHtml = '<dl>' +
                  '      <dt></dt>' +
                  '      <dd>' +
                  '         <label><input id="send_move_post" type="checkbox">Add a post to the topic that informs about this action?</label>' +
                  '      </dd>' +
                  '</dl>';
      jQuery(jHtml).insertBefore('.frm-buttons');
      jQuery('input[name="confirm"]').on('click', function(d) {
            var jVerify = jQuery('[name="new_forum"]').val();
            if(jVerify.indexOf('f') >= 0) {
               if(jQuery('#send_move_post').is(':checked')) {
                  d.preventDefault();
                  var jForum = jQuery('[name="f"]').val();
                  var jTopic = jQuery('[name="t"]').val();
                  var jCurrentLocal = jQuery('a.nav[href^="/f"]:last').text();
                  var jNewLocal = jQuery('[name="new_forum"] option:selected').text().split('--').pop();
                  var TID = jQuery('input[name="tid"]').val();
                  jQuery.post('/modcp?tid=' + TID, {
                         'new_forum': jVerify,
                         'mode': 'move',
                         'f': jForum,
                         't': jTopic,
                         'confirm': 'submit'
                  }).done(function() {
                         jQuery.post('/post?t=' + jTopic, {
                                   'mode': 'reply',
                                   'message': '[b]Automatic message[/b]\n\n\n\nThis topic has been moved from "[u]' + jCurrentLocal + '[/u]" to "[u]' + jNewLocal + '[/u]".',
                                   'post': 'submit',
                                   'attach_sig': '1'
                         }).done(function(e) {
                                   var href = jQuery(e).find('p.message a:first').attr('href');
                                   location.href = href;
                         }).fail(function() {
                                   alert("The topic has been moved, but an error occurred while trying to send post");
                         });
                  }).fail(function() {
                       alert("An error occurred when trying to move the topic");
                       location.reload();
                  });
               }
            } else {
                  d.preventDefault();
                  alert("Select a forum");
            }
      });
   }
});

Infos:
1 - The investment is on every page.
2 - Only works in PunBB.

Preview:
Image 1:
[JavaScript] Automatic post when moving topic YZlwk0j

Image 2:
[JavaScript] Automatic post when moving topic LmKW9pz

Powered by PunBB
Currently 0 users have thanked Daemon for this post:

2
Offline

  Shadow

Shadow
Administrator
Administrator
[sucesso="Tutorial accepted"]This tutorial has been accepted. Thank you for sharing with PunBB Community. [/sucesso]

Powered by PunBB
Currently 0 users have thanked Shadow for this post:

3
Offline

  Alexandru M

Alexandru M
Newbie
Newbie
It doesnt work for me. Sad

Powered by PunBB
Currently 0 users have thanked Alexandru M for this post:

4
Offline

  Bossanova

Bossanova
Punbb Rookie
Punbb Rookie
I wish all forum softwares had this feature. It's so nice to be able to say "this was moved" instead of having people ask over and over "where did my topic go?"

Powered by PunBB
Currently 0 users have thanked Bossanova for this post:

5
Offline

  Andrei34

Andrei34
Punbb Rookie
Punbb Rookie
very good tuto thx

Powered by PunBB
Currently 0 users have thanked Andrei34 for this post:

6
Offline

  Sponsored content



Powered by PunBB
Currently 0 users have thanked Sponsored content for this post:

View previous topic View next topic Back to top Message [Page 1 of 1]


Topic URL's

URL
BBcode
HTML

Permissions in this forum:
You cannot reply to topics in this forum