User:Gryllida/js/ajaxSectionUpdateOnDoubleClick.js

From Wikinews, the free news source you can write!
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

/*
Author : Svetlana Tkachenko svetlana@members.fsf.org
This file is a part of ajaxSectionUpdateOnDoubleClick.
Licence: GPLv3+
Version: 0.1
Release date: 2018-02-26
Description: updates a section when double-clicked (useful on talk pages sometimes)
*/ 

$('.mw-headline').each(function(i){
	var $self = $(this);
	//alert(i);
    //alert($self.text());
    var $anchor = $self.parent();
    $anchor.nextUntil( "h2" ).dblclick(function(){
    	console.log('hi');
    	var api = new mw.Api();
		api.get( { // Corresponds to "api.php?action=parse&page=test"
    		action: 'parse',
    		page: mw.config.get( 'wgPageName' ),
    		section: i+1
		} ).done(function(data){
			var html = data.parse.text['*'];
			//$(this).replacewith($('<p>j</p>'));
    		$anchor.nextUntil( "h2" ).remove();
    		$anchor.replaceWith($(html));
		})
    });
});