<commit_before>/**
 * Created by matthias on 28/10/14.
 */
$(document).ready(function() {

    /* --- SHOW/ADD COMMENT--- */

    $('.divComments').on('click', function (e) {
        var divComment = $(this),
            quitSpan = $('.quitSpanComment', this),
            etcSpan = $('.etcSpanComment', this),
            divFormComments = $('.divFormComments', this);
        e.stopPropagation();
        etcSpan.hide();
        divComment.addClass('divCommentsOpened');
        quitSpan.show();
        divFormComments.show();
        $('.inputComment', this).focus();
    });

    $('.inputComment').keydown(function (event) {
        var keycode = (event.keyCode ? event.keyCode : event.which);
        var postData = $(this).parent().serializeArray();
        var id = $(this).parent().attr('data-id');
        var input = $(this);
        if (keycode == '13') {
            var url = '/save/' + id;
            event.preventDefault();
            $.ajax({
                type: "POST",
                url: url,
                data: postData,
                success: function (e) {
                    input.css({
                        'box-shadow': '0px 2px 4px 0px green'
                    });
                    setTimeout(function () {
                        input.css('box-shadow', '');
                    }, 750);
                }
            });
        }
        else if (keycode == '27') {
            var divComment = $(this).closest('.divComments'),
                quitSpan = $('.quitSpanComment', divComment),
                etcSpan = $('.etcSpanComment', divComment),
                divFormComments = $('.divFormComments', divComment);
            quitSpan.hide();
            divComment.removeClass('divCommentsOpened');
            divFormComments.hide();
            etcSpan.fadeIn();
        }
    });

    $('.quitSpanComment').on('click', function (e) {
        e.stopPropagation();
        $(this).hide();
        var parr = $(this).parent();
        parr.removeClass('divCommentsOpened');
        $('.divFormComments', parr).hide();
        $('.etcSpanComment', parr).fadeIn();

    });

    /* --- END SHOW/ADD COMMENT---- */

    /* --- LIST OR GRID --- */

    $('.gridOrListButton').on('click', function () {
        if ($(this).css('opacity') != 1) {
            var id = $(this).attr('id');
            if (id != 'grid') {
                $('.idOfWord').hide();
                $('.methodsKeywords').css('position', 'static');
                $('.keywordsMethodsDisplayDone , .keywordsMethodsDisplay').addClass('keydorsInList');
                $(this).css('opacity', '1');
                $(this).siblings().css('opacity', '');
            }
            else {
                $('.idOfWord').show();
                $('.methodsKeywords').css('position', '');
                $('.keywordsMethodsDisplayDone , .keywordsMethodsDisplay').removeClass('keydorsInList');
                $(this).css('opacity', '1');
                $(this).siblings().css('opacity', '');
            }
        }
    });

    /* --- END LIST OR GRID --- */

    /* --- DISPLAY FULL ARTICLE --- */

    var isFullArticleShow = 'no',
        fullLoaded = 'no';

    $('#buttonFullArticle').on('click', function (e) {
        e.stopPropagation();
        if (isFullArticleShow == 'no') {

            var id = $('#validateButton').attr('data-id');
            $('#contentDisplay').hide();
            $(this).css({
                height: '100%',
                width: '100%',
                opacity: 1
            });

            $('#closeFullArticle').show(400);
            $('#spanFullArticle').hide();

            if (fullLoaded == 'no') {
                $('#fullArticleSection').load('/dump/' + id + '.xml').delay(560).fadeIn(400).delay(400).addClass('fullArticleSectionShow');
            }
            else {
                $('#fullArticleSection').delay(550).fadeIn();
            }

            isFullArticleShow = 'yes';
            fullLoaded = 'yes'

        }
    });

    $('#closeFullArticle').on('click', function (e) {
        e.stopPropagation();
        isFullArticleShow = 'no';
        $('#closeFullArticle').hide(300);
        $('#buttonFullArticle').css({
            height: '',
            width: '',
            opacity: '',
            overflow: 'hidden'
        });
        $('#fullArticleSection').hide();
        $('#spanFullArticle').fadeIn();
        $('#contentDisplay').fadeIn(450);

    });

    /* --- END DISPLAY  ARTICLE --- */

    /* --- CHANGE SCROLL STYLE --- */

    $("#sectionArticle , #keywordsDisplayDiv").scroller({
        customClass: "advanced"
    });

    /* --- END OF CHANGE SCROLL ---*/

    /* --- SHOW INIST KW BY METHOD --- */

    $("#inistKeywordsButton").click(
        function () {

            if ($('#keywordsInist').css('display') == 'none') {
                $(".methodsKeywords").animate({width: '50%'}, 400);
                $('#keywordsInist').show("slide", { direction: "right" }, 500);
                $('span', this).html('Cacher INIST');
                $(this).css({background: '#CC6A63'});
            }
            else {
                $(".methodsKeywords").animate({width: '100%'}, 400);
                $("#keywordsInist").hide("slide", { direction: "right" }, 400);
                $('span', this).html('Afficher INIST');
                $(this).css({background: ''})
            }

        }
    );

    /* --- END OF SHOW INIST ---*/

    /* --- COME BACK TO ABSTRACT --- */

    $("#sectionArticle").on('click', function () {
        if ($(this).css('opacity') !== '0.15') {
            if ($('#abstractFullLenght').css('display') == 'none') {
                $('#listOrGrid span').hide();
                $('#abstractFullLenght').css('display', 'block').siblings().not(".divHoverH1Display").hide();
                $('#keywordsInist').hide();
                $(".methodsKeywords").css('width', '100%');
                $("#inistKeywordsButton ").hide();
                $("#inistKeywordsButton > span").html('Afficher INIST');
                $("#inistKeywordsButton").css('background', 'rgba(204, 106, 99, 0.6)');
                $(".methodLinkround").css('borderColor', '');
            }
        }
    });

    /* --- END OF COME AbSTRACT ---*/

    /* ---CHANGE THE METHOD SHOW --- */

    $(".methodLinkround").click(
        function () {
            var id = $(this).attr('id');
            var nb = id.split('-');
            if ($('#abstractFullLenght').css('display') == 'block') {
                $('#abstractFullLenght').hide();
                $('#sectionArticle').css('opacity', '1');
                $("#keywordsDisplayDiv").show();
                $('#listOrGrid span').show();
                $('#methodButton-' + nb[1]).css('borderColor', '#CC6A63').siblings().css('borderColor', '');
            }
            if ($("#method" + nb[1] + 'ListOfKeywords').css('display') == 'none') {
                $('.methodsKeywords').not('#method' + nb[1] + 'ListOfKeywords').hide("slide", { direction: "right" }, 500);
                $('#method' + nb[1] + 'ListOfKeywords').show("slide", { direction: "left" }, 500);
                $('#methodButton-' + nb[1]).css('borderColor', '#CC6A63').siblings().css('borderColor', '');
                $('#keywordsInist .btn-default').hide();
                $('.inistForMethod-' + nb[1]).fadeIn().css('display', '');
            }
            if ($('#inistKeywordsButton').css('display') == 'none') {
                $('#inistKeywordsButton').css('display', 'block');
            }
        }
    );

    /* --- END OF CHANGE METHOD ---*/

    /* ---SUBMIT AJAX FORMS --- */

    // Validation

    $('#validateButton').on('click', function () {

        var id = $(this).attr('data-id');
        var url = '/save/' + id;

        if (!$(this).hasClass('isValidated')) {
            $.ajax({
                type: "POST",
                url: url,
                data: [
                    { name: "key", value: "validate"} ,
                    { name: "val", value: "yes"}
                ],
                success: function (e) {
                    $('#validateButton').removeClass('isNotValidated').addClass('isValidated');
                    $.ajax({
                        type: "POST",
                        url: url,
                        data: [
                            { name: "key", value: "fields.validate"} ,
                            { name: "val", value: "yes"}
                        ]
                    });
                }
            });
        }
        else {
            $.ajax({
                type: "POST",
                url: url,
                data: [
                    { name: "key", value: "validate"} ,
                    { name: "val", value: "no"}
                ],
                success: function (e) {
                    $('#validateButton').removeClass('isValidated').addClass('isNotValidated');
                    $.ajax({
                        type: "POST",
                        url: url,
                        data: [
                            { name: "key", value: "fields.validate"} ,
                            { name: "val", value: "no"}
                        ]
                    });
                }
            });
        }
    });

    // Keywords
    $(".formNotedKeyword input, .formNotedKeyword select").change(function (e) {
        var id = $(this).parent().attr('id');
        var postData = $(this).parent().serializeArray();
        var formURL = $(this).parent().attr("action");
        var li = $(this).parent().parent();

        $('#' + id + ' .loading').html('').show();

        $.ajax(
            {
                url: formURL,
                type: "POST",
                data: postData,
                success: function (e) {
                    setTimeout(function () {
                        $('#' + id + ' .loading').html('').fadeOut(750);
                        if (!li.hasClass("keywordsMethodsDisplayDone")) {
                            li.addClass("keywordsMethodsDisplayDone");
                            li.removeClass("keywordsMethodsisplay");
                            li.children('.formNotedKeywordsPreference').css('display', '');
                        }
                        li.css('box-shadow', '0px 1px 4px 0px green');
                        setTimeout(function () {
                            li.css('box-shadow', '');
                        }, 750);

                        // Check How many Keyworkds Are noted.

                        var pageId = $('#validateButton').attr('data-id');

                        $.getJSON( "/display/" + pageId + ".json", function( data ) {

                            var sourceKeywordsList = data.item.content.json.TEI.teiHeader.profileDesc.textClass.keywords,
                                nbSourceKeywordsListObject = Object.keys(sourceKeywordsList).length,
                                nbOfTotalSourceKeywords = 0;

                            for(var i = 0 ; i < nbSourceKeywordsListObject ; i ++){
                                if( (sourceKeywordsList[i].scheme != "inist-francis") && (sourceKeywordsList[i].scheme != "inist-pascal") && (sourceKeywordsList[i].scheme != "cc") && (sourceKeywordsList[i].scheme != "author") && (sourceKeywordsList[i]["xml#lang"] == "fr" )){
                                    var nbKW = Object.keys(sourceKeywordsList[i].term).length; // Get nb Of Keywords / Method
                                    nbOfTotalSourceKeywords += nbKW;
                                }
                            }

                            var notedKeywordsList = data.item.notedKeywords,
                                nbOfTotalNotedKeywords = 0;

                            for (var key in notedKeywordsList) {
                                var nbOfNotedKw = Object.keys(notedKeywordsList[key]).length; // Get nb Of Noted Keywords / Method
                                nbOfTotalNotedKeywords += nbOfNotedKw;
                            }

                            console.log(nbOfTotalNotedKeywords/nbOfTotalSourceKeywords);

                            if((nbOfTotalNotedKeywords/nbOfTotalSourceKeywords) === 1){
                                $('#validateButton').toggleClass("isDisable isNotValidated");
                                console.log("Tous les KW sont notés");
                            }

                        });

                    }, 900);

                },
                error: function () {

                }
            });
        e.preventDefault(); //STOP default action

    });

    /* --- END OF SUBMIT AJAX ---*/

});
<commit_msg>started progression ratio<commit_after>/**
 * Created by matthias on 28/10/14.
 */
$(document).ready(function() {

    /* --- SHOW/ADD COMMENT--- */

    $('.divComments').on('click', function (e) {
        var divComment = $(this),
            quitSpan = $('.quitSpanComment', this),
            etcSpan = $('.etcSpanComment', this),
            divFormComments = $('.divFormComments', this);
        e.stopPropagation();
        etcSpan.hide();
        divComment.addClass('divCommentsOpened');
        quitSpan.show();
        divFormComments.show();
        $('.inputComment', this).focus();
    });

    $('.inputComment').keydown(function (event) {
        var keycode = (event.keyCode ? event.keyCode : event.which);
        var postData = $(this).parent().serializeArray();
        var id = $(this).parent().attr('data-id');
        var input = $(this);
        if (keycode == '13') {
            var url = '/save/' + id;
            event.preventDefault();
            $.ajax({
                type: "POST",
                url: url,
                data: postData,
                success: function (e) {
                    input.css({
                        'box-shadow': '0px 2px 4px 0px green'
                    });
                    setTimeout(function () {
                        input.css('box-shadow', '');
                    }, 750);
                }
            });
        }
        else if (keycode == '27') {
            var divComment = $(this).closest('.divComments'),
                quitSpan = $('.quitSpanComment', divComment),
                etcSpan = $('.etcSpanComment', divComment),
                divFormComments = $('.divFormComments', divComment);
            quitSpan.hide();
            divComment.removeClass('divCommentsOpened');
            divFormComments.hide();
            etcSpan.fadeIn();
        }
    });

    $('.quitSpanComment').on('click', function (e) {
        e.stopPropagation();
        $(this).hide();
        var parr = $(this).parent();
        parr.removeClass('divCommentsOpened');
        $('.divFormComments', parr).hide();
        $('.etcSpanComment', parr).fadeIn();

    });

    /* --- END SHOW/ADD COMMENT---- */

    /* --- LIST OR GRID --- */

    $('.gridOrListButton').on('click', function () {
        if ($(this).css('opacity') != 1) {
            var id = $(this).attr('id');
            if (id != 'grid') {
                $('.idOfWord').hide();
                $('.methodsKeywords').css('position', 'static');
                $('.keywordsMethodsDisplayDone , .keywordsMethodsDisplay').addClass('keydorsInList');
                $(this).css('opacity', '1');
                $(this).siblings().css('opacity', '');
            }
            else {
                $('.idOfWord').show();
                $('.methodsKeywords').css('position', '');
                $('.keywordsMethodsDisplayDone , .keywordsMethodsDisplay').removeClass('keydorsInList');
                $(this).css('opacity', '1');
                $(this).siblings().css('opacity', '');
            }
        }
    });

    /* --- END LIST OR GRID --- */

    /* --- DISPLAY FULL ARTICLE --- */

    var isFullArticleShow = 'no',
        fullLoaded = 'no';

    $('#buttonFullArticle').on('click', function (e) {
        e.stopPropagation();
        if (isFullArticleShow == 'no') {

            var id = $('#validateButton').attr('data-id');
            $('#contentDisplay').hide();
            $(this).css({
                height: '100%',
                width: '100%',
                opacity: 1
            });

            $('#closeFullArticle').show(400);
            $('#spanFullArticle').hide();

            if (fullLoaded == 'no') {
                $('#fullArticleSection').load('/dump/' + id + '.xml').delay(560).fadeIn(400).delay(400).addClass('fullArticleSectionShow');
            }
            else {
                $('#fullArticleSection').delay(550).fadeIn();
            }

            isFullArticleShow = 'yes';
            fullLoaded = 'yes'

        }
    });

    $('#closeFullArticle').on('click', function (e) {
        e.stopPropagation();
        isFullArticleShow = 'no';
        $('#closeFullArticle').hide(300);
        $('#buttonFullArticle').css({
            height: '',
            width: '',
            opacity: '',
            overflow: 'hidden'
        });
        $('#fullArticleSection').hide();
        $('#spanFullArticle').fadeIn();
        $('#contentDisplay').fadeIn(450);

    });

    /* --- END DISPLAY  ARTICLE --- */

    /* --- CHANGE SCROLL STYLE --- */

    $("#sectionArticle , #keywordsDisplayDiv").scroller({
        customClass: "advanced"
    });

    /* --- END OF CHANGE SCROLL ---*/

    /* --- SHOW INIST KW BY METHOD --- */

    $("#inistKeywordsButton").click(
        function () {

            if ($('#keywordsInist').css('display') == 'none') {
                $(".methodsKeywords").animate({width: '50%'}, 400);
                $('#keywordsInist').show("slide", { direction: "right" }, 500);
                $('span', this).html('Cacher INIST');
                $(this).css({background: '#CC6A63'});
            }
            else {
                $(".methodsKeywords").animate({width: '100%'}, 400);
                $("#keywordsInist").hide("slide", { direction: "right" }, 400);
                $('span', this).html('Afficher INIST');
                $(this).css({background: ''})
            }

        }
    );

    /* --- END OF SHOW INIST ---*/

    /* --- COME BACK TO ABSTRACT --- */

    $("#sectionArticle").on('click', function () {
        if ($(this).css('opacity') !== '0.15') {
            if ($('#abstractFullLenght').css('display') == 'none') {
                $('#listOrGrid span').hide();
                $('#abstractFullLenght').css('display', 'block').siblings().not(".divHoverH1Display").hide();
                $('#keywordsInist').hide();
                $(".methodsKeywords").css('width', '100%');
                $("#inistKeywordsButton ").hide();
                $("#inistKeywordsButton > span").html('Afficher INIST');
                $("#inistKeywordsButton").css('background', 'rgba(204, 106, 99, 0.6)');
                $(".methodLinkround").css('borderColor', '');
            }
        }
    });

    /* --- END OF COME AbSTRACT ---*/

    /* ---CHANGE THE METHOD SHOW --- */

    $(".methodLinkround").click(
        function () {
            var id = $(this).attr('id');
            var nb = id.split('-');
            if ($('#abstractFullLenght').css('display') == 'block') {
                $('#abstractFullLenght').hide();
                $('#sectionArticle').css('opacity', '1');
                $("#keywordsDisplayDiv").show();
                $('#listOrGrid span').show();
                $('#methodButton-' + nb[1]).css('borderColor', '#CC6A63').siblings().css('borderColor', '');
            }
            if ($("#method" + nb[1] + 'ListOfKeywords').css('display') == 'none') {
                $('.methodsKeywords').not('#method' + nb[1] + 'ListOfKeywords').hide("slide", { direction: "right" }, 500);
                $('#method' + nb[1] + 'ListOfKeywords').show("slide", { direction: "left" }, 500);
                $('#methodButton-' + nb[1]).css('borderColor', '#CC6A63').siblings().css('borderColor', '');
                $('#keywordsInist .btn-default').hide();
                $('.inistForMethod-' + nb[1]).fadeIn().css('display', '');
            }
            if ($('#inistKeywordsButton').css('display') == 'none') {
                $('#inistKeywordsButton').css('display', 'block');
            }
        }
    );

    /* --- END OF CHANGE METHOD ---*/

    /* ---SUBMIT AJAX FORMS --- */

    // Validation

    $('#validateButton').on('click', function () {

        var id = $(this).attr('data-id');
        var url = '/save/' + id;

        if (!$(this).hasClass('isValidated')) {
            $.ajax({
                type: "POST",
                url: url,
                data: [
                    { name: "key", value: "validate"} ,
                    { name: "val", value: "yes"}
                ],
                success: function (e) {
                    $('#validateButton').removeClass('isNotValidated').addClass('isValidated');
                    $.ajax({
                        type: "POST",
                        url: url,
                        data: [
                            { name: "key", value: "fields.validate"} ,
                            { name: "val", value: "yes"}
                        ]
                    });
                }
            });
        }
        else {
            $.ajax({
                type: "POST",
                url: url,
                data: [
                    { name: "key", value: "validate"} ,
                    { name: "val", value: "no"}
                ],
                success: function (e) {
                    $('#validateButton').removeClass('isValidated').addClass('isNotValidated');
                    $.ajax({
                        type: "POST",
                        url: url,
                        data: [
                            { name: "key", value: "fields.validate"} ,
                            { name: "val", value: "no"}
                        ]
                    });
                }
            });
        }
    });

    // Keywords
    $(".formNotedKeyword input, .formNotedKeyword select").change(function (e) {
        var id = $(this).parent().attr('id');
        var postData = $(this).parent().serializeArray();
        var formURL = $(this).parent().attr("action");
        var li = $(this).parent().parent();

        $('#' + id + ' .loading').html('').show();

        $.ajax(
            {
                url: formURL,
                type: "POST",
                data: postData,
                success: function (e) {
                    setTimeout(function () {
                        $('#' + id + ' .loading').html('').fadeOut(750);
                        if (!li.hasClass("keywordsMethodsDisplayDone")) {
                            li.addClass("keywordsMethodsDisplayDone");
                            li.removeClass("keywordsMethodsisplay");
                            li.children('.formNotedKeywordsPreference').css('display', '');
                        }
                        li.css('box-shadow', '0px 1px 4px 0px green');
                        setTimeout(function () {
                            li.css('box-shadow', '');
                        }, 750);

                        // Check How many Keyworkds Are noted.

                        var pageId = $('#validateButton').attr('data-id');

                        $.getJSON( "/display/" + pageId + ".json", function( data ) {

                            var sourceKeywordsList = data.item.content.json.TEI.teiHeader.profileDesc.textClass.keywords,
                                nbSourceKeywordsListObject = Object.keys(sourceKeywordsList).length,
                                nbOfTotalSourceKeywords = 0;

                            for(var i = 0 ; i < nbSourceKeywordsListObject ; i ++){
                                if( (sourceKeywordsList[i].scheme != "inist-francis") && (sourceKeywordsList[i].scheme != "inist-pascal") && (sourceKeywordsList[i].scheme != "cc") && (sourceKeywordsList[i].scheme != "author") && (sourceKeywordsList[i]["xml#lang"] == "fr" )){
                                    var nbKW = Object.keys(sourceKeywordsList[i].term).length; // Get nb Of Keywords / Method
                                    nbOfTotalSourceKeywords += nbKW;
                                }
                            }

                            var notedKeywordsList = data.item.notedKeywords,
                                nbOfTotalNotedKeywords = 0;

                            for (var key in notedKeywordsList) {
                                var nbOfNotedKw = Object.keys(notedKeywordsList[key]).length; // Get nb Of Noted Keywords / Method
                                nbOfTotalNotedKeywords += nbOfNotedKw;
                            }

                            var ratio = nbOfTotalNotedKeywords/nbOfTotalSourceKeywords;

                            $.ajax(
                                {
                                    url: formURL,
                                    type: "POST",
                                    data: [
                                        { name: "key", value: "progressNotedKeywords"} ,
                                        { name: "val", value: ratio}
                                    ]
                                }
                            );

                            if((nbOfTotalNotedKeywords/nbOfTotalSourceKeywords) === 1){
                                $('#validateButton').toggleClass("isDisable isNotValidated");
                            }

                        });

                    }, 900);

                },
                error: function () {

                }
            });
        e.preventDefault(); //STOP default action

    });

    /* --- END OF SUBMIT AJAX ---*/

});
<|endoftext|>


<commit_before>/*!
 * fullcalendar-columns v1.10
 * Docs & License: https://github.com/mherrmann/fullcalendar-columns
 * (c) Michael Herrmann
 */
(function(root, factory) {
	/**
	 * Universal module definition following
	 * http://davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd:
	 */
	if (typeof define === 'function' && define.amd) // AMD
		define([ 'jquery', 'moment' ], factory);
	else if (typeof exports === 'object') // Node, CommonJS-like
		module.exports = factory(require('jquery'), require('moment'));
	else // Browser globals (root is window)
		root.returnExports = factory(jQuery, moment);
}(this, function($, moment) {
	var fc = $.fullCalendar;
	var AgendaView = fc.views.agenda.class || fc.views.agenda;
	fc.views.multiColAgenda = AgendaView.extend({
		originalEvents: null,
		fakeEvents: null,
		initialize: function() {
			this.numColumns = this.opt('numColumns');
			this.columnHeaders = this.opt('columnHeaders');
			AgendaView.prototype.initialize.call(this);
			this._monkeyPatchGridRendering();
		},
		renderEvents: function(events) {
			this.originalEvents = {};
			this.fakeEvents = [];
			for (var i = 0; i < events.length; i++) {
				var event = events[i];
				this.originalEvents[event._id] = event;
				this.fakeEvents.push(this._computeFakeEvent(event));
			}
			return AgendaView.prototype.renderEvents.call(
				this, this.fakeEvents
			);
		},
		trigger: function(name, thisObj) {
			var args = Array.prototype.slice.call(arguments);
			if (name == 'eventRender' || name == 'eventAfterRender'
				|| name == 'eventDestroy' || name == 'eventClick'
				|| name == 'eventMouseover' || name == 'eventMouseout')
				args[2] = this.originalEvents[args[2]._id];
			else if (name == 'dayClick' || name == 'dayRightclick' || name == 'select') {
				var date = this._computeOriginalEvent({ start: args[2] });
				args[2] = date.start;
				args[2].column = date.column;
			}
			return AgendaView.prototype.trigger.apply(this, args);
		},
		reportEventResize: function(event, location, largeUnit, el, ev) {
			return this._reportEventReschedule(
				'reportEventResize', event, location, largeUnit, el, ev
			);
		},
		reportEventDrop: function(event, location, largeUnit, el, ev) {
			return this._reportEventReschedule(
				'reportEventDrop', event, location, largeUnit, el, ev
			);
		},
		reportExternalDrop: function(meta, dropLocation, el, ev, ui) {
			var eventProps = meta.eventProps;
			var event;

			dropLocation = this._computeOriginalEvent(dropLocation);
			if (eventProps) {
				var eventInput = $.extend({}, eventProps, dropLocation);
				event = this.calendar.renderEvent(eventInput, meta.stick)[0];
			}

			this._triggerExternalDrop(event, dropLocation, el, ev, ui);
		},
		updateEvent: function(event) {
			$.extend(
				this._getFakeEvent(event._id), this._computeFakeEvent(event)
			);
		},
		computeRange: function(date) {
			var result = AgendaView.prototype.computeRange.call(this, date);
			var daysAvailable =
				this._countNonHiddenDaysBetween(result.start, result.end);
			var daysRequired = daysAvailable * this.numColumns;
			result.end = this._addNonHiddenDays(result.start, daysRequired);
			return result;
		},
		_monkeyPatchGridRendering: function() {
			var that = this;
			var origHeadCellHtml = this.timeGrid.headCellHtml;
			this.timeGrid.headCellHtml = function(cell) {
				/*
				 * Make multiple day header cells (each for one column) appear
				 * as one. The easiest way to do this would be to just render
				 * a single header cell with colspan=this.numColumns. However,
				 * this leads to misalignment between the day header cells and
				 * the events table. To get around this, we do render the same
				 * number of  cells as FullCalendar, but only fill the first
				 * one:
				 */
				var cellOrig = that._computeOriginalEvent(cell);
				var $html = $(origHeadCellHtml.call(this, cellOrig));
				var isFirstCellForDay = cellOrig.column == 0;
				var isLastCellForDay = cellOrig.column == that.numColumns - 1;

				var html = '';
				if (isFirstCellForDay) {
					// Make the cell appear centered:
					var posPercent = 100 * that.numColumns;
					html = '
'
					       + $html.html() + '
';
				} else {
					html = '

';
					$html.css('border-left-width', 0);
				}
				if (! isLastCellForDay)
					$html.css('border-right-width', 0);
				if (that.columnHeaders) {
					// Use the prefix 'fce-col-' (as in "FullCalendar
					// extension") for classes pertaining only to
					// fullcalendar-columns:
					html += '
' +
					        that.columnHeaders[cellOrig.column] + '
';
				}
				$html.html(html);
				return $html[0].outerHTML;
			};
			var origGetDayClasses = this.timeGrid.getDayClasses;
			this.timeGrid.getDayClasses = function(date) {
				var dateCol = that._computeOriginalEvent({ start: date });
				return origGetDayClasses.call(this, dateCol.start);
			};
		},
		_computeFakeEvent: function(event) {
			var result = $.extend({}, event);
			var start = this.calendar.moment(event.start);
			if (start >= this.start) {
				var daysDelta =
					moment.duration(event.start - this.start).days();
				var fakeDayOffset = daysDelta * this.numColumns + event.column;
				result.start = this._addNonHiddenDays(
					start.subtract(daysDelta, 'days'), fakeDayOffset
				);
				if ('end' in event) {
					var end = this.calendar.moment(event.end);
					result.end = this._addNonHiddenDays(
						end.subtract(daysDelta, 'days'), fakeDayOffset
					);
				}
			}
			return result;
		},
		_addNonHiddenDays: function(date, deltaDays) {
			var result = this.calendar.moment(date);
			for (var i=0; i < deltaDays; i++)
				result = this.skipHiddenDays(result.add(1, 'day'));
			return result;
		},
		_countNonHiddenDaysBetween: function(date1, date2) {
			for (var result=0; date1.isBefore(date2, 'day'); result++)
				date1 = this._addNonHiddenDays(date1, 1);
			return result;
		},
		_computeOriginalEvent: function(event) {
			var result = $.extend({}, event);
			var start = this.calendar.moment(event.start);
			if (start >= this.start) {
				var fakeDayOffset =
					this._countNonHiddenDaysBetween(this.start, start);
				result.column = fakeDayOffset % this.numColumns;
				var daysDelta = start.diff(this.start, 'days');
				var days = Math.floor(fakeDayOffset / this.numColumns);
				result.start = this._addNonHiddenDays(
					start.subtract(daysDelta, 'days'), days
				);
				if ('end' in event) {
					var end = this.calendar.moment(event.end);
					result.end = this._addNonHiddenDays(
						end.subtract(daysDelta, 'days'), days
					);
				}
			}
			return result;
		},
		_getFakeEvent: function(_id) {
			for (var i=0; i < this.fakeEvents.length; i++)
				if (this.fakeEvents[i]._id == _id)
					return this.fakeEvents[i];
		},
		_reportEventReschedule: function(
			rescheduleType, fakeEvent, location, largeUnit, el, ev
		) {
			fakeEvent.start = location.start.clone();
			fakeEvent.end = location.end.clone();
			var event = this.originalEvents[fakeEvent._id];
			if (event == null)
				return;
			location = this._computeOriginalEvent(location);
			return AgendaView.prototype[rescheduleType].call(
				this, event, location, largeUnit, el, ev
			);
		},
		_triggerExternalDrop: function(event, dropLocation, el, ev, ui) {
			// Trigger 'drop' regardless of whether element represents an event
			this.trigger('drop', el[0], dropLocation.start, ev, ui);
			if (event)
				this.trigger('eventReceive', null, event);
		}
	});
	var origFullCalendar = $.fn.fullCalendar;
	$.fn.fullCalendar = function(options) {
		if (options == 'updateEvent') { // Required by multiColAgenda
			var view = origFullCalendar.call(this, 'getView');
			if (view.updateEvent)
				view.updateEvent(arguments[1]);
		}
		return origFullCalendar.apply(this, arguments);
	};
}));
<commit_msg>Bug fixes and better integration with fc-rightclick<commit_after>/*!
 * fullcalendar-columns v1.11
 * Docs & License: https://github.com/mherrmann/fullcalendar-columns
 * (c) Michael Herrmann
 */
(function(root, factory) {
	/**
	 * Universal module definition following
	 * http://davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd:
	 */
	if (typeof define === 'function' && define.amd) // AMD
		define([ 'jquery', 'moment' ], factory);
	else if (typeof exports === 'object') // Node, CommonJS-like
		module.exports = factory(require('jquery'), require('moment'));
	else // Browser globals (root is window)
		root.returnExports = factory(jQuery, moment);
}(this, function($, moment) {
	var fc = $.fullCalendar;
	var AgendaView = fc.views.agenda.class || fc.views.agenda;
	fc.views.multiColAgenda = AgendaView.extend({
		originalEvents: null,
		fakeEvents: null,
		initialize: function() {
			this.numColumns = this.opt('numColumns');
			this.columnHeaders = this.opt('columnHeaders');
			AgendaView.prototype.initialize.call(this);
			this._monkeyPatchGridRendering();
		},
		renderEvents: function(events) {
			this.originalEvents = {};
			this.fakeEvents = [];
			for (var i = 0; i < events.length; i++) {
				var event = events[i];
				this.originalEvents[event._id] = event;
				this.fakeEvents.push(this._computeFakeEvent(event));
			}
			return AgendaView.prototype.renderEvents.call(
				this, this.fakeEvents
			);
		},
		trigger: function(name, thisObj) {
			var args = Array.prototype.slice.call(arguments);
			if (name == 'eventRender' || name == 'eventAfterRender'
				|| name == 'eventDestroy' || name == 'eventClick'
				|| name == 'eventMouseover' || name == 'eventMouseout'
				|| name == 'eventRightclick')
				args[2] = this.originalEvents[args[2]._id];
			else if (
				name == 'dayClick' || name == 'dayRightclick'
				|| name == 'select'
			) {
				var date = this._computeOriginalEvent({ start: args[2] });
				args[2] = date.start;
				args[2].column = date.column;
			}
			return AgendaView.prototype.trigger.apply(this, args);
		},
		reportEventResize: function(event, location, largeUnit, el, ev) {
			return this._reportEventReschedule(
				'reportEventResize', event, location, largeUnit, el, ev
			);
		},
		reportEventDrop: function(event, location, largeUnit, el, ev) {
			return this._reportEventReschedule(
				'reportEventDrop', event, location, largeUnit, el, ev
			);
		},
		reportExternalDrop: function(meta, dropLocation, el, ev, ui) {
			var eventProps = meta.eventProps;
			var event;

			dropLocation = this._computeOriginalEvent(dropLocation);
			if (eventProps) {
				var eventInput = $.extend({}, eventProps, dropLocation);
				event = this.calendar.renderEvent(eventInput, meta.stick)[0];
			}

			this._triggerExternalDrop(event, dropLocation, el, ev, ui);
		},
		updateEvent: function(event) {
			$.extend(
				this._getFakeEvent(event._id), this._computeFakeEvent(event)
			);
		},
		computeRange: function(date) {
			var result = AgendaView.prototype.computeRange.call(this, date);
			var daysAvailable =
				this._countNonHiddenDaysBetween(result.start, result.end);
			var daysRequired = daysAvailable * this.numColumns;
			result.end = this._addNonHiddenDays(result.start, daysRequired);
			return result;
		},
		_monkeyPatchGridRendering: function() {
			var that = this;
			var origHeadCellHtml = this.timeGrid.headCellHtml;
			this.timeGrid.headCellHtml = function(cell) {
				/*
				 * Make multiple day header cells (each for one column) appear
				 * as one. The easiest way to do this would be to just render
				 * a single header cell with colspan=this.numColumns. However,
				 * this leads to misalignment between the day header cells and
				 * the events table. To get around this, we do render the same
				 * number of  cells as FullCalendar, but only fill the first
				 * one:
				 */
				var cellOrig = that._computeOriginalEvent(cell);
				var $html = $(origHeadCellHtml.call(this, cellOrig));
				var isFirstCellForDay = cellOrig.column == 0;
				var isLastCellForDay = cellOrig.column == that.numColumns - 1;

				var html = '';
				if (isFirstCellForDay) {
					// Make the cell appear centered:
					var posPercent = 100 * that.numColumns;
					html = '
'
					       + $html.html() + '
';
				} else {
					html = '

';
					$html.css('border-left-width', 0);
				}
				if (! isLastCellForDay)
					$html.css('border-right-width', 0);
				if (that.columnHeaders) {
					// Use the prefix 'fce-col-' (as in "FullCalendar
					// extension") for classes pertaining only to
					// fullcalendar-columns:
					html += '
' +
					        that.columnHeaders[cellOrig.column] + '
';
				}
				$html.html(html);
				return $html[0].outerHTML;
			};
			var origGetDayClasses = this.timeGrid.getDayClasses;
			this.timeGrid.getDayClasses = function(date) {
				var dateCol = that._computeOriginalEvent({ start: date });
				return origGetDayClasses.call(this, dateCol.start);
			};
		},
		_computeFakeEvent: function(event) {
			var result = $.extend({}, event);
			var start = this.calendar.moment(event.start);
			if (start >= this.start) {
				var daysDelta =
					moment.duration(event.start - this.start).days();
				var fakeDayOffset = daysDelta * this.numColumns + event.column;
				result.start = this._addNonHiddenDays(
					start.subtract(daysDelta, 'days'), fakeDayOffset
				);
				if ('end' in event) {
					var end = this.calendar.moment(event.end);
					result.end = this._addNonHiddenDays(
						end.subtract(daysDelta, 'days'), fakeDayOffset
					);
				}
			}
			return result;
		},
		_addNonHiddenDays: function(date, deltaDays) {
			var result = this.calendar.moment(date);
			for (var i=0; i < deltaDays; i++)
				result = this.skipHiddenDays(result.add(1, 'day'));
			return result;
		},
		_countNonHiddenDaysBetween: function(date1, date2) {
			for (var result=0; date1.isBefore(date2, 'day'); result++)
				date1 = this._addNonHiddenDays(date1, 1);
			return result;
		},
		_computeOriginalEvent: function(event) {
			var result = $.extend({}, event);
			var start = this.calendar.moment(event.start);
			if (start >= this.start) {
				var fakeDayOffset =
					this._countNonHiddenDaysBetween(this.start, start);
				result.column = fakeDayOffset % this.numColumns;
				var daysDelta = start.diff(this.start, 'days');
				var days = Math.floor(fakeDayOffset / this.numColumns);
				result.start = this._addNonHiddenDays(
					start.subtract(daysDelta, 'days'), days
				);
				if ('end' in event) {
					var end = this.calendar.moment(event.end);
					result.end = this._addNonHiddenDays(
						end.subtract(daysDelta, 'days'), days
					);
				}
			}
			return result;
		},
		_getFakeEvent: function(_id) {
			for (var i=0; i < this.fakeEvents.length; i++)
				if (this.fakeEvents[i]._id == _id)
					return this.fakeEvents[i];
		},
		_reportEventReschedule: function(
			rescheduleType, fakeEvent, location, largeUnit, el, ev
		) {
			fakeEvent.start = location.start.clone();
			fakeEvent.end = location.end.clone();
			var event = this.originalEvents[fakeEvent._id];
			if (event == null)
				return;
			location = this._computeOriginalEvent(location);
			return AgendaView.prototype[rescheduleType].call(
				this, event, location, largeUnit, el, ev
			);
		},
		_triggerExternalDrop: function(event, dropLocation, el, ev, ui) {
			// Trigger 'drop' regardless of whether element represents an event
			this.trigger('drop', el[0], dropLocation.start, ev, ui);
			if (event)
				this.trigger('eventReceive', null, event);
		}
	});
	var origFullCalendar = $.fn.fullCalendar;
	$.fn.fullCalendar = function(options) {
		var view;
		if (options == 'updateEvent') { // Required by multiColAgenda
			view = origFullCalendar.call(this, 'getView');
			if (view.updateEvent)
				view.updateEvent(arguments[1]);
		} else if (options == 'clientEvents') {
			view = origFullCalendar.call(this, 'getView');
			if (view.calendar.clientEvents) {
				var origEvents = $.map(view.calendar.clientEvents(),
					function (fakeEvent) {
						return view.originalEvents[fakeEvent._id];
					}
				);
				// Mimic FC's clientEvents implementation:
				if ($.isFunction(arguments[1]))
					return $.grep(origEvents, arguments[1]);
				if (arguments[1] != null) {
					var filter = arguments[1] + '';
					return $.grep(origEvents, function(e) {
						return e._id == filter;
					});
				}
				return origEvents;
			}
		}
		return origFullCalendar.apply(this, arguments);
	};
}));
<|endoftext|>


<commit_before>function intval (mixed_var, base) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: stensi
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Matteo
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: intval('Kevin van Zonneveld');
    // *     returns 1: 0
    // *     example 2: intval(4.2);
    // *     returns 2: 4
    // *     example 3: intval(42, 8);
    // *     returns 3: 42
    // *     example 4: intval('09');
    // *     returns 4: 9

    var tmp;

    var type = typeof( mixed_var );

    if (type === 'boolean') {
        return (mixed_var) ? 1 : 0;
    } else if (type === 'string') {
        tmp = parseInt(mixed_var, base || 10);
        return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;
    } else if (type === 'number' && isFinite(mixed_var) ) {
        return Math.floor(mixed_var);
    } else {
        return 0;
    }
}<commit_msg>added intval comment<commit_after>function intval (mixed_var, base) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: stensi
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Matteo
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: intval('Kevin van Zonneveld');
    // *     returns 1: 0
    // *     example 2: intval(4.2);
    // *     returns 2: 4
    // *     example 3: intval(42, 8);
    // *     returns 3: 42
    // *     example 4: intval('09');
    // *     returns 4: 9
    // *     example 5: intval('1e', 16);
    // *     returns 5: 30

    var tmp;

    var type = typeof( mixed_var );

    if (type === 'boolean') {
        return (mixed_var) ? 1 : 0;
    } else if (type === 'string') {
        tmp = parseInt(mixed_var, base || 10);
        return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;
    } else if (type === 'number' && isFinite(mixed_var) ) {
        return Math.floor(mixed_var);
    } else {
        return 0;
    }
}<|endoftext|>


<commit_before>// ==UserScript==
// @name           futaba ID+IP popup
// @namespace      https://github.com/himuro-majika
// @description    同じIDやIPのレスをポップアップしちゃう
// @author         himuro_majika
// @note           赤福の「続きを読む」機能で読み込んだレスには反応しません。
// @note           適宜ページ全体をリロードしてください。
// @include        http://may.2chan.net/b/res/*
// @include        http://img.2chan.net/b/res/*
// @include        http://may.2chan.net/id/res/*
// @include        http://dec.2chan.net/53/res/*
// @include        http://dec.2chan.net/52/res/*
// @include        http://zip.2chan.net/1/res/*
// @include        http://zip.2chan.net/12/res/*
// @include        http://may.2chan.net/27/res/*
// @include        http://up.2chan.net/d/res/*
// @include        http://up.2chan.net/t/res/*
// @include        http://dat.2chan.net/21/res/*
// @include        http://up.2chan.net/e/res/*
// @include        http://up.2chan.net/j/res/*
// @include        http://nov.2chan.net/37/res/*
// @include        http://dat.2chan.net/45/res/*
// @include        http://up.2chan.net/r/res/*
// @include        http://jun.2chan.net/b/res/*
// @include        http://may.2chan.net/b/res/*
// @include        http://may.2chan.net/id/res/*
// @include        http://dat.2chan.net/23/res/*
// @include        http://jun.2chan.net/31/res/*
// @include        http://nov.2chan.net/28/res/*
// @include        http://zip.2chan.net/11/res/*
// @include        http://zip.2chan.net/14/res/*
// @include        http://zip.2chan.net/32/res/*
// @include        http://zip.2chan.net/8/res/*
// @include        http://jun.2chan.net/51/res/*
// @include        http://zip.2chan.net/5/res/*
// @include        http://zip.2chan.net/3/res/*
// @include        http://cgi.2chan.net/g/res/*
// @include        http://zip.2chan.net/2/res/*
// @include        http://dat.2chan.net/44/res/*
// @include        http://up.2chan.net/v/res/*
// @include        http://nov.2chan.net/y/res/*
// @include        http://dat.2chan.net/46/res/*
// @include        http://dat.2chan.net/22/res/*
// @include        http://up.2chan.net/x/res/*
// @include        http://nov.2chan.net/35/res/*
// @include        http://dec.2chan.net/50/res/*
// @include        http://dat.2chan.net/38/res/*
// @include        http://cgi.2chan.net/f/res/*
// @include        http://may.2chan.net/39/res/*
// @include        http://cgi.2chan.net/k/res/*
// @include        http://dat.2chan.net/l/res/*
// @include        http://may.2chan.net/40/res/*
// @include        http://zip.2chan.net/6/res/*
// @include        http://img.2chan.net/9/res/*
// @include        http://www.2chan.net/junbi/res/*
// @version        1.1
// @grant          GM_addStyle
// @license        MIT
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAAPUExURYv4i2PQYy2aLUe0R////zorx9oAAAAFdFJOU/////8A+7YOUwAAAElJREFUeNqUj1EOwDAIQoHn/c88bX+2fq0kRsAoUXVAfwzCttWsDWzw0kNVWd2tZ5K9gqmMZB8libt4pSg6YlO3RnTzyxePAAMAzqMDgTX8hYYAAAAASUVORK5CYII=
// ==/UserScript==
(function () {

	var Start = new Date().getTime();//count parsing time
	var saba = location.host.replace(".2chan.net","") +
		location.pathname.replace("futaba.htm","");
	var timer;

	setClassAndName();
	setEvent();
	setStyle();

	// ID/IPにclass,nameを設定する
	function setClassAndName() {
		var atd = document.evaluate(
			"/html/body/form/table/tbody/tr/td[@bgcolor]",
			document,
			null,
			XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
			null);
		for (var i = 0; i < atd.snapshotLength; i++) {
			var td = atd.snapshotItem(i);
			var id = [];
			id[i] = td.textContent.match(/I[DP]:\S+/);
			td.innerHTML = td.innerHTML.replace(/I[DP]:\S+/,
				"" + id[i]);
			td.innerHTML = td.innerHTML.replace(" No.", " No.");
		}
	}
	// イベントを設定
	function setEvent() {
		var aa = document.evaluate(
			"//a[@class='futaba_ip_popup_name']",
			document,
			null,
			XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
			null);
		for (var i = 0; i < aa.snapshotLength; i++) {
			var a = aa.snapshotItem(i);
			a.addEventListener("mouseover",show,true);
			a.addEventListener("mouseout",hide,true);
		}
	}
	// ポップアップを表示する
	function show(event) {
		delpop();
		var wX;	//ポップアップ表示位置X
		var wY;	//ポップアップ表示位置Y
		var tda = document.getElementsByName(this.name);
		var restable = [];
		for (var i = 0; i < tda.length; i++) {
			restable.push(tda[i].parentNode.parentNode.parentNode.innerHTML);
		}
		var table = document.createElement("table");
		table.id = "GM_fip_pop";
		table.innerHTML = restable.join(" ");
		table.addEventListener("mouseover",function(){
			clearTimeout(timer);
		},true);
		table.addEventListener("mouseout",hide,true);
		var body = document.getElementsByTagName("body");
		body[0].appendChild(table);
		wX = event.clientX;
		wY = window.scrollY + event.clientY - table.clientHeight;
		if ( wY < 0 ) {	//ポップアップが上に見きれる時は下に表示
			wY = window.scrollY + event.clientY;
		}
		table.setAttribute("style", "left:" + wX + "px; top:" + wY + "px;");
	}
	// ポップアップを消す
	function hide() {
		timer = setTimeout(delpop,250);
	}

	function delpop() {
		var doc_pop = document.getElementById("GM_fip_pop");
		if ( doc_pop ) {
			doc_pop.parentNode.removeChild(doc_pop);
		}
	}
	/*
	 * スタイル設定
	 */
	function setStyle() {
		var css = "#GM_fip_pop {" +
			"  position: absolute;" +
			"  z-index: 100;" +
			"  background-color: #eeaa88;"+
			"}" +
		"#GM_fip_pop > tbody > tr > td {" +
			"  color: #800000;" +
			"  font-size: 8pt !important;" +
			"}" +
		"#GM_fip_pop > tbody > tr > td > blockquote {" +
			"  margin-top: 0px !important;" +
			"  argin-bottom: 0px !important;" +
			"}" +
		".futaba_ip_popup_name {" +
			"  color: #F00;" +
			"}";
		if (typeof GM_addStyle != "undefined") {
			GM_addStyle(css);
		} else if (typeof addStyle != "undefined") {
			addStyle(css);
		} else {
			var heads = document.getElementsByTagName("head");
			if (heads.length > 0) {
				var node = document.createElement("style");
				node.type = "text/css";
				node.appendChild(document.createTextNode(css));
				heads[0].appendChild(node);
			}
		}
	}

	console.log('Parsing '+saba+': '+((new Date()).getTime()-Start) +'msec');//log parsing time

})();
<commit_msg>Change @include metadata<commit_after>// ==UserScript==
// @name           futaba ID+IP popup
// @namespace      https://github.com/himuro-majika
// @description    同じIDやIPのレスをポップアップしちゃう
// @author         himuro_majika
// @note           赤福の「続きを読む」機能で読み込んだレスには反応しません。
// @note           適宜ページ全体をリロードしてください。
// @include        http://*.2chan.net/*/res/*.htm
// @version        1.1
// @grant          GM_addStyle
// @license        MIT
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAAPUExURYv4i2PQYy2aLUe0R////zorx9oAAAAFdFJOU/////8A+7YOUwAAAElJREFUeNqUj1EOwDAIQoHn/c88bX+2fq0kRsAoUXVAfwzCttWsDWzw0kNVWd2tZ5K9gqmMZB8libt4pSg6YlO3RnTzyxePAAMAzqMDgTX8hYYAAAAASUVORK5CYII=
// ==/UserScript==
(function () {

	var Start = new Date().getTime();//count parsing time
	var saba = location.host.replace(".2chan.net","") +
		location.pathname.replace("futaba.htm","");
	var timer;

	setClassAndName();
	setEvent();
	setStyle();

	// ID/IPにclass,nameを設定する
	function setClassAndName() {
		var atd = document.evaluate(
			"/html/body/form/table/tbody/tr/td[@bgcolor]",
			document,
			null,
			XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
			null);
		for (var i = 0; i < atd.snapshotLength; i++) {
			var td = atd.snapshotItem(i);
			var id = [];
			id[i] = td.textContent.match(/I[DP]:\S+/);
			td.innerHTML = td.innerHTML.replace(/I[DP]:\S+/,
				"" + id[i]);
			td.innerHTML = td.innerHTML.replace(" No.", " No.");
		}
	}
	// イベントを設定
	function setEvent() {
		var aa = document.evaluate(
			"//a[@class='futaba_ip_popup_name']",
			document,
			null,
			XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
			null);
		for (var i = 0; i < aa.snapshotLength; i++) {
			var a = aa.snapshotItem(i);
			a.addEventListener("mouseover",show,true);
			a.addEventListener("mouseout",hide,true);
		}
	}
	// ポップアップを表示する
	function show(event) {
		delpop();
		var wX;	//ポップアップ表示位置X
		var wY;	//ポップアップ表示位置Y
		var tda = document.getElementsByName(this.name);
		var restable = [];
		for (var i = 0; i < tda.length; i++) {
			restable.push(tda[i].parentNode.parentNode.parentNode.innerHTML);
		}
		var table = document.createElement("table");
		table.id = "GM_fip_pop";
		table.innerHTML = restable.join(" ");
		table.addEventListener("mouseover",function(){
			clearTimeout(timer);
		},true);
		table.addEventListener("mouseout",hide,true);
		var body = document.getElementsByTagName("body");
		body[0].appendChild(table);
		wX = event.clientX;
		wY = window.scrollY + event.clientY - table.clientHeight;
		if ( wY < 0 ) {	//ポップアップが上に見きれる時は下に表示
			wY = window.scrollY + event.clientY;
		}
		table.setAttribute("style", "left:" + wX + "px; top:" + wY + "px;");
	}
	// ポップアップを消す
	function hide() {
		timer = setTimeout(delpop,250);
	}

	function delpop() {
		var doc_pop = document.getElementById("GM_fip_pop");
		if ( doc_pop ) {
			doc_pop.parentNode.removeChild(doc_pop);
		}
	}
	/*
	 * スタイル設定
	 */
	function setStyle() {
		var css = "#GM_fip_pop {" +
			"  position: absolute;" +
			"  z-index: 500;" +
			"  background-color: #eeaa88;"+
			"}" +
		"#GM_fip_pop > tbody > tr > td {" +
			"  color: #800000;" +
			"  font-size: 8pt !important;" +
			"}" +
		"#GM_fip_pop > tbody > tr > td > blockquote {" +
			"  margin-top: 0px !important;" +
			"  argin-bottom: 0px !important;" +
			"}" +
		".futaba_ip_popup_name {" +
			"  color: #F00;" +
			"}";
		if (typeof GM_addStyle != "undefined") {
			GM_addStyle(css);
		} else if (typeof addStyle != "undefined") {
			addStyle(css);
		} else {
			var heads = document.getElementsByTagName("head");
			if (heads.length > 0) {
				var node = document.createElement("style");
				node.type = "text/css";
				node.appendChild(document.createTextNode(css));
				heads[0].appendChild(node);
			}
		}
	}

	console.log('Parsing '+saba+': '+((new Date()).getTime()-Start) +'msec');//log parsing time

})();
<|endoftext|>


<commit_before>// Beaver: A beaver in the game.

var Class = require("classe");
var log = require(__basedir + "/gameplay/log");
var GameObject = require("./gameObject");

//<<-- Creer-Merge: requires -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

//<<-- /Creer-Merge: requires -->>

// @class Beaver: A beaver in the game.
var Beaver = Class(GameObject, {
    /**
     * Initializes Beavers.
     *
     * @param {Object} data - a simple mapping passed in to the constructor with whatever you sent with it. GameSettings are in here by key/value as well.
     */
    init: function(data) {
        GameObject.init.apply(this, arguments);

        /**
         * The number of actions remaining for the beaver this turn.
         *
         * @type {number}
         */
        this.actions = this.actions || 0;

        /**
         * The number of branches this beaver is holding.
         *
         * @type {number}
         */
        this.branches = this.branches || 0;

        /**
         * Number of turns this beaver is distracted for (0 means not distracted).
         *
         * @type {number}
         */
        this.distracted = this.distracted || 0;

        /**
         * The number of fish this beaver is holding.
         *
         * @type {number}
         */
        this.fish = this.fish || 0;

        /**
         * How much health this beaver has left.
         *
         * @type {number}
         */
        this.health = this.health || 0;

        /**
         * The Job this beaver was recruited to do.
         *
         * @type {Job}
         */
        this.job = this.job || null;

        /**
         * How many moves this beaver has left this turn.
         *
         * @type {number}
         */
        this.moves = this.moves || 0;

        /**
         * The Player that owns and can control this beaver.
         *
         * @type {Player}
         */
        this.owner = this.owner || null;

        /**
         * The tile this beaver is on.
         *
         * @type {Tile}
         */
        this.tile = this.tile || null;

        //<<-- Creer-Merge: init -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

        for(var key of this.job) {
            this[key] = this.job[key];
        }

        //<<-- /Creer-Merge: init -->>
    },

    gameObjectName: "Beaver",

    /**
     * Attacks another adjacent beaver.
     *
     * @param {Player} player - the player that called this.
     * @param {Tile} tile - The tile of the beaver you want to attack.
     * @param {function} asyncReturn - if you nest orders in this function you must return that value via this function in the order's callback.
     * @returns {boolean} True if successfully attacked, false otherwise.
     */
    attack: function(player, tile, asyncReturn) {
        // <<-- Creer-Merge: attack -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

        // Developer: Put your game logic for the Beaver's attack function here
        return false;

        // <<-- /Creer-Merge: attack -->>
    },

    /**
     * Builds a lodge on the Beavers current tile.
     *
     * @param {Player} player - the player that called this.
     * @param {function} asyncReturn - if you nest orders in this function you must return that value via this function in the order's callback.
     * @returns {boolean} True if successfully built a lodge, false otherwise.
     */
    buildLodge: function(player, asyncReturn) {
        // <<-- Creer-Merge: buildLodge -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

        // Developer: Put your game logic for the Beaver's buildLodge function here
        return false;

        // <<-- /Creer-Merge: buildLodge -->>
    },

    /**
     * Drops some of the given resource on the beaver's tile. Fish dropped in water disappear instantly, and fish dropped on land die one per tile per turn.
     *
     * @param {Player} player - the player that called this.
     * @param {string} resource - The type of resource to drop ('branch' or 'fish').
     * @param {number} amount - The amount of the resource to drop, numbers <= 0 will drop all of that type.
     * @param {function} asyncReturn - if you nest orders in this function you must return that value via this function in the order's callback.
     * @returns {boolean} True if successfully dropped the resource, false otherwise.
     */
    drop: function(player, resource, amount, asyncReturn) {
        // <<-- Creer-Merge: drop -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

        // Developer: Put your game logic for the Beaver's drop function here
        return false;

        // <<-- /Creer-Merge: drop -->>
    },

    /**
     * Harvests the branches or fish from a Spawner on an adjacent tile.
     *
     * @param {Player} player - the player that called this.
     * @param {Tile} tile - The tile you want to harvest.
     * @param {function} asyncReturn - if you nest orders in this function you must return that value via this function in the order's callback.
     * @returns {boolean} True if successfully harvested, false otherwise.
     */
    harvest: function(player, tile, asyncReturn) {
        // <<-- Creer-Merge: harvest -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
        let gathered = 0;

        if(tile === null) {
            // set reason
            return false;
        }
        if(tile.spawner === null) {
            // set reason
            return false;
        }
        if(!this.tile.hasNeighbor(tile)) {
            // set reason
            return false;
        }

        const load = this.fish + this.branches;

        if(load >= this.job.carryLimit) {
            // set reason
            return false;
        }

        const available = Math.pow(2, tile.spawner.health);
        const space = this.job.carryLimit - load;
        let skill = this.job.fishing;
        let container = this.fish;

        if(tile.spawner.type === "Branch") {
            skill = this.job.chopping;
            container = this.branches;
        }

        gathered = available < skill ? available : skill;
        gathered = gathered > space ? space : gathered;
        container += gathered;

        if(tile.spawner.health > 0) {
            tile.spawner.health--;
        }

        return gathered > 0;
        // <<-- /Creer-Merge: harvest -->>
    },

    /**
     * Moves this beaver from its current tile to an adjacent tile.
     *
     * @param {Player} player - the player that called this.
     * @param {Tile} tile - The tile this beaver should move to. Costs 2 moves normally, 3 if moving upstream, and 1 if moving downstream.
     * @param {function} asyncReturn - if you nest orders in this function you must return that value via this function in the order's callback.
     * @returns {boolean} True if the move worked, false otherwise.
     */
    move: function(player, tile, asyncReturn) {
        // <<-- Creer-Merge: move -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

        // Developer: Put your game logic for the Beaver's move function here
        return false;

        // <<-- /Creer-Merge: move -->>
    },

    /**
     * Picks up some branches or fish on the beaver's tile.
     *
     * @param {Player} player - the player that called this.
     * @param {string} resource - The type of resource to pickup ('branch' or 'fish').
     * @param {number} amount - The amount of the resource to drop, numbers <= 0 will pickup all of that type.
     * @param {function} asyncReturn - if you nest orders in this function you must return that value via this function in the order's callback.
     * @returns {boolean} True if successfully picked up a resource, false otherwise.
     */
    pickup: function(player, resource, amount, asyncReturn) {
        // <<-- Creer-Merge: pickup -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

        // Developer: Put your game logic for the Beaver's pickup function here
        return false;

        // <<-- /Creer-Merge: pickup -->>
    },

    //<<-- Creer-Merge: added-functions -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

    // You can add additional functions here. These functions will not be directly callable by client AIs

    //<<-- /Creer-Merge: added-functions -->>

});

module.exports = Beaver;
<commit_msg>Fix container updating<commit_after>// Beaver: A beaver in the game.

var Class = require("classe");
var log = require(__basedir + "/gameplay/log");
var GameObject = require("./gameObject");

//<<-- Creer-Merge: requires -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

//<<-- /Creer-Merge: requires -->>

// @class Beaver: A beaver in the game.
var Beaver = Class(GameObject, {
    /**
     * Initializes Beavers.
     *
     * @param {Object} data - a simple mapping passed in to the constructor with whatever you sent with it. GameSettings are in here by key/value as well.
     */
    init: function(data) {
        GameObject.init.apply(this, arguments);

        /**
         * The number of actions remaining for the beaver this turn.
         *
         * @type {number}
         */
        this.actions = this.actions || 0;

        /**
         * The number of branches this beaver is holding.
         *
         * @type {number}
         */
        this.branches = this.branches || 0;

        /**
         * Number of turns this beaver is distracted for (0 means not distracted).
         *
         * @type {number}
         */
        this.distracted = this.distracted || 0;

        /**
         * The number of fish this beaver is holding.
         *
         * @type {number}
         */
        this.fish = this.fish || 0;

        /**
         * How much health this beaver has left.
         *
         * @type {number}
         */
        this.health = this.health || 0;

        /**
         * The Job this beaver was recruited to do.
         *
         * @type {Job}
         */
        this.job = this.job || null;

        /**
         * How many moves this beaver has left this turn.
         *
         * @type {number}
         */
        this.moves = this.moves || 0;

        /**
         * The Player that owns and can control this beaver.
         *
         * @type {Player}
         */
        this.owner = this.owner || null;

        /**
         * The tile this beaver is on.
         *
         * @type {Tile}
         */
        this.tile = this.tile || null;

        //<<-- Creer-Merge: init -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

        for(var key of this.job) {
            this[key] = this.job[key];
        }

        //<<-- /Creer-Merge: init -->>
    },

    gameObjectName: "Beaver",

    /**
     * Attacks another adjacent beaver.
     *
     * @param {Player} player - the player that called this.
     * @param {Tile} tile - The tile of the beaver you want to attack.
     * @param {function} asyncReturn - if you nest orders in this function you must return that value via this function in the order's callback.
     * @returns {boolean} True if successfully attacked, false otherwise.
     */
    attack: function(player, tile, asyncReturn) {
        // <<-- Creer-Merge: attack -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

        // Developer: Put your game logic for the Beaver's attack function here
        return false;

        // <<-- /Creer-Merge: attack -->>
    },

    /**
     * Builds a lodge on the Beavers current tile.
     *
     * @param {Player} player - the player that called this.
     * @param {function} asyncReturn - if you nest orders in this function you must return that value via this function in the order's callback.
     * @returns {boolean} True if successfully built a lodge, false otherwise.
     */
    buildLodge: function(player, asyncReturn) {
        // <<-- Creer-Merge: buildLodge -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

        // Developer: Put your game logic for the Beaver's buildLodge function here
        return false;

        // <<-- /Creer-Merge: buildLodge -->>
    },

    /**
     * Drops some of the given resource on the beaver's tile. Fish dropped in water disappear instantly, and fish dropped on land die one per tile per turn.
     *
     * @param {Player} player - the player that called this.
     * @param {string} resource - The type of resource to drop ('branch' or 'fish').
     * @param {number} amount - The amount of the resource to drop, numbers <= 0 will drop all of that type.
     * @param {function} asyncReturn - if you nest orders in this function you must return that value via this function in the order's callback.
     * @returns {boolean} True if successfully dropped the resource, false otherwise.
     */
    drop: function(player, resource, amount, asyncReturn) {
        // <<-- Creer-Merge: drop -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

        // Developer: Put your game logic for the Beaver's drop function here
        return false;

        // <<-- /Creer-Merge: drop -->>
    },

    /**
     * Harvests the branches or fish from a Spawner on an adjacent tile.
     *
     * @param {Player} player - the player that called this.
     * @param {Tile} tile - The tile you want to harvest.
     * @param {function} asyncReturn - if you nest orders in this function you must return that value via this function in the order's callback.
     * @returns {boolean} True if successfully harvested, false otherwise.
     */
    harvest: function(player, tile, asyncReturn) {
        // <<-- Creer-Merge: harvest -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
        let gathered = 0;

        if(tile === null) {
            // set reason
            return false;
        }
        if(tile.spawner === null) {
            // set reason
            return false;
        }
        if(!this.tile.hasNeighbor(tile)) {
            // set reason
            return false;
        }

        const load = this.fish + this.branches;

        if(load >= this.job.carryLimit) {
            // set reason
            return false;
        }

        const available = Math.pow(2, tile.spawner.health);
        const space = this.job.carryLimit - load;
        let skill = this.job.fishing;
        let container = "fish";

        if(tile.spawner.type === "Branch") {
            skill = this.job.chopping;
            container = "branches";
        }

        gathered = available < skill ? available : skill;
        gathered = gathered > space ? space : gathered;
        this[container] += gathered;

        if(tile.spawner.health > 0) {
            tile.spawner.health--;
        }

        return gathered > 0;
        // <<-- /Creer-Merge: harvest -->>
    },

    /**
     * Moves this beaver from its current tile to an adjacent tile.
     *
     * @param {Player} player - the player that called this.
     * @param {Tile} tile - The tile this beaver should move to. Costs 2 moves normally, 3 if moving upstream, and 1 if moving downstream.
     * @param {function} asyncReturn - if you nest orders in this function you must return that value via this function in the order's callback.
     * @returns {boolean} True if the move worked, false otherwise.
     */
    move: function(player, tile, asyncReturn) {
        // <<-- Creer-Merge: move -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

        // Developer: Put your game logic for the Beaver's move function here
        return false;

        // <<-- /Creer-Merge: move -->>
    },

    /**
     * Picks up some branches or fish on the beaver's tile.
     *
     * @param {Player} player - the player that called this.
     * @param {string} resource - The type of resource to pickup ('branch' or 'fish').
     * @param {number} amount - The amount of the resource to drop, numbers <= 0 will pickup all of that type.
     * @param {function} asyncReturn - if you nest orders in this function you must return that value via this function in the order's callback.
     * @returns {boolean} True if successfully picked up a resource, false otherwise.
     */
    pickup: function(player, resource, amount, asyncReturn) {
        // <<-- Creer-Merge: pickup -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

        // Developer: Put your game logic for the Beaver's pickup function here
        return false;

        // <<-- /Creer-Merge: pickup -->>
    },

    //<<-- Creer-Merge: added-functions -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.

    // You can add additional functions here. These functions will not be directly callable by client AIs

    //<<-- /Creer-Merge: added-functions -->>

});

module.exports = Beaver;
<|endoftext|>