Uit Hack42
Ga naar: navigatie, zoeken
k
k (Wijzigingen door CookieMonster (Overleg) hersteld tot de laatste versie door Aequitas)
Regel 1: Regel 1:
 
/* JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers */
 
/* JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers */
jQuery().ready(function() {
 
    getEditToken();
 
    user = wgUserName;
 
    if (user) {
 
        var titles = jQuery('#Ik_kom_wel,#Ik_kom_niet,#Ik_kom_misschien,#Animo,#Aanwezig,#Afwezig,#Wie,#Wie_niet,#Wie_misschien');
 
        titles.each(function() {
 
            var $title = jQuery(this).parent();
 
            var $siblings = $title.nextUntil('h1,h2,h3,h4,h5,h6');
 
            var $ul = $siblings.filter('ul:first');
 
            console.log($siblings, $ul);
 
            var alreadyInList = $ul.find('li a:contains("'+user+'")').length > 0;
 
            if ( ! alreadyInList) {
 
                if ($ul.length === 0) {
 
                    $ul = jQuery('<ul>').insertAfter($title);
 
                }
 
                addAddUserButton($title, $ul);
 
            }
 
        });
 
    }
 
});
 
 
 
function getEditToken() {
 
function getEditToken() {
 
     jQuery.getJSON(
 
     jQuery.getJSON(
Regel 40: Regel 19:
 
     )
 
     )
 
}
 
}
 
+
function getSection(section_id) {
function addAddUserButton($title, $ul) {
+
     jQuery.getJSON(
     var button = jQuery('<input type="button" value="'+user+'"/>');
+
        wgScriptPath + '/api.php?',
    var textField = jQuery('<input type="text" value="+soep, oid" />');
+
        {
    $ul.append('<li>').append(button, textField);
+
            action: 'query',
 
+
             prop: 'revisions',
    button.click(function() {
+
            rvlimit: 1,
        var comment = textField.attr('value');
+
            rvprop: 'content',
        if (comment == '+soep, oid')
+
            titles: wgPageName,
             comment = '';
+
             rvsection: section_id,
        ajaxSubmitUserAndComment($title, comment);
+
            format: 'json'
    });
+
         },
 
+
         function( data ) {
    textField
+
             if ( data.query.pages && data.query.pageids ) {
        .css({color: 'lightgray'}) // TODO: use CSS class instead?
+
                var pageid = data.query.pageids[0];
        .focus(function() {
+
                 wgContent = data.query.pages[pageid].revisions['*'];
             if (this.value == '+soep, oid')
+
            }
                jQuery(this).val('').css({color: 'black'});
+
         }
         })
+
    )
         .blur(function() {
 
             if (this.value == '')
 
                 jQuery(this).val('+soep, oid').css({color: 'lightgray'});
 
         });
 
 
}
 
}
 +
jQuery().ready(function() {
 +
    getEditToken()
 +
    user = wgUserName;
 +
    if (user) {
 +
        console.log(user)
 +
        titels = '#Ik_kom_wel,#Ik_kom_niet,#Animo,#Aanwezig,#Afwezig,#Wie,#Wie_niet';
 +
        var user_is_al_in_lijst = jQuery(titels).parent().nextAll('ul').find('li a:contains("' + user + '")');
 +
console.log(user_is_al_in_lijst.length )
 +
        if (user_is_al_in_lijst.length) {
 +
            // user_is_al_in_lijst.parent().append('<input type="button" value="-"/>');
 +
        } else {
 +
            jQuery(titels).each(function(index, val) {
 +
                var ul = jQuery(val).parent().nextAll('ul:first')
 +
                var section_id = jQuery(val).parent().children('span').children('a').attr('href').match(/section=([0-9]+)/)[1]
 +
                var li = ul.append('<li><input type="button" value="' + user + '"/><input type="text" value="+soep, oid" /></li>');
 +
console.log(ul, section_id, li)
 +
                //ul.find('li:contains("...")').remove();
  
function ajaxSubmitUserAndComment($title, comment) {
+
                jQuery(li).find('input[type="button"]').click(function() {
    var section_id = $title.children('span a').attr('href').match(/section=([0-9]+)/)[1];
+
                    if (jQuery(this).next().attr('value') != "+soep, oid"){
    jQuery.ajax({
+
                        var comment = " " + jQuery(this).next().attr('value')
        url: wgScriptPath + '/api.php',
+
                    }
        data: {
+
                    if (!comment) comment = ''
            format: 'json',
+
                    jQuery.ajax({
            action: 'edit',
+
                        url: wgScriptPath + '/api.php',
            title: wgPageName,
+
                        data: {
            minor: true,
+
                            format: 'json',
            summary: 'Naam toegevoegd via button',
+
                            action: 'edit',
            section: section_id,
+
                            title: wgPageName,
            appendtext: '\n* {{Mentioneduserbutton|' + wgUserName + '}}'  + comment,
+
                            minor: true,
            token: wgEditToken
+
                            summary: 'naam toegevoegd via button',
        },
+
                            section: section_id,
        dataType: 'json',
+
                            appendtext: '\n* {{Mentioneduserbutton|' + wgUserName + '}}'  + comment,
        type: 'POST',
+
                            token: wgEditToken
        success: function(data) {
+
                        },
            window.location.href = window.location.href + '?' + new Date().getTime();
+
                        dataType: 'json',
            window.location.reload(true);
+
                        type: 'POST',
        },
+
                        success: function(data) {
        error: function(xhr) {
+
                            window.location.href = window.location.href + '?' + new Date().getTime();
            alert('Error: iets is mis gegaan, herlaad pagina en probeer opnieuw.');
+
                            window.location.reload(true);
 +
                        },
 +
                        error: function(xhr) {
 +
                            alert('Error: iets is mis gegaan, herlaad pagina en probeer opnieuw.');
 +
                        }
 +
                    });
 +
                });
 +
                jQuery(li).find('input[type="text"]').focus(function(){
 +
                        if(this.value == '+soep, oid') {
 +
                                this.value='';
 +
                                jQuery(this).css({'color':'black'});
 +
                        };
 +
                });
 +
                jQuery(li).find('input[type="text"]').css({'color':'lightgray'});
 +
               
 +
                jQuery(li).find('input[type="text"]').blur(function(){
 +
                        if(this.value == ''){
 +
                                this.value='+soep, oid';       
 +
                                jQuery(this).css({'color':'lightgray'});
 +
                        };
 +
                });
 +
            });
 
         }
 
         }
     });
+
     }
}
+
})

Versie van 7 mei 2013 15:39

/* JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers */
function getEditToken() {
    jQuery.getJSON(
        wgScriptPath + '/api.php?',
        {
            action: 'query',
            prop: 'info',
            intoken: 'edit',
            titles: 'Main Page',
            indexpageids: '',
            format: 'json'
        },
        function( data ) {
            if ( data.query.pages && data.query.pageids ) {
                var pageid = data.query.pageids[0];
                wgEditToken = data.query.pages[pageid].edittoken;
            }
        }
    )
}
function getSection(section_id) {
    jQuery.getJSON(
        wgScriptPath + '/api.php?',
        {
            action: 'query',
            prop: 'revisions',
            rvlimit: 1,
            rvprop: 'content',
            titles: wgPageName,
            rvsection: section_id,
            format: 'json'
        },
        function( data ) {
            if ( data.query.pages && data.query.pageids ) {
                var pageid = data.query.pageids[0];
                wgContent = data.query.pages[pageid].revisions['*'];
            }
        }
    )
}
jQuery().ready(function() {
    getEditToken()
    user = wgUserName;
    if (user) {
        console.log(user)
        titels = '#Ik_kom_wel,#Ik_kom_niet,#Animo,#Aanwezig,#Afwezig,#Wie,#Wie_niet';
        var user_is_al_in_lijst = jQuery(titels).parent().nextAll('ul').find('li a:contains("' + user + '")');
console.log(user_is_al_in_lijst.length )
        if (user_is_al_in_lijst.length) {
            // user_is_al_in_lijst.parent().append('<input type="button" value="-"/>');
        } else {
            jQuery(titels).each(function(index, val) {
                var ul = jQuery(val).parent().nextAll('ul:first')
                var section_id = jQuery(val).parent().children('span').children('a').attr('href').match(/section=([0-9]+)/)[1]
                var li = ul.append('<li><input type="button" value="' + user + '"/><input type="text" value="+soep, oid" /></li>');
console.log(ul, section_id, li)
                //ul.find('li:contains("...")').remove();

                jQuery(li).find('input[type="button"]').click(function() {
                    if (jQuery(this).next().attr('value') != "+soep, oid"){
                        var comment = " " + jQuery(this).next().attr('value')
                    }
                    if (!comment) comment = ''
                    jQuery.ajax({
                        url: wgScriptPath + '/api.php',
                        data: {
                            format: 'json',
                            action: 'edit',
                            title: wgPageName,
                            minor: true,
                            summary: 'naam toegevoegd via button',
                            section: section_id,
                            appendtext: '\n* {{Mentioneduserbutton|' + wgUserName + '}}'  + comment,
                            token: wgEditToken
                        },
                        dataType: 'json',
                        type: 'POST',
                        success: function(data) {
                            window.location.href = window.location.href + '?' + new Date().getTime();
                            window.location.reload(true);
                        },
                        error: function(xhr) {
                            alert('Error: iets is mis gegaan, herlaad pagina en probeer opnieuw.');
                        }
                    });
                });
                jQuery(li).find('input[type="text"]').focus(function(){
                        if(this.value == '+soep, oid') {
                                this.value='';
                                jQuery(this).css({'color':'black'});
                        };
                });
                jQuery(li).find('input[type="text"]').css({'color':'lightgray'});
                
                jQuery(li).find('input[type="text"]').blur(function(){
                        if(this.value == ''){
                                this.value='+soep, oid';        
                                jQuery(this).css({'color':'lightgray'});
                        };
                });
            });
        }
    }
})