<commit_before>// Copyright (c) 2009, Scott Ferguson
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the software nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SCOTT FERGUSON ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL SCOTT FERGUSON BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

function HotKeyManager() {
    /*****************
     N - Next Post
     P/M - Previous Post
     J - Next Page
     K/H - Previous Page
     O - Reanchor thread
     Q - Quick Quote current post
     E - Quick Edit current post
     R - Quick Reply current thread
    *******************/
    this.bindHotKeys();

    this.thread_post_size = jQuery('div#thread > table.post').size();
    this.current_post = findFirstUnreadPost();
}

HotKeyManager.prototype.bindHotKeys = function() {
    var that = this;

    jQuery(document).keypress(function(event) {
        var quick_reply_block = false;

        if (findCurrentPage() == 'showthread.php') {
            if (quickReply.isExpanded() || quickReply.isVisible()) {
                quick_reply_block = true;
            }
        }

        if (!quick_reply_block) {
            switch(event.keyCode) {
                case 110:
                    // Next post
                    that.nextPost();
                    break;
                case 112:
                case 109:
                    // Previous post
                    that.previousPost();
                    break;
                case 106:
                    // Next page
                    that.nextPage();
                    break;
                case 107:
                case 104:
                    // Previous page
                    that.previousPage();
                    break;
                case 111:
                    // Re-anchor thread
                    that.anchorThread();
                    break;
                case 49: /* 1 */
                    // Jump to first post on the page
                    that.firstPost();
                    break;
                case 48: /* 0 */
                    // Jump to last post on the page
                    that.lastPost();
                    break;
                case 113:
                    // Quick quote current post
                    that.quoteCurrentPost();
                    break;
                case 101:
                    // Quick edit current post
                    break;
                case 114:
                    // TODO: Conditionalize on quick reply being enabled
                    that.displayQuickReply();
                    break;
                case 27:
                    // TODO: Conditionalize on quick reply being enabled
                    that.hideQuickReply();
                    break;
            }
        }
    });
};

HotKeyManager.prototype.nextPage = function() {
    this.pageCount = countPages();

    switch(findCurrentPage()) {
        case 'forumdisplay.php':
        case 'showthread.php':
            this.rootPageType = (findCurrentPage() == 'forumdisplay.php') ? 'forumid' : 'threadid';
            this.basePageID = findForumID();
            this.currentPage = Number(jQuery('span.curpage').html());
            if (this.currentPage <= 0)
                this.currentPage = 1;
            if (this.currentPage < this.pageCount)
                jumpToPage(this.rootPageType, this.basePageID, this.currentPage + 1);
            break;
    }
};

HotKeyManager.prototype.previousPage = function() {
    this.pageCount = countPages();

    switch(findCurrentPage()) {
        case 'forumdisplay.php':
        case 'showthread.php':
            this.rootPageType = (findCurrentPage() == 'forumdisplay.php') ? 'forumid' : 'threadid';
            this.basePageID = findForumID();
            this.currentPage = Number(jQuery('span.curpage').html());
            if (this.currentPage <= 0)
                this.currentPage = 1;
            if (this.currentPage > 1)
                jumpToPage(this.rootPageType, this.basePageID, this.currentPage - 1);
            break;
    }
};

HotKeyManager.prototype.nextPost = function() {
    if (!findCurrentPage() == 'showthread.php') {
        return;
    }

    if (this.current_post < (this.thread_post_size - 1)) {
        this.current_post++;
    }

    var post = jQuery('div#thread > table.post');
    var previous_post = post.eq(this.current_post - 1);
    var current_post = post.eq(this.current_post);
    previous_post.removeClass('selected-post');
    current_post.addClass('selected-post');

    jQuery(window).scrollTop(current_post.offset().top);
};

HotKeyManager.prototype.previousPost = function() {
    if (!findCurrentPage() == 'showthread.php') {
        return;
    }

    if (this.current_post > 0) {
        this.current_post--;
    }

    var post = jQuery('div#thread > table.post');
    var previous_post = post.eq(this.current_post + 1);
    var current_post = post.eq(this.current_post);
    previous_post.removeClass('selected-post');
    current_post.addClass('selected-post');

    jQuery(window).scrollTop(current_post.offset().top);
};

HotKeyManager.prototype.firstPost = function() {
    if (!findCurrentPage() == 'showthread.php') {
        return;
    }

    var post = jQuery('div#thread > table.post');
    var current_post = post.eq(this.current_post);

    if (this.current_post > 0) {
        var previous_post = post.eq(this.current_post);

        this.current_post=0;
        current_post = post.eq(this.current_post);

        previous_post.removeClass('selected-post');
        current_post.addClass('selected-post');
    }

    jQuery(window).scrollTop(current_post.offset().top);
};

HotKeyManager.prototype.lastPost = function() {
    if (!findCurrentPage() == 'showthread.php') {
        return;
    }

    var post = jQuery('div#thread > table.post');
    var current_post = post.eq(this.current_post);

    if (this.current_post < this.thread_post_size-1) {
        var previous_post = post.eq(this.current_post);

        this.current_post=this.thread_post_size-1;
        current_post = post.eq(this.current_post);

        previous_post.removeClass('selected-post');
        current_post.addClass('selected-post');
    }

    jQuery(window).scrollTop(current_post.offset().top);
};

HotKeyManager.prototype.anchorThread = function() {
    if (!findCurrentPage() == 'showthread.php') {
        return;
    } else if (this.current_post == -1) {
        return;
    }

    var post = jQuery('div#thread > table.post').eq(this.current_post);
    post.addClass('selected-post');

    jQuery(window).scrollTop(post.offset().top);
};

HotKeyManager.prototype.quoteCurrentPost = function() {
    if (this.current_post == -1) {
        return;
    }

    var current_post = jQuery('div#thread > table.post').eq(this.current_post);
    var username = jQuery('tr > td.userinfo > dl > dt.author', current_post).html();
    // Query for the quote
    var quote = jQuery('tr > td.postbody', current_post).clone();

    quickReply.appendQuote(username, quote);
    quickReply.show();
};

HotKeyManager.prototype.displayQuickReply = function() {
    if (findCurrentPage() == 'showthread.php') {
        quickReply.show();
    }
};

HotKeyManager.prototype.hideQuickReply = function() {
    if (findCurrentPage() == 'showthread.php') {
        quickReply.hide();
    }
};
<commit_msg>Don't increment next post until we've highlighted the first<commit_after>// Copyright (c) 2009, Scott Ferguson
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the software nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SCOTT FERGUSON ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL SCOTT FERGUSON BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

function HotKeyManager() {
    /*****************
     N - Next Post
     P/M - Previous Post
     J - Next Page
     K/H - Previous Page
     O - Reanchor thread
     Q - Quick Quote current post
     E - Quick Edit current post
     R - Quick Reply current thread
    *******************/
    this.bindHotKeys();

    this.thread_post_size = jQuery('div#thread > table.post').size();
    this.current_post = findFirstUnreadPost();
}

HotKeyManager.prototype.bindHotKeys = function() {
    var that = this;

    jQuery(document).keypress(function(event) {
        var quick_reply_block = false;

        if (findCurrentPage() == 'showthread.php') {
            if (quickReply.isExpanded() || quickReply.isVisible()) {
                quick_reply_block = true;
            }
        }

        if (!quick_reply_block) {
            switch(event.keyCode) {
                case 110:
                    // Next post
                    that.nextPost();
                    break;
                case 112:
                case 109:
                    // Previous post
                    that.previousPost();
                    break;
                case 106:
                    // Next page
                    that.nextPage();
                    break;
                case 107:
                case 104:
                    // Previous page
                    that.previousPage();
                    break;
                case 111:
                    // Re-anchor thread
                    that.anchorThread();
                    break;
                case 49: /* 1 */
                    // Jump to first post on the page
                    that.firstPost();
                    break;
                case 48: /* 0 */
                    // Jump to last post on the page
                    that.lastPost();
                    break;
                case 113:
                    // Quick quote current post
                    that.quoteCurrentPost();
                    break;
                case 101:
                    // Quick edit current post
                    break;
                case 114:
                    // TODO: Conditionalize on quick reply being enabled
                    that.displayQuickReply();
                    break;
                case 27:
                    // TODO: Conditionalize on quick reply being enabled
                    that.hideQuickReply();
                    break;
            }
        }
    });
};

HotKeyManager.prototype.nextPage = function() {
    this.pageCount = countPages();

    switch(findCurrentPage()) {
        case 'forumdisplay.php':
        case 'showthread.php':
            this.rootPageType = (findCurrentPage() == 'forumdisplay.php') ? 'forumid' : 'threadid';
            this.basePageID = findForumID();
            this.currentPage = Number(jQuery('span.curpage').html());
            if (this.currentPage <= 0)
                this.currentPage = 1;
            if (this.currentPage < this.pageCount)
                jumpToPage(this.rootPageType, this.basePageID, this.currentPage + 1);
            break;
    }
};

HotKeyManager.prototype.previousPage = function() {
    this.pageCount = countPages();

    switch(findCurrentPage()) {
        case 'forumdisplay.php':
        case 'showthread.php':
            this.rootPageType = (findCurrentPage() == 'forumdisplay.php') ? 'forumid' : 'threadid';
            this.basePageID = findForumID();
            this.currentPage = Number(jQuery('span.curpage').html());
            if (this.currentPage <= 0)
                this.currentPage = 1;
            if (this.currentPage > 1)
                jumpToPage(this.rootPageType, this.basePageID, this.currentPage - 1);
            break;
    }
};

HotKeyManager.prototype.nextPost = function() {
    if (!findCurrentPage() == 'showthread.php') {
        return;
    }

    var post = jQuery('div#thread > table.post');
    var previous_post = post.eq(this.current_post - 1);
    var current_post = post.eq(this.current_post);
    previous_post.removeClass('selected-post');
    current_post.addClass('selected-post');

    jQuery(window).scrollTop(current_post.offset().top);

    if (this.current_post < (this.thread_post_size - 1)) {
        this.current_post++;
    }
};

HotKeyManager.prototype.previousPost = function() {
    if (!findCurrentPage() == 'showthread.php') {
        return;
    }

    if (this.current_post > 0) {
        this.current_post--;
    }

    var post = jQuery('div#thread > table.post');
    var previous_post = post.eq(this.current_post + 1);
    var current_post = post.eq(this.current_post);
    previous_post.removeClass('selected-post');
    current_post.addClass('selected-post');

    jQuery(window).scrollTop(current_post.offset().top);
};

HotKeyManager.prototype.firstPost = function() {
    if (!findCurrentPage() == 'showthread.php') {
        return;
    }

    var post = jQuery('div#thread > table.post');
    var current_post = post.eq(this.current_post);

    if (this.current_post > 0) {
        var previous_post = post.eq(this.current_post);

        this.current_post=0;
        current_post = post.eq(this.current_post);

        previous_post.removeClass('selected-post');
        current_post.addClass('selected-post');
    }

    jQuery(window).scrollTop(current_post.offset().top);
};

HotKeyManager.prototype.lastPost = function() {
    if (!findCurrentPage() == 'showthread.php') {
        return;
    }

    var post = jQuery('div#thread > table.post');
    var current_post = post.eq(this.current_post);

    if (this.current_post < this.thread_post_size-1) {
        var previous_post = post.eq(this.current_post);

        this.current_post=this.thread_post_size-1;
        current_post = post.eq(this.current_post);

        previous_post.removeClass('selected-post');
        current_post.addClass('selected-post');
    }

    jQuery(window).scrollTop(current_post.offset().top);
};

HotKeyManager.prototype.anchorThread = function() {
    if (!findCurrentPage() == 'showthread.php') {
        return;
    } else if (this.current_post == -1) {
        return;
    }

    var post = jQuery('div#thread > table.post').eq(this.current_post);
    post.addClass('selected-post');

    jQuery(window).scrollTop(post.offset().top);
};

HotKeyManager.prototype.quoteCurrentPost = function() {
    if (this.current_post == -1) {
        return;
    }

    var current_post = jQuery('div#thread > table.post').eq(this.current_post);
    var username = jQuery('tr > td.userinfo > dl > dt.author', current_post).html();
    // Query for the quote
    var quote = jQuery('tr > td.postbody', current_post).clone();

    quickReply.appendQuote(username, quote);
    quickReply.show();
};

HotKeyManager.prototype.displayQuickReply = function() {
    if (findCurrentPage() == 'showthread.php') {
        quickReply.show();
    }
};

HotKeyManager.prototype.hideQuickReply = function() {
    if (findCurrentPage() == 'showthread.php') {
        quickReply.hide();
    }
};
<|endoftext|>


<commit_before>'use strict';

var assign = require('lodash/object/assign'),
    forEach = require('lodash/collection/forEach');

/**
 * A provider for BPMN 2.0 elements context pad
 */
function CustomContextPadProvider(contextPad, modeling, elementFactory,
                            connect, create, bpmnReplace,
                            canvas) {

    contextPad.registerProvider(this);

    this._contextPad = contextPad;

    this._modeling = modeling;

    this._elementFactory = elementFactory;
    this._connect = connect;
    this._create = create;
    this._bpmnReplace = bpmnReplace;
    this._canvas  = canvas;
}

CustomContextPadProvider.$inject = [
    'contextPad',
    'modeling',
    'elementFactory',
    'connect',
    'create',
    'bpmnReplace',
    'canvas'
];

CustomContextPadProvider.prototype.getContextPadEntries = function(element) {

    var contextPad = this._contextPad,
        modeling = this._modeling,

        elementFactory = this._elementFactory,
        connect = this._connect,
        create = this._create,
        bpmnReplace = this._bpmnReplace,
        canvas = this._canvas;

    var actions = {};

    if (element.type === 'label') {
        return actions;
    }

    var bpmnElement = element.businessObject;

    function startConnect(event, element, autoActivate) {
        connect.start(event, element, autoActivate);
    }

    function removeElement(e) {
        if (element.waypoints) {
            modeling.removeConnection(element);
        } else {
            modeling.removeShape(element);
        }
    }

    function getReplaceMenuPosition(element) {

        var Y_OFFSET = 5;

        var diagramContainer = canvas.getContainer(),
            pad = contextPad.getPad(element).html;

        var diagramRect = diagramContainer.getBoundingClientRect(),
            padRect = pad.getBoundingClientRect();

        var top = padRect.top - diagramRect.top;
        var left = padRect.left - diagramRect.left;

        var pos = {
            x: left,
            y: top + padRect.height + Y_OFFSET
        };

        return pos;
    }

    function appendAction(type, className, options) {

        function appendListener(event, element) {

            var shape = elementFactory.createShape(assign({ type: type }, options));
            create.start(event, shape, element);
        }

        var shortType = type.replace(/^bpmn\:/, '');

        return {
            group: 'model',
            className: className,
            title: 'Append ' + shortType,
            action: {
                dragstart: appendListener,
                click: appendListener
            }
        };
    }

    if (bpmnElement.$instanceOf('bpmn:FlowNode')) {

        if (!bpmnElement.$instanceOf('bpmn:EndEvent') &&
            !bpmnElement.$instanceOf('bpmn:EventBasedGateway') &&
            !isEventType(bpmnElement, 'bpmn:IntermediateThrowEvent', 'bpmn:LinkEventDefinition')) {

            assign(actions, {
                'append.end-event': appendAction('bpmn:EndEvent', 'icon-end-event-none'),
                'append.gateway': appendAction('bpmn:ExclusiveGateway', 'icon-gateway-xor'),
                'append.append-task': appendAction('bpmn:Task', 'icon-task'),
                'append.intermediate-event': appendAction('bpmn:IntermediateThrowEvent',
                    'icon-intermediate-event-none')
            });
        }

        if (bpmnElement.$instanceOf('bpmn:EventBasedGateway')) {

            assign(actions, {
                'append.receive-task': appendAction('bpmn:ReceiveTask', 'icon-receive-task'),
                'append.message-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
                    'icon-intermediate-event-catch-message',
                    { _eventDefinitionType: 'bpmn:MessageEventDefinition'}),
                'append.timer-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
                    'icon-intermediate-event-catch-timer',
                    { _eventDefinitionType: 'bpmn:TimerEventDefinition'}),
                'append.condtion-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
                    'icon-intermediate-event-catch-condition',
                    { _eventDefinitionType: 'bpmn:ConditionalEventDefinition'}),
                'append.signal-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
                    'icon-intermediate-event-catch-signal',
                    { _eventDefinitionType: 'bpmn:SignalEventDefinition'})
            });
        }

        // Replace menu entry
        if (!bpmnElement.$instanceOf('bpmn:SubProcess')) {

            assign(actions, {
                'replace': {
                    group: 'edit',
                    className: 'icon-screw-wrench',
                    title: 'Change type',
                    action: {
                        click: function(event, element) {
                            bpmnReplace.openChooser(getReplaceMenuPosition(element), element);
                        }
                    }
                }
            });
        }
    }

    if (bpmnElement.$instanceOf('bpmn:FlowNode') ||
        bpmnElement.$instanceOf('bpmn:InteractionNode')) {

        assign(actions, {
            'append.text-annotation': appendAction('bpmn:TextAnnotation', 'icon-text-annotation'),

            'connect': {
                group: 'connect',
                className: 'icon-connection-multi',
                title: 'Connect using Sequence/MessageFlow',
                action: {
                    click: startConnect,
                    dragstart: startConnect
                }
            }
        });
    }

    if (bpmnElement.$instanceOf('bpmn:Task')) {

        assign(actions, {
            'resource':{
                group: 'edit',
                className: 'icon-flag',
                title: 'Set Resource',
                action: {
                    click: function(event,element){
                        var bo=element.businessObject, inputtext;
                        if(bo.resources){

                            inputtext='Current Performer of the Task ('+ bo.id+') is "'+bo.resources[0].name+'".\r\n If you want to assign a new Performer fill out the form:';
                        }
                        else{
                            inputtext='Assign a Performer to the Task ('+ bo.id+'):';
                        }
                        //TODO provide a list for choosing
                        var result=window.prompt(inputtext);
                        if(result){
                            var resourceRole=elementFactory._bpmnFactory.create('bpmn:Performer',{name: result});
                            modeling.updateProperties(element,{'resources':[resourceRole]});
                        }
                    }
                }
            }
        });
    }

// TODO: Enable PartnerRole
/*
    if(bpmnElement.$instanceOf('bpmn:Participant')){

        assign(actions, {
            'partnerRole': {
                group: 'edit',
                className: 'icon-flag',
                title: 'Mark as AppEnsemble',
                action: {
                    click: function(event,element){
                        var bo=element.businessObject, inputtext;
                        var result=window.confirm('Do you really like to mark the Participant ('+ bo.id+') as AppEnsemble?');
                        if(result){
                            var PartnerRole=elementFactory._bpmnFactory.create('bpmn:PartnerRole',{'name': "AppEnsemble"});
                            var PartnerRoleShape=elementFactory.createShape({businessObject:PartnerRole});
                            modeling.updateProperties(PartnerRole,{'participantRef':bo});
                        }
                    }
                }
            }
        });

    }*/

    // Delete Element Entry
    assign(actions, {
        'delete': {
            group: 'edit',
            className: 'icon-trash',
            title: 'Remove',
            action: {
                click: removeElement,
                dragstart: removeElement
            }
        }
    });

    return actions;
};

function isEventType(eventBo, type, definition) {

    var isType = eventBo.$instanceOf(type);
    var isDefinition = false;

    var definitions = eventBo.eventDefinitions || [];
    forEach(definitions, function(def) {
        if (def.$type === definition) {
            isDefinition = true;
        }
    });

    return isType && isDefinition;
}

module.exports = CustomContextPadProvider;
<commit_msg>Established connection between ContextPad and PerformerChooser<commit_after>'use strict';

var assign = require('lodash/object/assign'),
    forEach = require('lodash/collection/forEach');

/**
 * A provider for BPMN 2.0 elements context pad
 */
function CustomContextPadProvider(contextPad, modeling, elementFactory,
                            connect, create, bpmnReplace,
                            canvas, performerChooser) {

    contextPad.registerProvider(this);

    this._contextPad = contextPad;

    this._modeling = modeling;

    this._elementFactory = elementFactory;
    this._connect = connect;
    this._create = create;
    this._bpmnReplace = bpmnReplace;
    this._canvas  = canvas;
    this._performerChooser=performerChooser;
}

CustomContextPadProvider.$inject = [
    'contextPad',
    'modeling',
    'elementFactory',
    'connect',
    'create',
    'bpmnReplace',
    'canvas',
    'performerChooser'
];

CustomContextPadProvider.prototype.getContextPadEntries = function(element) {

    var contextPad = this._contextPad,
        modeling = this._modeling,

        elementFactory = this._elementFactory,
        connect = this._connect,
        create = this._create,
        bpmnReplace = this._bpmnReplace,
        canvas = this._canvas,
        performerChooser=this._performerChooser;

    var actions = {};

    if (element.type === 'label') {
        return actions;
    }

    var bpmnElement = element.businessObject;

    function startConnect(event, element, autoActivate) {
        connect.start(event, element, autoActivate);
    }

    function removeElement(e) {
        if (element.waypoints) {
            modeling.removeConnection(element);
        } else {
            modeling.removeShape(element);
        }
    }

    function getReplaceMenuPosition(element) {

        var Y_OFFSET = 5;

        var diagramContainer = canvas.getContainer(),
            pad = contextPad.getPad(element).html;

        var diagramRect = diagramContainer.getBoundingClientRect(),
            padRect = pad.getBoundingClientRect();

        var top = padRect.top - diagramRect.top;
        var left = padRect.left - diagramRect.left;

        var pos = {
            x: left,
            y: top + padRect.height + Y_OFFSET
        };

        return pos;
    }

    function appendAction(type, className, options) {

        function appendListener(event, element) {

            var shape = elementFactory.createShape(assign({ type: type }, options));
            create.start(event, shape, element);
        }

        var shortType = type.replace(/^bpmn\:/, '');

        return {
            group: 'model',
            className: className,
            title: 'Append ' + shortType,
            action: {
                dragstart: appendListener,
                click: appendListener
            }
        };
    }

    if (bpmnElement.$instanceOf('bpmn:FlowNode')) {

        if (!bpmnElement.$instanceOf('bpmn:EndEvent') &&
            !bpmnElement.$instanceOf('bpmn:EventBasedGateway') &&
            !isEventType(bpmnElement, 'bpmn:IntermediateThrowEvent', 'bpmn:LinkEventDefinition')) {

            assign(actions, {
                'append.end-event': appendAction('bpmn:EndEvent', 'icon-end-event-none'),
                'append.gateway': appendAction('bpmn:ExclusiveGateway', 'icon-gateway-xor'),
                'append.append-task': appendAction('bpmn:Task', 'icon-task'),
                'append.intermediate-event': appendAction('bpmn:IntermediateThrowEvent',
                    'icon-intermediate-event-none')
            });
        }

        if (bpmnElement.$instanceOf('bpmn:EventBasedGateway')) {

            assign(actions, {
                'append.receive-task': appendAction('bpmn:ReceiveTask', 'icon-receive-task'),
                'append.message-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
                    'icon-intermediate-event-catch-message',
                    { _eventDefinitionType: 'bpmn:MessageEventDefinition'}),
                'append.timer-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
                    'icon-intermediate-event-catch-timer',
                    { _eventDefinitionType: 'bpmn:TimerEventDefinition'}),
                'append.condtion-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
                    'icon-intermediate-event-catch-condition',
                    { _eventDefinitionType: 'bpmn:ConditionalEventDefinition'}),
                'append.signal-intermediate-event': appendAction('bpmn:IntermediateCatchEvent',
                    'icon-intermediate-event-catch-signal',
                    { _eventDefinitionType: 'bpmn:SignalEventDefinition'})
            });
        }

        // Replace menu entry
        if (!bpmnElement.$instanceOf('bpmn:SubProcess')) {

            assign(actions, {
                'replace': {
                    group: 'edit',
                    className: 'icon-screw-wrench',
                    title: 'Change type',
                    action: {
                        click: function(event, element) {
                            bpmnReplace.openChooser(getReplaceMenuPosition(element), element);
                        }
                    }
                }
            });
        }
    }

    if (bpmnElement.$instanceOf('bpmn:FlowNode') ||
        bpmnElement.$instanceOf('bpmn:InteractionNode')) {

        assign(actions, {
            'append.text-annotation': appendAction('bpmn:TextAnnotation', 'icon-text-annotation'),

            'connect': {
                group: 'connect',
                className: 'icon-connection-multi',
                title: 'Connect using Sequence/MessageFlow',
                action: {
                    click: startConnect,
                    dragstart: startConnect
                }
            }
        });
    }

    if (bpmnElement.$instanceOf('bpmn:Task')) {

        assign(actions, {
            'resource':{
                group: 'edit',
                className: 'icon-flag',
                title: 'Set Resource',
                action: {
                    click: function(event,element){
                        performerChooser.openChooser(getReplaceMenuPosition(element), element);
                        var bo=element.businessObject, inputtext;
                        if(bo.resources){

                            inputtext='Current Performer of the Task ('+ bo.id+') is "'+bo.resources[0].name+'".\r\n If you want to assign a new Performer fill out the form:';
                        }
                        else{
                            inputtext='Assign a Performer to the Task ('+ bo.id+'):';
                        }
                        //TODO provide a list for choosing
                        var result=window.prompt(inputtext);
                        if(result){
                            var resourceRole=elementFactory._bpmnFactory.create('bpmn:Performer',{name: result});
                            modeling.updateProperties(element,{'resources':[resourceRole]});
                        }
                    }
                }
            }
        });
    }

// TODO: Enable PartnerRole
/*
    if(bpmnElement.$instanceOf('bpmn:Participant')){

        assign(actions, {
            'partnerRole': {
                group: 'edit',
                className: 'icon-flag',
                title: 'Mark as AppEnsemble',
                action: {
                    click: function(event,element){
                        var bo=element.businessObject, inputtext;
                        var result=window.confirm('Do you really like to mark the Participant ('+ bo.id+') as AppEnsemble?');
                        if(result){
                            var PartnerRole=elementFactory._bpmnFactory.create('bpmn:PartnerRole',{'name': "AppEnsemble"});
                            var PartnerRoleShape=elementFactory.createShape({businessObject:PartnerRole});
                            modeling.updateProperties(PartnerRole,{'participantRef':bo});
                        }
                    }
                }
            }
        });

    }*/

    // Delete Element Entry
    assign(actions, {
        'delete': {
            group: 'edit',
            className: 'icon-trash',
            title: 'Remove',
            action: {
                click: removeElement,
                dragstart: removeElement
            }
        }
    });

    return actions;
};

function isEventType(eventBo, type, definition) {

    var isType = eventBo.$instanceOf(type);
    var isDefinition = false;

    var definitions = eventBo.eventDefinitions || [];
    forEach(definitions, function(def) {
        if (def.$type === definition) {
            isDefinition = true;
        }
    });

    return isType && isDefinition;
}

module.exports = CustomContextPadProvider;
<|endoftext|>


<commit_before>import React, { PropTypes } from 'react';
import { Map, List } from 'immutable';
import cx from 'classnames';
import ThreadCommentMore from './thread-comment-more';

const ThreadComment = ({
  comment,
  cache,
  fetchMoreComments,
  shouldExpandChildren,
  toggleExpandChildren,
}) => {
  const data = comment.get('data');
  const commentId = data.get('id');
  const linkId = data.get('link_id');
  const childrenExpanded = shouldExpandChildren(commentId);

  // replies is an empty string if there are no replies
  const children = data.getIn(['replies', 'data', 'children'], List());

  return (

           toggleExpandChildren(commentId)}
            aria-hidden="true"
            className={cx(
            'fa', {
              'fa-chevron-down': childrenExpanded,
              'fa-chevron-right': !childrenExpanded,
            })}
            style={{cursor: 'pointer'}}
          />

{data.get('author')}

{data.get('body')}

        {
          childrenExpanded
            ? children.map((child, i) => {
              const childKind = child.get('kind');

              if (childKind === 'more') {
                return (
                  <ThreadCommentMore
                    linkId={linkId}
                    toggleExpandChildren={toggleExpandChildren}
                    shouldExpandChildren={shouldExpandChildren}
                    fetchMoreComments={fetchMoreComments}
                    comment={child}
                    cache={cache}
                    key={i} />
                );
              }

              return (
                <ThreadComment
                  toggleExpandChildren={toggleExpandChildren}
                  shouldExpandChildren={shouldExpandChildren}
                  fetchMoreComments={fetchMoreComments}
                  comment={child}
                  cache={cache}
                  key={i} />
              );
            })
          : []
        }

  );
};

ThreadComment.propTypes = {
  fetchMoreComments: PropTypes.func.isRequired,
  comment: PropTypes.instanceOf(Map).isRequired,
  cache: PropTypes.instanceOf(Map).isRequired,
  toggleExpandChildren: PropTypes.func.isRequired,
  shouldExpandChildren: PropTypes.func.isRequired,
};

export default ThreadComment;
<commit_msg>feat(thread-comment): Add comment score, and age<commit_after>import React, { PropTypes } from 'react';
import { Map, List } from 'immutable';
import cx from 'classnames';
import ThreadCommentMore from './thread-comment-more';

const ThreadComment = ({
  comment,
  cache,
  fetchMoreComments,
  shouldExpandChildren,
  toggleExpandChildren,
}) => {
  const data = comment.get('data');
  const commentId = data.get('id');
  const linkId = data.get('link_id');
  const childrenExpanded = shouldExpandChildren(commentId);

  // replies is an empty string if there are no replies
  const children = data.getIn(['replies', 'data', 'children'], List());

  return (

           toggleExpandChildren(commentId)}
            aria-hidden="true"
            className={cx(
            'fa', {
              'fa-chevron-down': childrenExpanded,
              'fa-chevron-right': !childrenExpanded,
            })}
            style={{cursor: 'pointer'}}
          />

              {data.get('author')}

              {data.get('score')} points

              {differenceInHours(Date.now() / 1000, data.get('created'))} hours ago

{data.get('body')}

        {
          childrenExpanded
            ? children.map((child, i) => {
              const childKind = child.get('kind');

              if (childKind === 'more') {
                return (
                  <ThreadCommentMore
                    linkId={linkId}
                    toggleExpandChildren={toggleExpandChildren}
                    shouldExpandChildren={shouldExpandChildren}
                    fetchMoreComments={fetchMoreComments}
                    comment={child}
                    cache={cache}
                    key={i} />
                );
              }

              return (
                <ThreadComment
                  toggleExpandChildren={toggleExpandChildren}
                  shouldExpandChildren={shouldExpandChildren}
                  fetchMoreComments={fetchMoreComments}
                  comment={child}
                  cache={cache}
                  key={i} />
              );
            })
          : []
        }

  );
};

function differenceInHours(now, then) {
  const SECONDS_IN_HOUR = 60 * 60;
  return Math.floor((now - then) / SECONDS_IN_HOUR);
}

ThreadComment.propTypes = {
  fetchMoreComments: PropTypes.func.isRequired,
  comment: PropTypes.instanceOf(Map).isRequired,
  cache: PropTypes.instanceOf(Map).isRequired,
  toggleExpandChildren: PropTypes.func.isRequired,
  shouldExpandChildren: PropTypes.func.isRequired,
};

export default ThreadComment;
<|endoftext|>


<commit_before>var mainCanvas = document.getElementById('canvas');
const MAX_CANVAS_WIDTH = mainCanvas.width;
const MAX_CANVAS_HEIGHT = mainCanvas.height;

var playField = (function () {

    const PUZZLE_HOVER_TINT = '#009900';

    var _stage,
        _canvas,
        _img,
        _pieces,
        _puzzleWidth,
        _puzzleHeight,
        _pieceWidth,
        _pieceHeight,
        _currentPiece,
        _currentDropPiece,
        _mouse,
        _puzzle_difficulty,
        mouse,
        puzzlePiece,
        playField,
        timer;

    mouse = (function () {
        var mouse = Object.create({});

        Object.defineProperty(mouse, 'init', {
            value: function (x, y) {
                this.x = x;
                this.y = y;
                return this;
            }
        });

        Object.defineProperty(mouse, 'x', {
            get: function () {
                return this._x;
            },
            set: function (value) {
                this._x = value;
            }
        });

        Object.defineProperty(mouse, 'y', {
            get: function () {
                return this._y;
            },
            set: function (value) {
                this._y = value;
            }
        });

        return mouse;
    }());

    puzzlePiece = (function () {
        var piece = Object.create({});

        Object.defineProperty(piece, 'init', {
            value: function (startX, startY) {
                this.startX = startX;
                this.startY = startY;
                this.currentX = startX;
                this.currentY = startY;
                return this;
            }
        });

        Object.defineProperty(piece, 'startX', {
            get: function () {
                return this._startX;
            },
            set: function (value) {
                this._startX = value;
            }
        });

        Object.defineProperty(piece, 'startY', {
            get: function () {
                return this._startY;
            },
            set: function (value) {
                this._startY = value;
            }
        });

        Object.defineProperty(piece, 'currentX', {
            get: function () {
                return this._currentX;
            },
            set: function (value) {
                this._currentX = value;
            }
        });

        Object.defineProperty(piece, 'currentY', {
            get: function () {
                return this._currentY;
            },
            set: function (value) {
                this._currentY = value;
            }
        });

        return piece;
    }());

    playField = (function () {
        var playfield = Object.create({});

        Object.defineProperty(playfield, 'init', {
            value: function (imageSrc, difficulty) {
                _img = new Image();
                _img.addEventListener('load', playField.onImage, false);
                _img.src = imageSrc;
                _puzzle_difficulty = difficulty;
                return this;
            }
        });

        Object.defineProperty(playfield, 'onImage', {
            value: function (e) {
                if (_img.width > MAX_CANVAS_WIDTH || _img.height > MAX_CANVAS_HEIGHT) {
                    var resizedImageSrc = resizeImage(_img);
                    _img.setAttribute('src', resizedImageSrc);
                }

                _pieceWidth = Math.floor(_img.width / _puzzle_difficulty);
                _pieceHeight = Math.floor(_img.height / _puzzle_difficulty);
                _puzzleWidth = _pieceWidth * _puzzle_difficulty;
                _puzzleHeight = _pieceHeight * _puzzle_difficulty;
                playField.setCanvas();
                playField.initPuzzle();
            }
        });

        Object.defineProperty(playfield, 'setCanvas', {
            value: function () {
                _canvas = document.getElementById('canvas');
                _stage = _canvas.getContext('2d');
                _canvas.width = _puzzleWidth;
                _canvas.height = _puzzleHeight;
                _canvas.style.border = "1px solid black";
            }
        });

        Object.defineProperty(playfield, 'initPuzzle', {
            value: function () {
                _pieces = [];
                _mouse = Object.create(mouse).init(0, 0);
                _currentPiece = null;
                _currentDropPiece = null;
                _stage.drawImage(_img, 0, 0, _puzzleWidth, _puzzleHeight, 0, 0, _puzzleWidth, _puzzleHeight);
                playField.createTitle("Click to Start Puzzle");
                playField.buildPieces();

                timerr.showTimer();
                timerr.resetTimer();
            }
        });

        Object.defineProperty(playfield, 'createTitle', {
            value: function (msg) {
                _stage.fillStyle = "#000000";
                _stage.globalAlpha = 0.4;
                _stage.fillRect(100, 0, _puzzleWidth - 200, 40);
                _stage.fillStyle = "#FFFFFF";
                _stage.globalAlpha = 1;
                _stage.textAlign = "center";
                _stage.textBaseline = "middle";
                _stage.font = "20px Arial";
                _stage.fillText(msg, _puzzleWidth / 2, 20);
            }
        });

        Object.defineProperty(playfield, 'buildPieces', {
            value: function () {
                var i,
                    piece,
                    puzzleDifficulty = _puzzle_difficulty * _puzzle_difficulty,
                    xPos = 0,
                    yPos = 0;

                for (i = 0; i < puzzleDifficulty; i += 1) {
                    piece = Object.create(puzzlePiece).init(xPos, yPos);
                    _pieces.push(piece);
                    xPos += _pieceWidth;
                    if (xPos >= _puzzleWidth) {
                        xPos = 0;
                        yPos += _pieceHeight;
                    }
                }
                _canvas.onmousedown = playField.shufflePuzzle;
            }
        });

        Object.defineProperty(playfield, 'shufflePuzzle', {
            value: function () {
                _pieces = playField.shuffleArray(_pieces);
                _stage.clearRect(0, 0, _puzzleWidth, _puzzleHeight);
                var i,
                    len,
                    piece,
                    xPos = 0,
                    yPos = 0;

                for (i = 0, len = _pieces.length; i < len; i += 1) {
                    piece = _pieces[i];
                    piece.currentX = xPos;
                    piece.currentY = yPos;
                    _stage.drawImage(_img, piece.startX, piece.startY, _pieceWidth, _pieceHeight, xPos, yPos, _pieceWidth, _pieceHeight);
                    _stage.strokeRect(xPos, yPos, _pieceWidth, _pieceHeight);
                    xPos += _pieceWidth;

                    if (xPos >= _puzzleWidth) {
                        xPos = 0;
                        yPos += _pieceHeight;
                    }
                }
                _canvas.onmousedown = playField.onPuzzleClick;

                timerr.startTimer();
                console.log('timer has been started!');
            }
        });

        Object.defineProperty(playfield, 'onPuzzleClick', {
            value: function (e) {
                if (e.layerX || e.layerX == 0) {
                    _mouse.x = e.layerX - _canvas.offsetLeft;
                    _mouse.y = e.layerY - _canvas.offsetTop;
                }
                else if (e.offsetX || e.offsetX == 0) {
                    _mouse.x = e.offsetX - _canvas.offsetLeft;
                    _mouse.y = e.offsetY - _canvas.offsetTop;
                }
                _currentPiece = playField.checkPieceClicked();

                if (_currentPiece != null) {
                    _stage.clearRect(_currentPiece.currentX, _currentPiece.currentY, _pieceWidth, _pieceHeight);
                    _stage.save();
                    _stage.globalAlpha = 0.9;
                    _stage.drawImage(_img, _currentPiece.startX, _currentPiece.startY, _pieceWidth, _pieceHeight, _mouse.x - (_pieceWidth / 2), _mouse.y - (_pieceHeight / 2), _pieceWidth, _pieceHeight);
                    _stage.restore();
                    _canvas.onmousemove = playField.updatePuzzle;
                    _canvas.onmouseup = playField.pieceDropped;
                }

            }
        });

        Object.defineProperty(playfield, 'checkPieceClicked', {
            value: function () {
                var i,
                    len,
                    piece;

                for (i = 0, len = _pieces.length; i < len; i += 1) {
                    piece = _pieces[i];
                    if (_mouse.x < piece.currentX || _mouse.x > (piece.currentX + _pieceWidth) ||
                        _mouse.y < piece.currentY || _mouse.y > (piece.currentY + _pieceHeight)) {
                        //PIECE NOT HIT
                    }
                    else {
                        return piece;
                    }
                }
                return null;
            }
        });

        Object.defineProperty(playfield, 'updatePuzzle', {
            value: function (e) {
                var i,
                    len,
                    piece;
                _currentDropPiece = null;

                if (e.layerX || e.layerX == 0) {
                    _mouse.x = e.layerX - _canvas.offsetLeft;
                    _mouse.y = e.layerY - _canvas.offsetTop;
                } else if (e.offsetX || e.offsetX == 0) {
                    _mouse.x = e.offsetX - _canvas.offsetLeft;
                    _mouse.y = e.offsetY - _canvas.offsetTop;
                }
                _stage.clearRect(0, 0, _puzzleWidth, _puzzleHeight);

                for (i = 0, len = _pieces.length; i < len; i += 1) {
                    piece = _pieces[i];
                    if (piece == _currentPiece) {
                        continue;
                    }

                    _stage.drawImage(_img, piece.startX, piece.startY, _pieceWidth, _pieceHeight, piece.currentX, piece.currentY, _pieceWidth, _pieceHeight);
                    _stage.strokeRect(piece.currentX, piece.currentY, _pieceWidth, _pieceHeight);

                    if (_currentDropPiece == null) {
                        if (_mouse.x < piece.currentX || _mouse.x > (piece.currentX + _pieceWidth) ||
                            _mouse.y < piece.currentY || _mouse.y > (piece.currentY + _pieceHeight)) {
                            //NOT OVER
                        }
                        else {
                            _currentDropPiece = piece;
                            _stage.save();
                            _stage.globalAlpha = 0.4;
                            _stage.fillStyle = PUZZLE_HOVER_TINT;
                            _stage.fillRect(_currentDropPiece.currentX,
                                _currentDropPiece.currentY,
                                _pieceWidth, _pieceHeight);
                            _stage.restore();
                        }
                    }
                }

                _stage.save();
                _stage.globalAlpha = 0.6;
                _stage.drawImage(_img, _currentPiece.startX, _currentPiece.startY, _pieceWidth, _pieceHeight,
                    _mouse.x - (_pieceWidth / 2), _mouse.y - (_pieceHeight / 2), _pieceWidth, _pieceHeight);
                _stage.restore();
                _stage.strokeRect(_mouse.x - (_pieceWidth / 2), _mouse.y - (_pieceHeight / 2), _pieceWidth, _pieceHeight);
            }
        });

        Object.defineProperty(playfield, 'pieceDropped', {
            value: function (e) {
                var tmp;

                _canvas.onmousemove = null;
                _canvas.onmouseup = null;
                if (_currentDropPiece != null) {
                    tmp = {xPos: _currentPiece.currentX, yPos: _currentPiece.currentY};
                    _currentPiece.currentX = _currentDropPiece.currentX;
                    _currentPiece.currentY = _currentDropPiece.currentY;
                    _currentDropPiece.currentX = tmp.xPos;
                    _currentDropPiece.currentY = tmp.yPos;
                }
                playField.resetPuzzleAndCheckWin();
            }
        });

        Object.defineProperty(playfield, 'resetPuzzleAndCheckWin', {
            value: function () {
                var i,
                    len,
                    piece,
                    gameWin = true;

                _stage.clearRect(0, 0, _puzzleWidth, _puzzleHeight);

                for (i = 0, len = _pieces.length; i < len; i += 1) {
                    piece = _pieces[i];
                    _stage.drawImage(_img, piece.startX, piece.startY, _pieceWidth, _pieceHeight, piece.currentX, piece.currentY, _pieceWidth, _pieceHeight);
                    _stage.strokeRect(piece.currentX, piece.currentY, _pieceWidth, _pieceHeight);
                    if (piece.currentX != piece.startX || piece.currentY != piece.startY) {
                        gameWin = false;
                    }
                }
                if (gameWin) {
                    setTimeout(playField.gameOver, 500);
                    timer.stopTimer();
                }
            }
        });

        Object.defineProperty(playfield, 'gameOver', {
            value: function () {
                _canvas.onmousedown = null;
                _canvas.onmousemove = null;
                _canvas.onmouseup = null;
                timerr.stopTimer();

                playField.initPuzzle();
            }
        });

        Object.defineProperty(playfield, 'shuffleArray', {
            value: function (o) {
                var j,
                    x,
                    i;

                for (j, x, i = o.length - 1; i > 0; i -= 1) {
                    j = parseInt(Math.random() * i);
                    x = o[i];
                    o[i] = o[j];
                    o[j] = x;
                }
                return o;
            }
        });

         timerr = (function () {
            var clsStopwatch = function () {
                var startAt = 0,
                    lapTime = 0;

                var now = function () {
                    return (new Date()).getTime();
                };

                this.start = function () {
                    startAt = startAt ? startAt : now();
                };

                this.stop = function () {
                    lapTime = startAt ? lapTime + now() - startAt : lapTime;
                    startAt = 0;
                };

                this.reset = function () {
                    lapTime = startAt = 0;
                };

                this.time = function () {
                    return lapTime + (startAt ? now() - startAt : 0);
                };
            };

            var playTime = new clsStopwatch(),
                timer,
                clocktimer;

            function pad(num, size) {
                var s = "0000" + num;
                return s.substr(s.length - size);
            }

            function formatTime(time) {
                var hours = 0,
                    minutes = 0,
                    seconds = 0,
                    newTime = '';

                hours = Math.floor(time / (60 * 60 * 1000));
                time = time % (60 * 60 * 1000);
                minutes = Math.floor(time / (60 * 1000));
                time = time % (60 * 1000);
                seconds = Math.floor(time / 1000);

                newTime = pad(hours, 2) + ':' + pad(minutes, 2) + ':' + pad(seconds, 2);
                return newTime;
            }

            var tmr = {
               showTimer:function() {
                timer = document.getElementById('timer');
                tmr.updateTimer();
            },

             updateTimer:function() {
                timer.innerHTML = formatTime(playTime.time());
            },

           startTimer: function () {
                clocktimer = setInterval("timerr.updateTimer()", 1000);
                playTime.start();
            },

            stopTimer:function () {
                playTime.stop();
                clearInterval(clocktimer);
            },

            resetTimer:function () {
                tmr.stopTimer();
                playTime.reset();
                tmr.updateTimer();
            }
        };

            return tmr;
        }());

        return playfield;
    }());

    return playField;
}());

function createPlayField(imageSrc, difficulty) {
    var plr = Object.create(playField).init(imageSrc, difficulty);
}

function resizeImage(img) {
    // Create off-screen canvas for resizing purposes
    var canvas = document.createElement('canvas'),
        ctx = canvas.getContext('2d');

    var width = img.width;
    var height = img.height;

    // Scale image
    if (width > height) {
        if (width > MAX_CANVAS_WIDTH) {
            height *= MAX_CANVAS_WIDTH / width;
            width = MAX_CANVAS_WIDTH;
        }
    } else {
        if (height > MAX_CANVAS_HEIGHT) {
            width *= MAX_CANVAS_HEIGHT / height;
            height = MAX_CANVAS_HEIGHT;
        }
    }

    // Set dimension to target size
    canvas.width = width;
    canvas.height = height;

    // Draw source image into the off-screen canvas:
    ctx.drawImage(img, 0, 0, width, height);

    // Encode image to Base64
    var newImage = canvas.toDataURL("image/png");
    return newImage;
}<commit_msg>Decoupled resizeImage function in puzzle.js<commit_after>var mainCanvas = document.getElementById('canvas');
const MAX_CANVAS_WIDTH = mainCanvas.width;
const MAX_CANVAS_HEIGHT = mainCanvas.height;

var playField = (function () {

    const PUZZLE_HOVER_TINT = '#009900';

    var _stage,
        _canvas,
        _img,
        _pieces,
        _puzzleWidth,
        _puzzleHeight,
        _pieceWidth,
        _pieceHeight,
        _currentPiece,
        _currentDropPiece,
        _mouse,
        _puzzle_difficulty,
        mouse,
        puzzlePiece,
        playField,
        timer;

    mouse = (function () {
        var mouse = Object.create({});

        Object.defineProperty(mouse, 'init', {
            value: function (x, y) {
                this.x = x;
                this.y = y;
                return this;
            }
        });

        Object.defineProperty(mouse, 'x', {
            get: function () {
                return this._x;
            },
            set: function (value) {
                this._x = value;
            }
        });

        Object.defineProperty(mouse, 'y', {
            get: function () {
                return this._y;
            },
            set: function (value) {
                this._y = value;
            }
        });

        return mouse;
    }());

    puzzlePiece = (function () {
        var piece = Object.create({});

        Object.defineProperty(piece, 'init', {
            value: function (startX, startY) {
                this.startX = startX;
                this.startY = startY;
                this.currentX = startX;
                this.currentY = startY;
                return this;
            }
        });

        Object.defineProperty(piece, 'startX', {
            get: function () {
                return this._startX;
            },
            set: function (value) {
                this._startX = value;
            }
        });

        Object.defineProperty(piece, 'startY', {
            get: function () {
                return this._startY;
            },
            set: function (value) {
                this._startY = value;
            }
        });

        Object.defineProperty(piece, 'currentX', {
            get: function () {
                return this._currentX;
            },
            set: function (value) {
                this._currentX = value;
            }
        });

        Object.defineProperty(piece, 'currentY', {
            get: function () {
                return this._currentY;
            },
            set: function (value) {
                this._currentY = value;
            }
        });

        return piece;
    }());

    playField = (function () {
        var playfield = Object.create({});

        Object.defineProperty(playfield, 'init', {
            value: function (imageSrc, difficulty) {
                _img = new Image();
                _img.addEventListener('load', playField.onImage, false);
                _img.src = imageSrc;
                _puzzle_difficulty = difficulty;
                return this;
            }
        });

        Object.defineProperty(playfield, 'onImage', {
            value: function (e) {
                if (_img.width > MAX_CANVAS_WIDTH || _img.height > MAX_CANVAS_HEIGHT) {
                    var resizedImageSrc = resizeImage(_img, MAX_CANVAS_WIDTH, MAX_CANVAS_HEIGHT);
                    _img.setAttribute('src', resizedImageSrc);
                }

                _pieceWidth = Math.floor(_img.width / _puzzle_difficulty);
                _pieceHeight = Math.floor(_img.height / _puzzle_difficulty);
                _puzzleWidth = _pieceWidth * _puzzle_difficulty;
                _puzzleHeight = _pieceHeight * _puzzle_difficulty;
                playField.setCanvas();
                playField.initPuzzle();
            }
        });

        Object.defineProperty(playfield, 'setCanvas', {
            value: function () {
                _canvas = document.getElementById('canvas');
                _stage = _canvas.getContext('2d');
                _canvas.width = _puzzleWidth;
                _canvas.height = _puzzleHeight;
                _canvas.style.border = "1px solid black";
            }
        });

        Object.defineProperty(playfield, 'initPuzzle', {
            value: function () {
                _pieces = [];
                _mouse = Object.create(mouse).init(0, 0);
                _currentPiece = null;
                _currentDropPiece = null;
                _stage.drawImage(_img, 0, 0, _puzzleWidth, _puzzleHeight, 0, 0, _puzzleWidth, _puzzleHeight);
                playField.createTitle("Click to Start Puzzle");
                playField.buildPieces();

                timerr.showTimer();
                timerr.resetTimer();
            }
        });

        Object.defineProperty(playfield, 'createTitle', {
            value: function (msg) {
                _stage.fillStyle = "#000000";
                _stage.globalAlpha = 0.4;
                _stage.fillRect(100, 0, _puzzleWidth - 200, 40);
                _stage.fillStyle = "#FFFFFF";
                _stage.globalAlpha = 1;
                _stage.textAlign = "center";
                _stage.textBaseline = "middle";
                _stage.font = "20px Arial";
                _stage.fillText(msg, _puzzleWidth / 2, 20);
            }
        });

        Object.defineProperty(playfield, 'buildPieces', {
            value: function () {
                var i,
                    piece,
                    puzzleDifficulty = _puzzle_difficulty * _puzzle_difficulty,
                    xPos = 0,
                    yPos = 0;

                for (i = 0; i < puzzleDifficulty; i += 1) {
                    piece = Object.create(puzzlePiece).init(xPos, yPos);
                    _pieces.push(piece);
                    xPos += _pieceWidth;
                    if (xPos >= _puzzleWidth) {
                        xPos = 0;
                        yPos += _pieceHeight;
                    }
                }
                _canvas.onmousedown = playField.shufflePuzzle;
            }
        });

        Object.defineProperty(playfield, 'shufflePuzzle', {
            value: function () {
                _pieces = playField.shuffleArray(_pieces);
                _stage.clearRect(0, 0, _puzzleWidth, _puzzleHeight);
                var i,
                    len,
                    piece,
                    xPos = 0,
                    yPos = 0;

                for (i = 0, len = _pieces.length; i < len; i += 1) {
                    piece = _pieces[i];
                    piece.currentX = xPos;
                    piece.currentY = yPos;
                    _stage.drawImage(_img, piece.startX, piece.startY, _pieceWidth, _pieceHeight, xPos, yPos, _pieceWidth, _pieceHeight);
                    _stage.strokeRect(xPos, yPos, _pieceWidth, _pieceHeight);
                    xPos += _pieceWidth;

                    if (xPos >= _puzzleWidth) {
                        xPos = 0;
                        yPos += _pieceHeight;
                    }
                }
                _canvas.onmousedown = playField.onPuzzleClick;

                timerr.startTimer();
                console.log('timer has been started!');
            }
        });

        Object.defineProperty(playfield, 'onPuzzleClick', {
            value: function (e) {
                if (e.layerX || e.layerX == 0) {
                    _mouse.x = e.layerX - _canvas.offsetLeft;
                    _mouse.y = e.layerY - _canvas.offsetTop;
                }
                else if (e.offsetX || e.offsetX == 0) {
                    _mouse.x = e.offsetX - _canvas.offsetLeft;
                    _mouse.y = e.offsetY - _canvas.offsetTop;
                }
                _currentPiece = playField.checkPieceClicked();

                if (_currentPiece != null) {
                    _stage.clearRect(_currentPiece.currentX, _currentPiece.currentY, _pieceWidth, _pieceHeight);
                    _stage.save();
                    _stage.globalAlpha = 0.9;
                    _stage.drawImage(_img, _currentPiece.startX, _currentPiece.startY, _pieceWidth, _pieceHeight, _mouse.x - (_pieceWidth / 2), _mouse.y - (_pieceHeight / 2), _pieceWidth, _pieceHeight);
                    _stage.restore();
                    _canvas.onmousemove = playField.updatePuzzle;
                    _canvas.onmouseup = playField.pieceDropped;
                }

            }
        });

        Object.defineProperty(playfield, 'checkPieceClicked', {
            value: function () {
                var i,
                    len,
                    piece;

                for (i = 0, len = _pieces.length; i < len; i += 1) {
                    piece = _pieces[i];
                    if (_mouse.x < piece.currentX || _mouse.x > (piece.currentX + _pieceWidth) ||
                        _mouse.y < piece.currentY || _mouse.y > (piece.currentY + _pieceHeight)) {
                        //PIECE NOT HIT
                    }
                    else {
                        return piece;
                    }
                }
                return null;
            }
        });

        Object.defineProperty(playfield, 'updatePuzzle', {
            value: function (e) {
                var i,
                    len,
                    piece;
                _currentDropPiece = null;

                if (e.layerX || e.layerX == 0) {
                    _mouse.x = e.layerX - _canvas.offsetLeft;
                    _mouse.y = e.layerY - _canvas.offsetTop;
                } else if (e.offsetX || e.offsetX == 0) {
                    _mouse.x = e.offsetX - _canvas.offsetLeft;
                    _mouse.y = e.offsetY - _canvas.offsetTop;
                }
                _stage.clearRect(0, 0, _puzzleWidth, _puzzleHeight);

                for (i = 0, len = _pieces.length; i < len; i += 1) {
                    piece = _pieces[i];
                    if (piece == _currentPiece) {
                        continue;
                    }

                    _stage.drawImage(_img, piece.startX, piece.startY, _pieceWidth, _pieceHeight, piece.currentX, piece.currentY, _pieceWidth, _pieceHeight);
                    _stage.strokeRect(piece.currentX, piece.currentY, _pieceWidth, _pieceHeight);

                    if (_currentDropPiece == null) {
                        if (_mouse.x < piece.currentX || _mouse.x > (piece.currentX + _pieceWidth) ||
                            _mouse.y < piece.currentY || _mouse.y > (piece.currentY + _pieceHeight)) {
                            //NOT OVER
                        }
                        else {
                            _currentDropPiece = piece;
                            _stage.save();
                            _stage.globalAlpha = 0.4;
                            _stage.fillStyle = PUZZLE_HOVER_TINT;
                            _stage.fillRect(_currentDropPiece.currentX,
                                _currentDropPiece.currentY,
                                _pieceWidth, _pieceHeight);
                            _stage.restore();
                        }
                    }
                }

                _stage.save();
                _stage.globalAlpha = 0.6;
                _stage.drawImage(_img, _currentPiece.startX, _currentPiece.startY, _pieceWidth, _pieceHeight,
                    _mouse.x - (_pieceWidth / 2), _mouse.y - (_pieceHeight / 2), _pieceWidth, _pieceHeight);
                _stage.restore();
                _stage.strokeRect(_mouse.x - (_pieceWidth / 2), _mouse.y - (_pieceHeight / 2), _pieceWidth, _pieceHeight);
            }
        });

        Object.defineProperty(playfield, 'pieceDropped', {
            value: function (e) {
                var tmp;

                _canvas.onmousemove = null;
                _canvas.onmouseup = null;
                if (_currentDropPiece != null) {
                    tmp = {xPos: _currentPiece.currentX, yPos: _currentPiece.currentY};
                    _currentPiece.currentX = _currentDropPiece.currentX;
                    _currentPiece.currentY = _currentDropPiece.currentY;
                    _currentDropPiece.currentX = tmp.xPos;
                    _currentDropPiece.currentY = tmp.yPos;
                }
                playField.resetPuzzleAndCheckWin();
            }
        });

        Object.defineProperty(playfield, 'resetPuzzleAndCheckWin', {
            value: function () {
                var i,
                    len,
                    piece,
                    gameWin = true;

                _stage.clearRect(0, 0, _puzzleWidth, _puzzleHeight);

                for (i = 0, len = _pieces.length; i < len; i += 1) {
                    piece = _pieces[i];
                    _stage.drawImage(_img, piece.startX, piece.startY, _pieceWidth, _pieceHeight, piece.currentX, piece.currentY, _pieceWidth, _pieceHeight);
                    _stage.strokeRect(piece.currentX, piece.currentY, _pieceWidth, _pieceHeight);
                    if (piece.currentX != piece.startX || piece.currentY != piece.startY) {
                        gameWin = false;
                    }
                }
                if (gameWin) {
                    setTimeout(playField.gameOver, 500);
                    timer.stopTimer();
                }
            }
        });

        Object.defineProperty(playfield, 'gameOver', {
            value: function () {
                _canvas.onmousedown = null;
                _canvas.onmousemove = null;
                _canvas.onmouseup = null;
                timerr.stopTimer();

                playField.initPuzzle();
            }
        });

        Object.defineProperty(playfield, 'shuffleArray', {
            value: function (o) {
                var j,
                    x,
                    i;

                for (j, x, i = o.length - 1; i > 0; i -= 1) {
                    j = parseInt(Math.random() * i);
                    x = o[i];
                    o[i] = o[j];
                    o[j] = x;
                }
                return o;
            }
        });

         timerr = (function () {
            var clsStopwatch = function () {
                var startAt = 0,
                    lapTime = 0;

                var now = function () {
                    return (new Date()).getTime();
                };

                this.start = function () {
                    startAt = startAt ? startAt : now();
                };

                this.stop = function () {
                    lapTime = startAt ? lapTime + now() - startAt : lapTime;
                    startAt = 0;
                };

                this.reset = function () {
                    lapTime = startAt = 0;
                };

                this.time = function () {
                    return lapTime + (startAt ? now() - startAt : 0);
                };
            };

            var playTime = new clsStopwatch(),
                timer,
                clocktimer;

            function pad(num, size) {
                var s = "0000" + num;
                return s.substr(s.length - size);
            }

            function formatTime(time) {
                var hours = 0,
                    minutes = 0,
                    seconds = 0,
                    newTime = '';

                hours = Math.floor(time / (60 * 60 * 1000));
                time = time % (60 * 60 * 1000);
                minutes = Math.floor(time / (60 * 1000));
                time = time % (60 * 1000);
                seconds = Math.floor(time / 1000);

                newTime = pad(hours, 2) + ':' + pad(minutes, 2) + ':' + pad(seconds, 2);
                return newTime;
            }

            var tmr = {
               showTimer:function() {
                timer = document.getElementById('timer');
                tmr.updateTimer();
            },

             updateTimer:function() {
                timer.innerHTML = formatTime(playTime.time());
            },

           startTimer: function () {
                clocktimer = setInterval("timerr.updateTimer()", 1000);
                playTime.start();
            },

            stopTimer:function () {
                playTime.stop();
                clearInterval(clocktimer);
            },

            resetTimer:function () {
                tmr.stopTimer();
                playTime.reset();
                tmr.updateTimer();
            }
        };

            return tmr;
        }());

        return playfield;
    }());

    return playField;
}());

function createPlayField(imageSrc, difficulty) {
    var plr = Object.create(playField).init(imageSrc, difficulty);
}

function resizeImage(img, maxWidth, maxHeight) {
    // Create off-screen canvas for resizing purposes
    var canvas = document.createElement('canvas'),
        ctx = canvas.getContext('2d'),
        width = img.width,
        height = img.height,
        resizedImage;

    // Scale image
    if (width > height) {
        if (width > maxWidth) {
            height *= maxWidth / width;
            width = maxWidth;
        }
    } else {
        if (height > maxHeight) {
            width *= maxHeight / height;
            height = maxHeight;
        }
    }

    // Set dimensions to target size
    canvas.width = width;
    canvas.height = height;

    // Draw source image into the off-screen canvas:
    ctx.drawImage(img, 0, 0, width, height);

    // Encode image to Base64
    resizedImage = canvas.toDataURL("image/png");
    return resizedImage;
}<|endoftext|>


<commit_before>import deserializeUserConProfile from './deserializeUserConProfile';
import Form from '../Models/Form';
import { deserializeForm } from '../FormPresenter/GraphQLFormDeserialization';

const buildStateFromData = (userConProfileData, conventionData) => {
  const {
    user_con_profile_form: userConProfileForm,
    ...conventionProps
  } = conventionData;

  return {
    userConProfile: deserializeUserConProfile(userConProfileData),
    convention: conventionProps,
    form: deserializeForm(userConProfileForm),
  };
};

export default buildStateFromData;
<commit_msg>Remove unused import<commit_after>import deserializeUserConProfile from './deserializeUserConProfile';
import { deserializeForm } from '../FormPresenter/GraphQLFormDeserialization';

const buildStateFromData = (userConProfileData, conventionData) => {
  const {
    user_con_profile_form: userConProfileForm,
    ...conventionProps
  } = conventionData;

  return {
    userConProfile: deserializeUserConProfile(userConProfileData),
    convention: conventionProps,
    form: deserializeForm(userConProfileForm),
  };
};

export default buildStateFromData;
<|endoftext|>


<commit_before>const REALMS = {
  "eu": ["Aegwynn",  "Aerie Peak",  "Agamaggan",  "Aggra (Português)",  "Aggramar",  "Ahn'Qiraj",  "Al'Akir",  "Alexstrasza",  "Alleria",
         "Alonsus",  "Aman'Thul",  "Ambossar",  "Anachronos",  "Anetheron",  "Antonidas",  "Anub'arak",  "Arak-arahm",  "Arathi",
         "Arathor",  "Archimonde",  "Area 52",  "Argent Dawn",  "Arthas",  "Arygos",  "Ashenvale",  "Aszune",  "Auchindoun",
         "Azjol-Nerub",  "Azshara",  "Azuregos",  "Azuremyst",  "Baelgun",  "Balnazzar",  "Benedictus",  "Beta Leveling Realm 01",
         "Beta Leveling Realm 03",  "Beta Max Level PvP",  "Blackhand",  "Blackmoore",  "Blackrock",  "Blackscar", "Bladefist",
         "Blade's Edge",  "Bloodfeather",  "Bloodhoof",  "Bloodscalp",  "Blutkessel",  "Booty Bay",  "Borean Tundra",
         "Boulderfist",  "Brill",  "Bronze Dragonflight",  "Bronzebeard",   "Burning Blade",  "Burning Legion", "Burning Steppes",
         "Chamber of Aspects",  "Chants éternels",  "Cho'gall",  "Chromaggus",  "Colinas Pardas",  "Confréri du Thorium",
         "Conseil des Ombres",  "Crushridge",  "C'Thun",  "Culte de la Rive noire",  "Daggerspine",  "Dalaran", "Dalvengyr",
         "Darkmoon Faire",  "Darksorrow",  "Darkspear",  "Das Konsortium",  "Das Syndikat",  "Deathguard", "Deathweaver",
         "Deathwing",  "Deepholm",  "Defias Brotherhood",  "Dentarg",  "Der abyssische Rat",  "Der Mithrilorden",
         "Der Rat von Dalaran",  "Destromath",  "Dethecus",  "Die Aldor",  "Die Arguswacht",  "Die ewige Wacht",  "Die Nachtwache",
         "Die Silberne Hand",  "Die Todeskrallen",  "Doomhammer",  "Draenor",  "Dragonblight",  "Dragonmaw", "Drak'thul",
         "Drek'Thar",  "Dun Modr",  "Dun Morogh",  "Dunemaul",  "Durotan",  "Earthen Ring",  "Echsenkessel", "Eitrigg",
         "Eldre'Thalas",  "Elune",  "Emerald Dream",  "Emeriss",  "Eonar",  "Eredar",  "Eversong",  "Executus", "Exodar",
         "Festung der Stürme",  "Fordragon",  "Forscherliga",  "Frostmane",  "Frostmourne",  "Frostwhisper", "Frostwolf",
         "Galakrond",  "Garona",  "Garrosh",  "Genjuros",  "Ghostlands",  "Gilneas",  "Goldrinn",  "Gordunni", "Gorgonnash",
         "Greymane",  "Grim Batol",  "Grom",  "Gul'dan",  "Hakkar",  "Haomarush",  "Hellfire",  "Hellscream", "Howling Fjord",
         "Hyjal",  "Illidan",  "Jaedenar",  "Kael'thas",  "Kalaran",  "Karazhan",  "Kargath",  "Kazzak", "Kel'Thuzad",
         "Khadgar",  "Khaz Modan",  "Khaz'goroth",  "Kil'jaeden",  "Kilrogg",  "Kirin Tor",  "Kor'gall", "Krag'jin",
         "Krasus",  "Kul Tiras",  "Kult der Verdammten",  "La Croisade écarlate",  "Laughing Skull",  "Les Clairvoyants",
         "Les Sentinelles",  "Lich King",  "Lightbringer",  "Lightning's Blade",  "Lordaeron",  "Los Errantes", "Lothar",
         "Lycanthoth",  "Madmortem",  "Magtheridon",  "Malfurion",  "Mal'Ganis",  "Malorne",  "Malygos",  "Mannoroth",
         "Marécage de Zangar",  "Mazrigos",  "Medivh",  "Minahonda",  "Moonglade",  "Mug'thol",  "Nagrand",  "Naralex",
         "Nathrezim",  "Naxxramas",  "Nazjatar",  "Nefarian",  "Nemesis",  "Neptulon",  "Nera'thor",  "Ner'zhul",  "Nethersturm",
         "Nordrassil",  "Norgannon",  "Nozdormu",  "Onyxia",  "Outland",  "Perenolde",  "Pozzo dell'Eternità",  "Proudmoore",
         "Quel'Thalas",  "Ragnaros",  "Rajaxx",  "Rashgarroth",  "Ravencrest",  "Ravenholdt",  "Razuvious",  "Rexxar",
         "Runetotem",  "Sanguino",  "Sargeras",  "Saurfang",  "Scarshield Legion",  "Sen'jin",  "Shadowsong",  "Shattered Halls",
         "Shattered Hand",  "Shattrath",  "Shen'dralar",  "Silvermoon",  "Sinstralis",  "Skullcrusher",  "Soulflayer",
         "Spinebreaker",  "Sporeggar",  "Steamwheedle Cartel",  "Stormrage",  "Stormreaver",  "Stormscale",  "Sunstrider",
         "Suramar",  "Sylvanas",  "Taerar",  "Talnivarr",  "Tarren Mill",  "Teldrassil",  "Temple noir",  "Terenas",  "Terokkar",
         "Terrordar",  "The Maelstrom",  "The Sha'tar",  "The Venture Co",  "Theradras",  "Thermaplugg",  "Thrall",
         "Throk'Feroth",  "Thunderhorn",  "Tichondrius",  "Tirion",  "Todeswache",  "Trollbane",  "Turalyon",  "Twilight's Hammer",
         "Twisting Nether",  "Tyrande",  "Uldaman",  "Ulduar",  "Uldum",  "Un'Goro",  "Varimathras",  "Vashj", "Vek'lor",
         "Vek'nilash",  "Vol'jin",  "Wildhammer",  "Wrathbringer",  "Xavius",  "Ysera",  "Ysondre",  "Zenedar",
         "Zirkel des Cenarius",  "Zul'jin",  "Zuluhed"],
  "us": ["Aegwynn", "Aerie Peak", "Agamaggan", "Aggramar", "Akama", "Alexstrasza", "Alleria", "Altar of Storms", "Alterac Mountains",
         "Aman'Thul", "Anasterian", "Andorhal", "Anetheron", "Antonidas", "Anub'arak", "Anvilmar", "Arathor", "Archimonde", "Area 52",
         "Argent Dawn", "Arthas", "Arygos", "Auchindoun", "Azgalor", "Azjol-Nerub", "Azralon", "Azshara", "Azuremyst", "Baelgun",
         "Balnazzar", "Barthilas", "Benedictus", "Beta Leveling Realm 01", "Beta Leveling Realm 03",  "Beta Max Level PvP",
         "Black Dragonflight", "Blackhand", "Blackrock", "Blackwater Raiders", "Blackwing Lair", "Bladefist", "Blade's Edge",
         "Bleeding Hollow",  "Blood Furnace", "Bloodhoof", "Bloodscalp", "Bonechewer", "Borean Tundra", "Boulderfist",
         "Bronzebeard", "Broxigar",  "Burning Blade", "Burning Legion", "Caelestrasz", "Cairne", "Cenarion Circle", "Cenarius",
         "Cho'gall", "Chromaggus", "Coilfang", "Crushridge", "Daggerspine", "Dalaran", "Dalvengyr", "Dark Iron", "Darkspear",
         "Darrowmere", "Dath'Remar", "Dawnbringer", "Deathwing", "Demon Soul", "Dentarg", "Destromath", "Dethecus", "Detheroc",
         "Doomhammer", "Draenor", "Dragonblight", "Dragonmaw", "Draka", "Drakkari", "Drak'Tharon", "Drak'thul", "Dreadmaul",
         "Drenden", "Dunemaul", "Durotan", "Duskwood", "Earthen Ring", "Echo Isles", "Eitrigg", "Eldre'Thalas", "Elune",
         "Emerald Dream", "Eonar", "Eredar", "Executus", "Exodar", "Farstriders", "Feathermoon", "Fenris", "Firetree",
         "Fizzcrank", "Frostmane", "Frostmourne", "Frostwolf", "Galakrond", "Gallywix", "Garithos", "Garona", "Garrosh",
         "Ghostlands", "Gilneas", "Gnomeregan", "Goldrinn", "Gorefiend", "Gorgonnash", "Greymane", "Grizzly Hills", "Gul'dan",
         "Gundrak", "Gurubashi", "Hakkar", "Haomarush", "Hellscream", "Hydraxis", "Hyjal", "Icecrown", "Illidan", "Jaedenar",
         "Jubei'Thos", "Kael'thas", "Kalaran", "Kalecgos", "Kargath", "Kel'Thuzad", "Khadgar", "Khaz Modan", "Khaz'goroth",
         "Kil'jaeden", "Kilrogg", "Kirin Tor", "Korgath", "Korialstrasz", "Kul Tiras", "Laughing Skull", "Lethon", "Lightbringer",
         "Lightninghoof", "Lightning's Blade", "Llane", "Lothar", "Lycanthoth", "Madoran", "Maelstrom", "Magtheridon", "Maiev",
         "Malfurion", "Mal'Ganis", "Malorne", "Malygos", "Mannoroth", "Medivh", "Misha", "Mok'Nathal", "Moon Guard", "Moonrunner",
         "Mug'thol", "Muradin", "Nagrand", "Nathrezim", "Nazgrel", "Nazjatar", "Nemesis", "Ner'zhul", "Nesingwary",
         "Nordrassil", "Norgannon", "Onyxia", "Perenolde", "Proudmoore", "Quel'dorei", "Quel'Thalas", "Ragnaros", "Ravencrest",
         "Ravenholdt", "Rexxar", "Rivendare", "Runetotem", "Sargeras", "Saurfang", "Scarlet Crusade", "Scilla", "Sen'jin", "Sentinels",
         "Shadow Council", "Shadowmoon", "Shadowsong", "Shandris", "Shattered Halls", "Shattered Hand", "Shu'halo", "Silver Hand",
         "Silvermoon", "Sisters of Elune", "Skullcrusher", "Skywall", "Smolderthorn", "Spinebreaker", "Spirestone", "Staghelm",
         "Steamwheedle Cartel", "Stonemaul", "Stormrage", "Stormreaver", "Stormscale", "Suramar", "Tanaris", "Terenas", "Terokkar",
         "Thaurissan", "The Forgotten Coast", "The Scryers", "The Underbog", "The Venture Co", "Thorium Brotherhood", "Thrall",
         "Thunderhorn", "Thunderlord", "Tichondrius", "Tol Barad", "Tortheldrin", "Trollbane", "Turalyon", "Twisting Nether",
         "Uldaman", "Uldum", "Undermine", "Ursin", "Uther", "Vashj", "Vek'nilash", "Velen", "Warsong", "Whisperwind",
         "Wildhammer", "Windrunner", "Winterhoof", "Wyrmrest Accord", "Ysera", "Ysondre", "Zangarmarsh", "Zul'jin", "Zuluhed"]
};
<commit_msg>added korean realms<commit_after>const REALMS = {
  "eu": ["Aegwynn",  "Aerie Peak",  "Agamaggan",  "Aggra (Português)",  "Aggramar",  "Ahn'Qiraj",  "Al'Akir",  "Alexstrasza",  "Alleria",
         "Alonsus",  "Aman'Thul",  "Ambossar",  "Anachronos",  "Anetheron",  "Antonidas",  "Anub'arak",  "Arak-arahm",  "Arathi",
         "Arathor",  "Archimonde",  "Area 52",  "Argent Dawn",  "Arthas",  "Arygos",  "Ashenvale",  "Aszune",  "Auchindoun",
         "Azjol-Nerub",  "Azshara",  "Azuregos",  "Azuremyst",  "Baelgun",  "Balnazzar",  "Benedictus",  "Beta Leveling Realm 01",
         "Beta Leveling Realm 03",  "Beta Max Level PvP",  "Blackhand",  "Blackmoore",  "Blackrock",  "Blackscar", "Bladefist",
         "Blade's Edge",  "Bloodfeather",  "Bloodhoof",  "Bloodscalp",  "Blutkessel",  "Booty Bay",  "Borean Tundra",
         "Boulderfist",  "Brill",  "Bronze Dragonflight",  "Bronzebeard",   "Burning Blade",  "Burning Legion", "Burning Steppes",
         "Chamber of Aspects",  "Chants éternels",  "Cho'gall",  "Chromaggus",  "Colinas Pardas",  "Confréri du Thorium",
         "Conseil des Ombres",  "Crushridge",  "C'Thun",  "Culte de la Rive noire",  "Daggerspine",  "Dalaran", "Dalvengyr",
         "Darkmoon Faire",  "Darksorrow",  "Darkspear",  "Das Konsortium",  "Das Syndikat",  "Deathguard", "Deathweaver",
         "Deathwing",  "Deepholm",  "Defias Brotherhood",  "Dentarg",  "Der abyssische Rat",  "Der Mithrilorden",
         "Der Rat von Dalaran",  "Destromath",  "Dethecus",  "Die Aldor",  "Die Arguswacht",  "Die ewige Wacht",  "Die Nachtwache",
         "Die Silberne Hand",  "Die Todeskrallen",  "Doomhammer",  "Draenor",  "Dragonblight",  "Dragonmaw", "Drak'thul",
         "Drek'Thar",  "Dun Modr",  "Dun Morogh",  "Dunemaul",  "Durotan",  "Earthen Ring",  "Echsenkessel", "Eitrigg",
         "Eldre'Thalas",  "Elune",  "Emerald Dream",  "Emeriss",  "Eonar",  "Eredar",  "Eversong",  "Executus", "Exodar",
         "Festung der Stürme",  "Fordragon",  "Forscherliga",  "Frostmane",  "Frostmourne",  "Frostwhisper", "Frostwolf",
         "Galakrond",  "Garona",  "Garrosh",  "Genjuros",  "Ghostlands",  "Gilneas",  "Goldrinn",  "Gordunni", "Gorgonnash",
         "Greymane",  "Grim Batol",  "Grom",  "Gul'dan",  "Hakkar",  "Haomarush",  "Hellfire",  "Hellscream", "Howling Fjord",
         "Hyjal",  "Illidan",  "Jaedenar",  "Kael'thas",  "Kalaran",  "Karazhan",  "Kargath",  "Kazzak", "Kel'Thuzad",
         "Khadgar",  "Khaz Modan",  "Khaz'goroth",  "Kil'jaeden",  "Kilrogg",  "Kirin Tor",  "Kor'gall", "Krag'jin",
         "Krasus",  "Kul Tiras",  "Kult der Verdammten",  "La Croisade écarlate",  "Laughing Skull",  "Les Clairvoyants",
         "Les Sentinelles",  "Lich King",  "Lightbringer",  "Lightning's Blade",  "Lordaeron",  "Los Errantes", "Lothar",
         "Lycanthoth",  "Madmortem",  "Magtheridon",  "Malfurion",  "Mal'Ganis",  "Malorne",  "Malygos",  "Mannoroth",
         "Marécage de Zangar",  "Mazrigos",  "Medivh",  "Minahonda",  "Moonglade",  "Mug'thol",  "Nagrand",  "Naralex",
         "Nathrezim",  "Naxxramas",  "Nazjatar",  "Nefarian",  "Nemesis",  "Neptulon",  "Nera'thor",  "Ner'zhul",  "Nethersturm",
         "Nordrassil",  "Norgannon",  "Nozdormu",  "Onyxia",  "Outland",  "Perenolde",  "Pozzo dell'Eternità",  "Proudmoore",
         "Quel'Thalas",  "Ragnaros",  "Rajaxx",  "Rashgarroth",  "Ravencrest",  "Ravenholdt",  "Razuvious",  "Rexxar",
         "Runetotem",  "Sanguino",  "Sargeras",  "Saurfang",  "Scarshield Legion",  "Sen'jin",  "Shadowsong",  "Shattered Halls",
         "Shattered Hand",  "Shattrath",  "Shen'dralar",  "Silvermoon",  "Sinstralis",  "Skullcrusher",  "Soulflayer",
         "Spinebreaker",  "Sporeggar",  "Steamwheedle Cartel",  "Stormrage",  "Stormreaver",  "Stormscale",  "Sunstrider",
         "Suramar",  "Sylvanas",  "Taerar",  "Talnivarr",  "Tarren Mill",  "Teldrassil",  "Temple noir",  "Terenas",  "Terokkar",
         "Terrordar",  "The Maelstrom",  "The Sha'tar",  "The Venture Co",  "Theradras",  "Thermaplugg",  "Thrall",
         "Throk'Feroth",  "Thunderhorn",  "Tichondrius",  "Tirion",  "Todeswache",  "Trollbane",  "Turalyon",  "Twilight's Hammer",
         "Twisting Nether",  "Tyrande",  "Uldaman",  "Ulduar",  "Uldum",  "Un'Goro",  "Varimathras",  "Vashj", "Vek'lor",
         "Vek'nilash",  "Vol'jin",  "Wildhammer",  "Wrathbringer",  "Xavius",  "Ysera",  "Ysondre",  "Zenedar",
         "Zirkel des Cenarius",  "Zul'jin",  "Zuluhed"],
  "us": ["Aegwynn", "Aerie Peak", "Agamaggan", "Aggramar", "Akama", "Alexstrasza", "Alleria", "Altar of Storms", "Alterac Mountains",
         "Aman'Thul", "Anasterian", "Andorhal", "Anetheron", "Antonidas", "Anub'arak", "Anvilmar", "Arathor", "Archimonde", "Area 52",
         "Argent Dawn", "Arthas", "Arygos", "Auchindoun", "Azgalor", "Azjol-Nerub", "Azralon", "Azshara", "Azuremyst", "Baelgun",
         "Balnazzar", "Barthilas", "Benedictus", "Beta Leveling Realm 01", "Beta Leveling Realm 03",  "Beta Max Level PvP",
         "Black Dragonflight", "Blackhand", "Blackrock", "Blackwater Raiders", "Blackwing Lair", "Bladefist", "Blade's Edge",
         "Bleeding Hollow",  "Blood Furnace", "Bloodhoof", "Bloodscalp", "Bonechewer", "Borean Tundra", "Boulderfist",
         "Bronzebeard", "Broxigar",  "Burning Blade", "Burning Legion", "Caelestrasz", "Cairne", "Cenarion Circle", "Cenarius",
         "Cho'gall", "Chromaggus", "Coilfang", "Crushridge", "Daggerspine", "Dalaran", "Dalvengyr", "Dark Iron", "Darkspear",
         "Darrowmere", "Dath'Remar", "Dawnbringer", "Deathwing", "Demon Soul", "Dentarg", "Destromath", "Dethecus", "Detheroc",
         "Doomhammer", "Draenor", "Dragonblight", "Dragonmaw", "Draka", "Drakkari", "Drak'Tharon", "Drak'thul", "Dreadmaul",
         "Drenden", "Dunemaul", "Durotan", "Duskwood", "Earthen Ring", "Echo Isles", "Eitrigg", "Eldre'Thalas", "Elune",
         "Emerald Dream", "Eonar", "Eredar", "Executus", "Exodar", "Farstriders", "Feathermoon", "Fenris", "Firetree",
         "Fizzcrank", "Frostmane", "Frostmourne", "Frostwolf", "Galakrond", "Gallywix", "Garithos", "Garona", "Garrosh",
         "Ghostlands", "Gilneas", "Gnomeregan", "Goldrinn", "Gorefiend", "Gorgonnash", "Greymane", "Grizzly Hills", "Gul'dan",
         "Gundrak", "Gurubashi", "Hakkar", "Haomarush", "Hellscream", "Hydraxis", "Hyjal", "Icecrown", "Illidan", "Jaedenar",
         "Jubei'Thos", "Kael'thas", "Kalaran", "Kalecgos", "Kargath", "Kel'Thuzad", "Khadgar", "Khaz Modan", "Khaz'goroth",
         "Kil'jaeden", "Kilrogg", "Kirin Tor", "Korgath", "Korialstrasz", "Kul Tiras", "Laughing Skull", "Lethon", "Lightbringer",
         "Lightninghoof", "Lightning's Blade", "Llane", "Lothar", "Lycanthoth", "Madoran", "Maelstrom", "Magtheridon", "Maiev",
         "Malfurion", "Mal'Ganis", "Malorne", "Malygos", "Mannoroth", "Medivh", "Misha", "Mok'Nathal", "Moon Guard", "Moonrunner",
         "Mug'thol", "Muradin", "Nagrand", "Nathrezim", "Nazgrel", "Nazjatar", "Nemesis", "Ner'zhul", "Nesingwary",
         "Nordrassil", "Norgannon", "Onyxia", "Perenolde", "Proudmoore", "Quel'dorei", "Quel'Thalas", "Ragnaros", "Ravencrest",
         "Ravenholdt", "Rexxar", "Rivendare", "Runetotem", "Sargeras", "Saurfang", "Scarlet Crusade", "Scilla", "Sen'jin", "Sentinels",
         "Shadow Council", "Shadowmoon", "Shadowsong", "Shandris", "Shattered Halls", "Shattered Hand", "Shu'halo", "Silver Hand",
         "Silvermoon", "Sisters of Elune", "Skullcrusher", "Skywall", "Smolderthorn", "Spinebreaker", "Spirestone", "Staghelm",
         "Steamwheedle Cartel", "Stonemaul", "Stormrage", "Stormreaver", "Stormscale", "Suramar", "Tanaris", "Terenas", "Terokkar",
         "Thaurissan", "The Forgotten Coast", "The Scryers", "The Underbog", "The Venture Co", "Thorium Brotherhood", "Thrall",
         "Thunderhorn", "Thunderlord", "Tichondrius", "Tol Barad", "Tortheldrin", "Trollbane", "Turalyon", "Twisting Nether",
         "Uldaman", "Uldum", "Undermine", "Ursin", "Uther", "Vashj", "Vek'nilash", "Velen", "Warsong", "Whisperwind",
         "Wildhammer", "Windrunner", "Winterhoof", "Wyrmrest Accord", "Ysera", "Ysondre", "Zangarmarsh", "Zul'jin", "Zuluhed"],
   "kr": ["렉사르", "불타는 군단", "와일드해머", "가로나", "달라란", "데스윙", "라그나로스", "말퓨리온", "세나리우스", "알렉스트라자", "카르가스",
          "하이잘", "헬스크림", "스톰레이지", "윈드러너", "굴단 (Gul'dan)", "노르간논", "듀로탄", "아즈샤라",  "에이그윈",  "엘룬", "이오나",
          "줄진"]
};
<|endoftext|>