Uit Hack42
Ga naar: navigatie, zoeken
(6 tussenliggende versies door 2 gebruikers niet weergegeven)
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');
 +
            var alreadyInList = $ul.find('li a:contains("'+user+'")').length > 0;
 +
            if ( ! alreadyInList) {
 +
                if ( ! $ul.length) {
 +
                    $ul = jQuery('<ul>').insertAfter($title);
 +
                }
 +
                addAddUserButton($title, $ul);
 +
            }
 +
        });
 +
    }
 +
});
 +
 
function getEditToken() {
 
function getEditToken() {
 
     jQuery.getJSON(
 
     jQuery.getJSON(
Regel 19: Regel 39:
 
     )
 
     )
 
}
 
}
function getSection(section_id) {
+
 
     jQuery.getJSON(
+
function addAddUserButton($title, $ul) {
        wgScriptPath + '/api.php?',
+
     var button = jQuery('<input type="button" value="'+user+'"/>');
        {
+
    var textField = jQuery('<input type="text" value="+soep, oid" />');
            action: 'query',
+
    $ul.append(jQuery('<li>').append(button, textField));
             prop: 'revisions',
+
 
            rvlimit: 1,
+
    button.click(function() {
            rvprop: 'content',
+
        var comment = textField.attr('value');
            titles: wgPageName,
+
        if (comment == '+soep, oid')
             rvsection: section_id,
+
             comment = '';
            format: 'json'
+
        ajaxSubmitUserAndComment($title, comment);
         },
+
    });
         function( data ) {
+
 
             if ( data.query.pages && data.query.pageids ) {
+
    textField
                 var pageid = data.query.pageids[0];
+
        .css({color: 'lightgray'}) // TODO: use CSS class instead?
                wgContent = data.query.pages[pageid].revisions['*'];
+
        .focus(function() {
            }
+
             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 + '")');
 
  
        if (user_is_al_in_lijst.length) {
+
function ajaxSubmitUserAndComment($title, comment) {
            // user_is_al_in_lijst.parent().append('<input type="button" value="-"/>');
+
    var $editButton = $title.find('span a');
        } else {
+
    if ($editButton.length) {
            jQuery(titels).each(function(index, val) {
+
        var section_id = $editButton.attr('href').match(/section=([0-9]+)/)[1];
                var ul = jQuery(val).parent().nextAll('ul:first')
+
        jQuery.ajax({
                var section_id = jQuery(val).parent().children('span').children('a').attr('href').match(/section=([0-9]+)/)[1]
+
            url: wgScriptPath + '/api.php',
                var li = ul.append('<li><input type="button" value="' + user + '"/><input type="text" value="+soep, oid" /></li>');
+
            data: {
                //ul.find('li:contains("...")').remove();
+
                format: 'json',
 
+
                action: 'edit',
                jQuery(li).find('input[type="button"]').click(function() {
+
                title: wgPageName,
                    if (jQuery(this).next().attr('value') != "+soep, oid"){
+
                minor: true,
                        var comment = " " + jQuery(this).next().attr('value')
+
                summary: 'Naam toegevoegd via button',
                    }
+
                section: section_id,
                    if (!comment) comment = ''
+
                appendtext: '\n* {{Mentioneduserbutton|' + wgUserName + '}}'  + comment,
                    jQuery.ajax({
+
                token: wgEditToken
                        url: wgScriptPath + '/api.php',
+
            },
                        data: {
+
            dataType: 'json',
                            format: 'json',
+
            type: 'POST',
                            action: 'edit',
+
            success: function(data) {
                            title: wgPageName,
+
                window.location.href = window.location.href + '?' + new Date().getTime();
                            minor: true,
+
                window.location.reload(true);
                            summary: 'naam toegevoegd via button',
+
            },
                            section: section_id,
+
            error: function(xhr) {
                            appendtext: '\n* {{Mentioneduserbutton|' + wgUserName + '}}'  + comment,
+
                alert('Error: iets is mis gegaan, herlaad pagina en probeer opnieuw.');
                            token: wgEditToken
+
            }
                        },
+
        });
                        dataType: 'json',
+
    } else {
                        type: 'POST',
+
        alert('Error: iets is mis gegaan, herlaad pagina en probeer opnieuw.');
                        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'});
 
                        };
 
                });
 
            });
 
        }
 
 
     }
 
     }
})
+
}

Versie van 7 mei 2013 14:59

/* 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');
            var alreadyInList = $ul.find('li a:contains("'+user+'")').length > 0;
            if ( ! alreadyInList) {
                if ( ! $ul.length) {
                    $ul = jQuery('<ul>').insertAfter($title);
                }
                addAddUserButton($title, $ul);
            }
        });
    }
});

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 addAddUserButton($title, $ul) {
    var button = jQuery('<input type="button" value="'+user+'"/>');
    var textField = jQuery('<input type="text" value="+soep, oid" />');
    $ul.append(jQuery('<li>').append(button, textField));

    button.click(function() {
        var comment = textField.attr('value');
        if (comment == '+soep, oid')
            comment = '';
        ajaxSubmitUserAndComment($title, comment);
    });

    textField
        .css({color: 'lightgray'}) // TODO: use CSS class instead?
        .focus(function() {
            if (this.value == '+soep, oid')
                jQuery(this).val('').css({color: 'black'});
        })
        .blur(function() {
            if (this.value == '')
                jQuery(this).val('+soep, oid').css({color: 'lightgray'});
        });
}

function ajaxSubmitUserAndComment($title, comment) {
    var $editButton = $title.find('span a');
    if ($editButton.length) {
        var section_id = $editButton.attr('href').match(/section=([0-9]+)/)[1];
        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.');
            }
        });
    } else {
        alert('Error: iets is mis gegaan, herlaad pagina en probeer opnieuw.');
    }
}