Uit Hack42
Ga naar: navigatie, zoeken
k
Regel 46: Regel 46:
 
         titels = '#Ik_kom_wel,#Ik_kom_niet,#Animo,#Aanwezig,#Afwezig,#Wie,#Wie_niet';
 
         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 + '")');
 
         var user_is_al_in_lijst = jQuery(titels).parent().nextAll('ul').find('li a:contains("' + user + '")');
console.log(user_is_al_in_lijst )
+
console.log(user_is_al_in_lijst.length )
 
         if (user_is_al_in_lijst.length) {
 
         if (user_is_al_in_lijst.length) {
 
             // user_is_al_in_lijst.parent().append('<input type="button" value="-"/>');
 
             // user_is_al_in_lijst.parent().append('<input type="button" value="-"/>');

Versie van 10 mrt 2013 00:05

/* 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>');
                //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'});
                        };
                });
            });
        }
    }
})