Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"message_popover.min.js","sources":["../src/message_popover.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Controls the message popover in the nav bar.\n *\n * @module     core_message/message_popover\n * @copyright  2018 Ryan Wyllie <ryan@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n[\n    'jquery',\n    'core/custom_interaction_events',\n    'core/pubsub',\n    'core_message/message_drawer_events'\n],\nfunction(\n    $,\n    CustomEvents,\n    PubSub,\n    MessageDrawerEvents\n) {\n    var SELECTORS = {\n        COUNT_CONTAINER: '[data-region=\"count-container\"]'\n    };\n\n    /**\n     * Toggle the message drawer visibility.\n     *\n     * @param {String} buttonid The button id for the popover.\n     */\n    var toggleMessageDrawerVisibility = function(buttonid) {\n        PubSub.publish(MessageDrawerEvents.TOGGLE_VISIBILITY, buttonid);\n    };\n\n    /**\n     * Decrement the unread conversation count in the nav bar if a conversation\n     * is read. When there are no unread conversations then hide the counter.\n     *\n     * @param {Object} button The button element for the popover.\n     * @return {Function}\n     */\n    var handleDecrementConversationCount = function(button) {\n        return function() {\n            var countContainer = button.find(SELECTORS.COUNT_CONTAINER);\n            var count = parseInt(countContainer.text(), 10);\n\n            if (isNaN(count)) {\n                countContainer.addClass('hidden');\n            } else if (!count || count < 2) {\n                countContainer.addClass('hidden');\n            } else {\n                count = count - 1;\n                countContainer.text(count);\n            }\n        };\n    };\n\n    /**\n     * Add events listeners for when the popover icon is clicked and when conversations\n     * are read.\n     *\n     * @param {Object} button The button element for the popover.\n     */\n    var registerEventListeners = function(button) {\n        CustomEvents.define(button, [CustomEvents.events.activate]);\n\n        button.on(CustomEvents.events.activate, function(e, data) {\n            toggleMessageDrawerVisibility(button.attr('id'));\n            button.focus();\n            data.originalEvent.preventDefault();\n        });\n\n        PubSub.subscribe(MessageDrawerEvents.CONVERSATION_READ, handleDecrementConversationCount(button));\n        PubSub.subscribe(MessageDrawerEvents.CONTACT_REQUEST_ACCEPTED, handleDecrementConversationCount(button));\n        PubSub.subscribe(MessageDrawerEvents.CONTACT_REQUEST_DECLINED, handleDecrementConversationCount(button));\n    };\n\n    /**\n     * Initialise the message popover.\n     *\n     * @param {Object} button The button element for the popover.\n     */\n    var init = function(button) {\n        button = $(button);\n        registerEventListeners(button);\n    };\n\n    return {\n        init: init,\n    };\n});\n"],"names":["define","$","CustomEvents","PubSub","MessageDrawerEvents","SELECTORS","handleDecrementConversationCount","button","countContainer","find","count","parseInt","text","isNaN","addClass","registerEventListeners","events","activate","on","e","data","buttonid","attr","publish","TOGGLE_VISIBILITY","focus","originalEvent","preventDefault","subscribe","CONVERSATION_READ","CONTACT_REQUEST_ACCEPTED","CONTACT_REQUEST_DECLINED","init"],"mappings":";;;;;;;AAsBAA,sCACA,CACI,SACA,iCACA,cACA,uCAEJ,SACIC,EACAC,aACAC,OACAC,yBAEIC,0BACiB,kCAmBjBC,iCAAmC,SAASC,eACrC,eACCC,eAAiBD,OAAOE,KAAKJ,2BAC7BK,MAAQC,SAASH,eAAeI,OAAQ,IAExCC,MAAMH,SAEEA,OAASA,MAAQ,EADzBF,eAAeM,SAAS,WAIxBJ,OAAgB,EAChBF,eAAeI,KAAKF,UAW5BK,uBAAyB,SAASR,QAClCL,aAAaF,OAAOO,OAAQ,CAACL,aAAac,OAAOC,WAEjDV,OAAOW,GAAGhB,aAAac,OAAOC,UAAU,SAASE,EAAGC,MApCpB,IAASC,SAAAA,SAqCPd,OAAOe,KAAK,MApC9CnB,OAAOoB,QAAQnB,oBAAoBoB,kBAAmBH,UAqClDd,OAAOkB,QACPL,KAAKM,cAAcC,oBAGvBxB,OAAOyB,UAAUxB,oBAAoByB,kBAAmBvB,iCAAiCC,SACzFJ,OAAOyB,UAAUxB,oBAAoB0B,yBAA0BxB,iCAAiCC,SAChGJ,OAAOyB,UAAUxB,oBAAoB2B,yBAA0BzB,iCAAiCC,gBAa7F,CACHyB,KANO,SAASzB,QAChBA,OAASN,EAAEM,QACXQ,uBAAuBR"}