Misplaced Pages

User:NQ/WatchlistResetConfirm.js: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< User:NQ Browse history interactively← Previous editContent deleted Content added
Revision as of 09:20, 1 November 2016 view sourceNQ (talk | contribs)Extended confirmed users, Pending changes reviewers, Rollbackers6,648 edits convert to OOjs-UI thanks to the excellent mediawiki documentation← Previous edit Latest revision as of 01:11, 8 December 2016 view source NQ (talk | contribs)Extended confirmed users, Pending changes reviewers, Rollbackers6,648 edits gpl 
Line 1: Line 1:
//Adds a confirmation dialogue to the Watchlist Reset button /*Adds a confirmation dialogue to the Watchlist Reset button
//https://en.wikipedia.org/search/?title=Misplaced Pages:Village_pump_(technical)&oldid=746997333#Watchlist:_.22Are_you_sure_you_want_to_mark_all_pages_as_visited.3F.22 https://en.wikipedia.org/search/?title=Misplaced Pages:Village_pump_(technical)&oldid=746997333#Watchlist:_.22Are_you_sure_you_want_to_mark_all_pages_as_visited.3F.22


* Licensed under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. See the
* GNU General Public License for more details.
* A copy of the GPL is available at https://www.gnu.org/licenses/gpl-2.0.txt
/* ############################################################################ /* ############################################################################
$(function() { $(function() {

Latest revision as of 01:11, 8 December 2016

/*Adds a confirmation dialogue to the Watchlist Reset button
https://en.wikipedia.org/search/?title=Misplaced Pages:Village_pump_(technical)&oldid=746997333#Watchlist:_.22Are_you_sure_you_want_to_mark_all_pages_as_visited.3F.22

* Licensed under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. See the
* GNU General Public License for more details.
* A copy of the GPL is available at https://www.gnu.org/licenses/gpl-2.0.txt 
 
 /* ############################################################################
$(function() {
    $watchlistReset = $('#mw-watchlist-resetbutton');
    $watchlistReset.css('display', 'inline'); //already hidden in css
    $watchlistReset.on('click', function(event) {
        if (!confirm('Are you sure you want to mark all pages as visited?' )) {
            event.preventDefault();
        }
    });
}); ############################################################################ */

/* Using ] */

mw.loader.using(, function() {

  $watchlistReset = $('#mw-watchlist-resetbutton');
  $watchlistReset.css('display', 'inline'); //if already hidden in css; recommended

  var messageDialog = new OO.ui.MessageDialog();
  var windowManager = new OO.ui.WindowManager();
  $('body').append(windowManager.$element);
  windowManager.addWindows();

  $watchlistReset.submit(function(event) {
    event.preventDefault();

    windowManager.openWindow(messageDialog, {
      title: 'Confirm',
      message: 'Mark all pages as visited?',
      actions:  },
               { action: 'reset', label: 'Confirm', flags: }]
    }).then(function(opened) {
      opened.then(function(closing, data) {
        if (data && data.action === 'reset') {
        	
/* Uses ] to reset the watchlist without refreshing the page */
             
          // Code adapted from ]
          new mw.Api().post({
            action: 'setnotificationtimestamp',
            entirewatchlist: '',
            token: mw.user.tokens.get('editToken')
          }).done(function() {
            $('.mw-changeslist-line-watched').removeClass('mw-changeslist-line-watched').addClass('mw-changeslist-line-not-watched');
          });
          
        } 
      });
    });
  });
});