moodle/lib/amd/build/auto_rows.min.js.map
2023-03-09 09:53:19 +08:00

1 line
4.6 KiB
Plaintext

{"version":3,"file":"auto_rows.min.js","sources":["../src/auto_rows.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 * Enhance a textarea with auto growing rows to fit the content.\n *\n * @module core/auto_rows\n * @copyright 2016 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.2\n */\ndefine(['jquery'], function($) {\n var SELECTORS = {\n ELEMENT: '[data-auto-rows]'\n };\n\n var EVENTS = {\n ROW_CHANGE: 'autorows:rowchange',\n };\n\n /**\n * Determine how many rows should be set for the given element.\n *\n * @method calculateRows\n * @param {jQuery} element The textarea element\n * @return {int} The number of rows for the element\n * @private\n */\n var calculateRows = function(element) {\n var currentRows = element.attr('rows');\n var minRows = element.data('min-rows');\n var maxRows = element.attr('data-max-rows');\n\n var height = element.height();\n var innerHeight = element.innerHeight();\n var padding = innerHeight - height;\n\n var scrollHeight = element[0].scrollHeight;\n var rows = (scrollHeight - padding) / (height / currentRows);\n\n // Remove the height styling to let the height be calculated automatically\n // based on the row attribute.\n element.css('height', '');\n\n if (rows < minRows) {\n return minRows;\n } else if (maxRows && rows >= maxRows) {\n return maxRows;\n } else {\n return rows;\n }\n };\n\n /**\n * Listener for change events to trigger resizing of the element.\n *\n * @method changeListener\n * @param {Event} e The triggered event.\n * @private\n */\n var changeListener = function(e) {\n var element = $(e.target);\n var minRows = element.data('min-rows');\n var currentRows = element.attr('rows');\n\n if (typeof minRows === \"undefined\") {\n element.data('min-rows', currentRows);\n }\n\n // Reset element to single row so that the scroll height of the\n // element is correctly calculated each time.\n element.attr('rows', 1);\n var rows = calculateRows(element);\n element.attr('rows', rows);\n\n if (rows != currentRows) {\n element.trigger(EVENTS.ROW_CHANGE);\n }\n };\n\n /**\n * Add the event listeners for all text areas within the given element.\n *\n * @method init\n * @param {jQuery|selector} root The container element of all enhanced text areas\n * @public\n */\n var init = function(root) {\n if ($(root).data('auto-rows')) {\n $(root).on('input propertychange', changeListener.bind(this));\n } else {\n $(root).on('input propertychange', SELECTORS.ELEMENT, changeListener.bind(this));\n }\n };\n\n return /** @module core/auto_rows */ {\n init: init,\n events: EVENTS,\n };\n});\n"],"names":["define","$","SELECTORS","EVENTS","ROW_CHANGE","changeListener","e","element","target","minRows","data","currentRows","attr","rows","maxRows","height","padding","innerHeight","scrollHeight","css","calculateRows","trigger","init","root","on","bind","this","events"],"mappings":";;;;;;;;AAuBAA,wBAAO,CAAC,WAAW,SAASC,OACpBC,kBACS,mBAGTC,OAAS,CACTC,WAAY,sBA2CZC,eAAiB,SAASC,OACtBC,QAAUN,EAAEK,EAAEE,QACdC,QAAUF,QAAQG,KAAK,YACvBC,YAAcJ,QAAQK,KAAK,aAER,IAAZH,SACPF,QAAQG,KAAK,WAAYC,aAK7BJ,QAAQK,KAAK,OAAQ,OACjBC,KA5CY,SAASN,aACrBI,YAAcJ,QAAQK,KAAK,QAC3BH,QAAUF,QAAQG,KAAK,YACvBI,QAAUP,QAAQK,KAAK,iBAEvBG,OAASR,QAAQQ,SAEjBC,QADcT,QAAQU,cACEF,OAGxBF,MADeN,QAAQ,GAAGW,aACHF,UAAYD,OAASJ,oBAIhDJ,QAAQY,IAAI,SAAU,IAElBN,KAAOJ,QACAA,QACAK,SAAWD,MAAQC,QACnBA,QAEAD,KAuBAO,CAAcb,SACzBA,QAAQK,KAAK,OAAQC,MAEjBA,MAAQF,aACRJ,QAAQc,QAAQlB,OAAOC,mBAmBM,CACjCkB,KATO,SAASC,MACZtB,EAAEsB,MAAMb,KAAK,aACbT,EAAEsB,MAAMC,GAAG,uBAAwBnB,eAAeoB,KAAKC,OAEvDzB,EAAEsB,MAAMC,GAAG,uBAAwBtB,kBAAmBG,eAAeoB,KAAKC,QAM9EC,OAAQxB"}