FANDOM


//docs | talk | reference
/*
 * Function:	setThreadToolsMonobookCSS(isMessageWall)
 * 
 * Parameters:	boolean isMessageWall -- whether or not this is a Message Wall page
 * 
 * Description:	Appends CSS to <head> -- Monobook skin only
 * 
 * Called By:	initThreadTools()
 */
function setThreadToolsMonobookCSS(isMessageWall) {
	// Set container position to relative so that absolute positioning
    // works properly for the buttons in Monobook
    $('.speech-bubble-message').css('position', 'relative');
 
	if (isMessageWall) {
		// CSS , Monobook , Message Wall
        $('head').append(
        '<style type="text/css">' +
        '.threadButton { ' +
            ' display: none; float: none !important; position: absolute; top: -5px;' +
            ' margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; font-size: 11px;' +
            ' height: 21px; width: 75px; line-height: 15px; left: 15px; cursor: pointer;' +
        '}' +
        '.toggleUser {' +
            ' left: 105px;' +
        '}' +
        '.toggleThread {' +
            ' left: 195px;' +
        '}' +
        '.speech-bubble-message:hover .threadButton {' +
            ' display: block;' +
        '}' +
            '.threadButton:hover {' +
            ' display: block; width: 81px; height: 25px; top: -7px;'+
            ' line-height: 19px; margin-left: -3px' +
        '}' +
        '</style>');
 
        // Push stuff down to make additional room for the buttons
		$('.msg-title').css('padding-top','7px');
		$('li.message > .speech-bubble-message').css('top', '-10px').css('padding-top', '10px');
	} else {
		// CSS , Monobook , Article Comments
        $('head').append(
        '<style type="text/css">' +
        '.threadButton { ' +
            ' display: none; float: none !important; position: absolute; top: -5px;' +
            ' margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; font-size: 11px;' +
            ' height: 21px; width: 75px; line-height: 15px; left: 15px; cursor: pointer;' +
        '}' +
        '.toggleUser {' +
            ' left: 105px;' +
        '}' +
        '.toggleThread {' +
            ' left: 195px;' +
        '}' +
        '.speech-bubble-message:hover .threadButton {' +
            ' display: block;' +
        '}' +
            '.threadButton:hover {' +
            ' display: block; width: 81px; height: 25px; top: -7px;'+
            ' line-height: 19px; margin-left: -3px' +
        '}' +
        '</style>');
 
        // Push stuff down to make additional room for the buttons
		$('div.article-comm-text').css('top', '-12px').css('padding-top', '12px');
	}
}
 
/*
 * Function:	setThreadToolsOasisCSS(isMessageWall)
 * 
 * Parameters:	boolean isMessageWall -- whether or not this is a Message Wall page
 * 
 * Description:	Appends CSS to <head> -- Oasis skin only
 * 
 * Called By:	initThreadTools()
 */
function setThreadToolsOasisCSS(isMessageWall) {
	if (isMessageWall) {
		// CSS , Oasis , Message Wall
        $('head').append(
        '<style type="text/css">' +
        '.threadButton { ' +
            ' display: none; float: none !important; position: absolute; top: -5px;' +
            ' margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; font-size: 11px;' +
            ' height: 18px; width: 90px; line-height: 15px;' +
        '}' +
        '.toggleUser {' +
            ' left: 120px;' +
        '}' +
        '.toggleThread {' +
            ' left: 225px;' +
        '}' +
        '.speech-bubble-message:hover .threadButton {' +
            ' display: block;' +
        '}' +
            '.threadButton:hover {' +
        ' display: block; width: 96px; height: 22px; top: -7px;'+
            ' line-height: 19px; margin-left: -3px' +
        '}' +
        '</style>');
 
        // Push stuff down to make additional room for the buttons
		$('.msg-title').css('padding-top','5px');
		$('li.message > .speech-bubble-message').css('top', '-12px').css('padding-top', '12px');
	} else {
		// CSS , Oasis , Article Comments
        $('head').append(
        '<style type="text/css">' +
        '.threadButton { ' +
            ' display: none; float: none !important; position: absolute; top: -5px;' +
            ' margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; font-size: 11px;' +
            ' height: 18px; width: 90px; line-height: 15px;' +
        '}' +
        '.toggleUser {' +
            ' left: 120px;' +
        '}' +
        '.toggleThread {' +
            ' left: 225px;' +
        '}' +
        '.speech-bubble-message:hover .threadButton {' +
            ' display: block;' +
        '}' +
            '.threadButton:hover {' +
        ' display: block; width: 96px; height: 22px; top: -7px;'+
            ' line-height: 19px; margin-left: -3px' +
        '}' +
        '</style>');
	}
}
 
/*
 * Function:	initThreadTools()
 * 
 * Description:	Initializes the TheradTools user interface
 * 
 * Called By:	document.ready()
 * 
 * TO-DO-LIST: 	1) should be called by whatever event is triggered (ask Grunny?)
 * 				when viewing pages 2,3,etc of Article Comments and Message Wall Posts
 * 				2) Monobook CSS may need improvement
 */
function initThreadTools() {
	// Exit if there are 0 posts
	if (!$('.comments li').length) return;
 
	// boolean -- true if and only if this is a Message Wall page
	var isMessageWall = (wgCanonicalNamespace == "Thread" || wgCanonicalNamespace == "Message_Wall");
 
	// Text displayed for the various thread buttons
    var buttonTexts = {
        toggleComment: {
            true: 'Hide Post', false: 'Show Post'
        },
        toggleUser: {
            true: 'Hide User', false: 'Show User'
        },
        toggleThread: {
            true: 'Hide Thread', false: 'Show Thread'
        }
    };
 
    // Define needed CSS styles
    if (skin == "monobook") {
    	setThreadToolsMonobookCSS(isMessageWall);
    } else {
    	setThreadToolsOasisCSS(isMessageWall);
    }
 
    // create HTML string required to create a button
    function createButton (className) {
        return '<button class="threadButton ' + className + ' wikia-button secondary" type="button">'
            + buttonTexts[className][true] +
            '</button>';
    }
 
    // Add thread buttons to the DOM
    if (isMessageWall) {
    	$('li.message > .speech-bubble-message')
        .prepend(
            createButton('toggleComment') + createButton('toggleUser') + createButton('toggleThread')
        );
    } else {
    	$('.speech-bubble-message')
        .prepend(
            createButton('toggleComment') + createButton('toggleUser') + createButton('toggleThread')
        );
    }
 
    $('.threadButton')
    .data({
        on: true,
    })
    .click(function () {
        var on = !$(this).data('on');
        $(this).data('on', on)
        .text(function () {
            for (var i in buttonTexts) {
                if ($(this).hasClass(i)) {
                    return buttonTexts[i][on];
                }
            }
        })
        .trigger('toggle');
    });
 
    // Toggle Thread handler
    $('.toggleThread')
    .on('toggle', function () {
        console.log(
                ($(this).data('on') ? 'showing' : 'hiding') + ' thread'
        );
    });
 
    // Toggle User handler
    $('.toggleUser')
    .on('toggle', function () {
        console.log(
                ($(this).data('on') ? 'showing' : 'hiding') + ' user'
        );
    });
 
    // Toggle Comment handler
    $('.toggleComment')
    .on('toggle', function () {
        console.log(
                ($(this).data('on') ? 'showing' : 'hiding') + ' post'
        );
 
        // temporary functionality, testing purposes
        if (isMessageWall) {
        	$(this).siblings('.MiniEditorWrapper').find('.editarea').css('display', $(this).data('on') ? 'block' : 'none' );
        } else {
        	$(this).siblings('.article-comm-text').css('display', $(this).data('on') ? 'block' : 'none' );
        }
    });
 
    // Add "Source" button to "More" dropdown (Message Wall only):
    if (1200 == wgNamespaceNumber) {
 
        // Add the button:
        $('.buttonswrapper ul', '#Wall')
        .append('<li><a class="view-source" href="#"> Source </a></li>');
 
        // Log source to console:
        $('a.view-source', '#Wall')
        .click(function (e) {
            e.preventDefault();
            var id = $(this).parents('li.SpeechBubble:first').attr('data-id');
            $.get(wgServer + wgScript + '?curid=' + id + '&action=raw', function (data) {
                var m; if (m = data.match(/(.+)\<ac_metadata\s+title="([^"]+)"/)) {
                    console.log(m[1]);
                } else {
                    console.log(data);
                }
            });
        });
 
    // Add bracket pictogram and "source" link to article commments:
    } else {
 
        // Add pic and link:
        $('.tools', '#article-comments-ul')
        .prepend(
            '<img width="14" height="16" src="data:image/gif;base64,R0lGODlhDgAQAKIHAMfFy1VQZhsXLUU0lxgHaBQITC8fdQAAACH5BAEAAAcALAAAAAAOABAAAANJCKpxtyyQUkxxwVYhi/jOJxQENwlOemRTh6qrUUolHM9EDbOmrvK010/WE6aAOSOGGLQhPU7mxABoOBiUwXTwCgwsJZEoJBYkAAA7" alt="" />' +
            '<a class="view-source" href="#">source</a>'
        );
 
        // Log source to console:
        $('.view-source', '#article-comments-ul')
        .click(function (e) {
            e.preventDefault();
            var m, text = $(this).parents('.speech-bubble-message:first').children('.article-comm-text');
            if (m = text.attr('id').match(/\d+$/)) {
                $.get(wgServer + wgScript + '?curid=' + m.pop() + '&action=raw', function (data) {
                    console.log(data);
                });
            }
        });
    }
}
 
/*
 * Function:	document.ready()
 * 
 * Description:	Ensures that the user interface initializes after the page has loaded
 * 
 * Calls:		initThreadTools()
 */
$(function () {
    initThreadTools();
 
    // Reload ThreadTools when article comments paginate:
    if ('undefined' != typeof ArticleComments && ArticleComments.hasOwnProperty('addHover')) {
        ArticleComments.addHoverOverride = ArticleComments.addHover;
        ArticleComments.addHover = function () {
            ArticleComments.addHoverOverride();
            initThreadTools();
        }
    }
});
//

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.