From b95f339d2260f20b868a46fee546ed7956e785fc Mon Sep 17 00:00:00 2001 From: Julen Pardo Date: Fri, 6 May 2016 11:00:24 +0200 Subject: [PATCH 1/7] issue #11: change build file to run selenium through xvfb --- build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.xml b/build.xml index 1d68c22..6b62949 100644 --- a/build.xml +++ b/build.xml @@ -75,7 +75,7 @@ - + From aafa3dd2f91eff8a0cd1d050a1f459635e288c73 Mon Sep 17 00:00:00 2001 From: Julen Pardo Date: Fri, 6 May 2016 12:35:46 +0200 Subject: [PATCH 2/7] issue #11: kill xvbf manually before starting with behat Kills both Selenium and xvfb are killed. The "killall" command is a dirty workaround to issue #11, but no other way has been found to make the tests work properly. --- build.xml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build.xml b/build.xml index 6b62949..62f3cce 100644 --- a/build.xml +++ b/build.xml @@ -70,7 +70,9 @@ - + + + @@ -78,7 +80,7 @@ - + From c136e38d6899f0246b98d968b32239ebd1eef742 Mon Sep 17 00:00:00 2001 From: Julen Pardo Date: Fri, 6 May 2016 15:41:17 +0200 Subject: [PATCH 3/7] issue #16: update test to check that spans are not displayed; remove unnecessary test --- tests/behat/multilang2.feature | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/tests/behat/multilang2.feature b/tests/behat/multilang2.feature index 7492def..1b061cf 100644 --- a/tests/behat/multilang2.feature +++ b/tests/behat/multilang2.feature @@ -14,25 +14,11 @@ Feature: Atto multilanguage list And I select the text in the "Description" Atto editor When I click on "Multi-Language Content (v2)" "button" When I click on "English" "link" - Then I should see "{mlang en}Multilingual content{mlang}" - - @javascript - Scenario: Tag some text with multilang labels again, now checking their style - Given I log in as "admin" - And the following config values are set as admin: - | toolbar | multilang2 = multilang2, table | editor_atto | # Needed table button, otherwise multilang list doesn't spread out... - And I am on homepage - And I follow "Profile" in the user menu - And I follow "Edit profile" - And I set the field "Description" to "Multilingual content, again" - And I select the text in the "Description" Atto editor - When I click on "Multi-Language Content (v2)" "button" - When I click on "English" "link" And I press "Update profile" And I follow "Preferences" in the user menu And I follow "Editor preferences" And I set the field "Text editor" to "Plain text area" And I press "Save changes" And I follow "Edit profile" - Then I should see "{mlang en}Multilingual content, again{mlang}" - + Then I should see "{mlang en}Multilingual content{mlang}" + And I should not see "{mlang en}" From 016764d3835ceceedcd7af70d209545a8aaf93af Mon Sep 17 00:00:00 2001 From: Julen Pardo Date: Tue, 24 May 2016 16:56:18 +0200 Subject: [PATCH 4/7] issue #17: add listeners only for those buttons that are for submitting the form For submitting the actual form of the page, not any other form that may appear in the page (admin search, e.g.). --- .../moodle-atto_multilang2-button-coverage.js | 4 +- .../moodle-atto_multilang2-button-debug.js | 72 +++++++------------ .../moodle-atto_multilang2-button-min.js | 2 +- .../moodle-atto_multilang2-button.js | 72 +++++++------------ yui/src/button/js/button.js | 72 +++++++------------ 5 files changed, 81 insertions(+), 141 deletions(-) diff --git a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-coverage.js b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-coverage.js index df5c530..c884c22 100644 --- a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-coverage.js +++ b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-coverage.js @@ -1,6 +1,6 @@ if (typeof __coverage__ === 'undefined') { __coverage__ = {}; } if (!__coverage__['build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js']) { - __coverage__['build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js'] = {"path":"build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0,"100":0,"101":0,"102":0,"103":0,"104":0,"105":0,"106":0,"107":0,"108":0,"109":0,"110":0,"111":0,"112":0,"113":0,"114":0,"115":0,"116":0,"117":0,"118":0,"119":0,"120":0,"121":0,"122":0,"123":0,"124":0,"125":0,"126":0,"127":0,"128":0,"129":0,"130":0,"131":0,"132":0,"133":0,"134":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0],"14":[0,0],"15":[0,0],"16":[0,0],"17":[0,0],"18":[0,0],"19":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0},"fnMap":{"1":{"name":"(anonymous_1)","line":1,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":60}}},"2":{"name":"(anonymous_2)","line":73,"loc":{"start":{"line":73,"column":17},"end":{"line":73,"column":28}}},"3":{"name":"(anonymous_3)","line":107,"loc":{"start":{"line":107,"column":22},"end":{"line":107,"column":33}}},"4":{"name":"(anonymous_4)","line":126,"loc":{"start":{"line":126,"column":29},"end":{"line":126,"column":40}}},"5":{"name":"(anonymous_5)","line":161,"loc":{"start":{"line":161,"column":14},"end":{"line":161,"column":36}}},"6":{"name":"(anonymous_6)","line":188,"loc":{"start":{"line":188,"column":23},"end":{"line":188,"column":34}}},"7":{"name":"(anonymous_7)","line":222,"loc":{"start":{"line":222,"column":27},"end":{"line":222,"column":38}}},"8":{"name":"(anonymous_8)","line":248,"loc":{"start":{"line":248,"column":25},"end":{"line":248,"column":36}}},"9":{"name":"(anonymous_9)","line":270,"loc":{"start":{"line":270,"column":24},"end":{"line":270,"column":36}}},"10":{"name":"(anonymous_10)","line":299,"loc":{"start":{"line":299,"column":36},"end":{"line":299,"column":48}}},"11":{"name":"(anonymous_11)","line":332,"loc":{"start":{"line":332,"column":27},"end":{"line":332,"column":38}}},"12":{"name":"(anonymous_12)","line":397,"loc":{"start":{"line":397,"column":26},"end":{"line":397,"column":37}}},"13":{"name":"(anonymous_13)","line":466,"loc":{"start":{"line":466,"column":25},"end":{"line":466,"column":36}}},"14":{"name":"(anonymous_14)","line":513,"loc":{"start":{"line":513,"column":29},"end":{"line":513,"column":40}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":582,"column":61}},"2":{"start":{"line":28,"column":0},"end":{"line":52,"column":56}},"3":{"start":{"line":62,"column":0},"end":{"line":579,"column":3}},"4":{"start":{"line":74,"column":8},"end":{"line":75,"column":30}},"5":{"start":{"line":77,"column":8},"end":{"line":98,"column":9}},"6":{"start":{"line":78,"column":12},"end":{"line":78,"column":58}},"7":{"start":{"line":79,"column":12},"end":{"line":79,"column":55}},"8":{"start":{"line":81,"column":12},"end":{"line":88,"column":15}},"9":{"start":{"line":90,"column":12},"end":{"line":90,"column":91}},"10":{"start":{"line":92,"column":12},"end":{"line":92,"column":36}},"11":{"start":{"line":94,"column":12},"end":{"line":97,"column":13}},"12":{"start":{"line":95,"column":16},"end":{"line":95,"column":43}},"13":{"start":{"line":96,"column":16},"end":{"line":96,"column":43}},"14":{"start":{"line":108,"column":8},"end":{"line":109,"column":18}},"15":{"start":{"line":111,"column":8},"end":{"line":111,"column":48}},"16":{"start":{"line":112,"column":8},"end":{"line":112,"column":32}},"17":{"start":{"line":113,"column":8},"end":{"line":113,"column":30}},"18":{"start":{"line":115,"column":8},"end":{"line":115,"column":41}},"19":{"start":{"line":127,"column":8},"end":{"line":129,"column":21}},"20":{"start":{"line":131,"column":8},"end":{"line":131,"column":57}},"21":{"start":{"line":133,"column":8},"end":{"line":140,"column":9}},"22":{"start":{"line":134,"column":12},"end":{"line":139,"column":13}},"23":{"start":{"line":135,"column":16},"end":{"line":138,"column":19}},"24":{"start":{"line":142,"column":8},"end":{"line":142,"column":28}},"25":{"start":{"line":162,"column":8},"end":{"line":165,"column":20}},"26":{"start":{"line":167,"column":8},"end":{"line":167,"column":84}},"27":{"start":{"line":169,"column":8},"end":{"line":169,"column":45}},"28":{"start":{"line":170,"column":8},"end":{"line":170,"column":87}},"29":{"start":{"line":172,"column":8},"end":{"line":172,"column":71}},"30":{"start":{"line":173,"column":8},"end":{"line":173,"column":73}},"31":{"start":{"line":175,"column":8},"end":{"line":175,"column":54}},"32":{"start":{"line":177,"column":8},"end":{"line":177,"column":27}},"33":{"start":{"line":189,"column":8},"end":{"line":193,"column":19}},"34":{"start":{"line":195,"column":8},"end":{"line":210,"column":9}},"35":{"start":{"line":196,"column":12},"end":{"line":196,"column":46}},"36":{"start":{"line":198,"column":12},"end":{"line":204,"column":13}},"37":{"start":{"line":199,"column":16},"end":{"line":199,"column":58}},"38":{"start":{"line":200,"column":16},"end":{"line":202,"column":17}},"39":{"start":{"line":201,"column":20},"end":{"line":201,"column":87}},"40":{"start":{"line":203,"column":16},"end":{"line":203,"column":43}},"41":{"start":{"line":206,"column":15},"end":{"line":210,"column":9}},"42":{"start":{"line":207,"column":12},"end":{"line":209,"column":13}},"43":{"start":{"line":208,"column":16},"end":{"line":208,"column":65}},"44":{"start":{"line":212,"column":8},"end":{"line":212,"column":20}},"45":{"start":{"line":223,"column":8},"end":{"line":227,"column":22}},"46":{"start":{"line":229,"column":8},"end":{"line":229,"column":67}},"47":{"start":{"line":230,"column":8},"end":{"line":230,"column":63}},"48":{"start":{"line":232,"column":8},"end":{"line":234,"column":9}},"49":{"start":{"line":233,"column":12},"end":{"line":233,"column":70}},"50":{"start":{"line":249,"column":8},"end":{"line":250,"column":55}},"51":{"start":{"line":252,"column":8},"end":{"line":252,"column":64}},"52":{"start":{"line":254,"column":8},"end":{"line":256,"column":9}},"53":{"start":{"line":255,"column":12},"end":{"line":255,"column":81}},"54":{"start":{"line":271,"column":8},"end":{"line":271,"column":25}},"55":{"start":{"line":273,"column":8},"end":{"line":273,"column":27}},"56":{"start":{"line":275,"column":8},"end":{"line":275,"column":49}},"57":{"start":{"line":277,"column":8},"end":{"line":277,"column":37}},"58":{"start":{"line":278,"column":8},"end":{"line":278,"column":35}},"59":{"start":{"line":281,"column":8},"end":{"line":281,"column":62}},"60":{"start":{"line":282,"column":8},"end":{"line":282,"column":39}},"61":{"start":{"line":300,"column":8},"end":{"line":300,"column":25}},"62":{"start":{"line":302,"column":8},"end":{"line":302,"column":27}},"63":{"start":{"line":304,"column":8},"end":{"line":304,"column":50}},"64":{"start":{"line":306,"column":8},"end":{"line":306,"column":37}},"65":{"start":{"line":307,"column":8},"end":{"line":307,"column":35}},"66":{"start":{"line":309,"column":8},"end":{"line":309,"column":74}},"67":{"start":{"line":310,"column":8},"end":{"line":310,"column":39}},"68":{"start":{"line":333,"column":8},"end":{"line":341,"column":30}},"69":{"start":{"line":343,"column":8},"end":{"line":343,"column":78}},"70":{"start":{"line":345,"column":8},"end":{"line":349,"column":9}},"71":{"start":{"line":346,"column":12},"end":{"line":346,"column":33}},"72":{"start":{"line":347,"column":12},"end":{"line":347,"column":27}},"73":{"start":{"line":348,"column":12},"end":{"line":348,"column":36}},"74":{"start":{"line":351,"column":8},"end":{"line":373,"column":9}},"75":{"start":{"line":352,"column":12},"end":{"line":352,"column":58}},"76":{"start":{"line":353,"column":12},"end":{"line":353,"column":64}},"77":{"start":{"line":355,"column":12},"end":{"line":355,"column":50}},"78":{"start":{"line":357,"column":12},"end":{"line":357,"column":65}},"79":{"start":{"line":359,"column":12},"end":{"line":361,"column":13}},"80":{"start":{"line":360,"column":16},"end":{"line":360,"column":25}},"81":{"start":{"line":363,"column":12},"end":{"line":370,"column":13}},"82":{"start":{"line":364,"column":16},"end":{"line":364,"column":56}},"83":{"start":{"line":365,"column":16},"end":{"line":365,"column":73}},"84":{"start":{"line":367,"column":16},"end":{"line":367,"column":69}},"85":{"start":{"line":369,"column":16},"end":{"line":369,"column":77}},"86":{"start":{"line":372,"column":12},"end":{"line":372,"column":49}},"87":{"start":{"line":375,"column":8},"end":{"line":375,"column":27}},"88":{"start":{"line":398,"column":8},"end":{"line":408,"column":21}},"89":{"start":{"line":410,"column":8},"end":{"line":410,"column":81}},"90":{"start":{"line":411,"column":8},"end":{"line":411,"column":89}},"91":{"start":{"line":413,"column":8},"end":{"line":417,"column":9}},"92":{"start":{"line":414,"column":12},"end":{"line":414,"column":33}},"93":{"start":{"line":415,"column":12},"end":{"line":415,"column":27}},"94":{"start":{"line":416,"column":12},"end":{"line":416,"column":36}},"95":{"start":{"line":419,"column":8},"end":{"line":444,"column":9}},"96":{"start":{"line":420,"column":12},"end":{"line":420,"column":58}},"97":{"start":{"line":421,"column":12},"end":{"line":421,"column":64}},"98":{"start":{"line":423,"column":12},"end":{"line":423,"column":50}},"99":{"start":{"line":425,"column":12},"end":{"line":425,"column":73}},"100":{"start":{"line":427,"column":12},"end":{"line":429,"column":13}},"101":{"start":{"line":428,"column":16},"end":{"line":428,"column":25}},"102":{"start":{"line":431,"column":12},"end":{"line":439,"column":13}},"103":{"start":{"line":432,"column":16},"end":{"line":432,"column":64}},"104":{"start":{"line":433,"column":16},"end":{"line":433,"column":68}},"105":{"start":{"line":435,"column":16},"end":{"line":435,"column":84}},"106":{"start":{"line":436,"column":16},"end":{"line":436,"column":69}},"107":{"start":{"line":438,"column":16},"end":{"line":438,"column":77}},"108":{"start":{"line":441,"column":12},"end":{"line":441,"column":49}},"109":{"start":{"line":443,"column":12},"end":{"line":443,"column":31}},"110":{"start":{"line":467,"column":8},"end":{"line":475,"column":27}},"111":{"start":{"line":477,"column":8},"end":{"line":477,"column":51}},"112":{"start":{"line":479,"column":8},"end":{"line":479,"column":58}},"113":{"start":{"line":480,"column":8},"end":{"line":480,"column":55}},"114":{"start":{"line":482,"column":8},"end":{"line":499,"column":9}},"115":{"start":{"line":483,"column":12},"end":{"line":496,"column":13}},"116":{"start":{"line":484,"column":16},"end":{"line":484,"column":44}},"117":{"start":{"line":486,"column":16},"end":{"line":486,"column":75}},"118":{"start":{"line":488,"column":16},"end":{"line":495,"column":17}},"119":{"start":{"line":489,"column":20},"end":{"line":489,"column":52}},"120":{"start":{"line":491,"column":20},"end":{"line":491,"column":76}},"121":{"start":{"line":492,"column":20},"end":{"line":492,"column":66}},"122":{"start":{"line":494,"column":20},"end":{"line":494,"column":88}},"123":{"start":{"line":498,"column":12},"end":{"line":498,"column":49}},"124":{"start":{"line":514,"column":8},"end":{"line":521,"column":18}},"125":{"start":{"line":523,"column":8},"end":{"line":523,"column":55}},"126":{"start":{"line":524,"column":8},"end":{"line":524,"column":57}},"127":{"start":{"line":525,"column":8},"end":{"line":525,"column":61}},"128":{"start":{"line":527,"column":8},"end":{"line":536,"column":9}},"129":{"start":{"line":528,"column":12},"end":{"line":535,"column":13}},"130":{"start":{"line":529,"column":16},"end":{"line":529,"column":56}},"131":{"start":{"line":531,"column":16},"end":{"line":531,"column":73}},"132":{"start":{"line":532,"column":16},"end":{"line":532,"column":69}},"133":{"start":{"line":534,"column":16},"end":{"line":534,"column":77}},"134":{"start":{"line":538,"column":8},"end":{"line":538,"column":25}}},"branchMap":{"1":{"line":77,"type":"if","locations":[{"start":{"line":77,"column":8},"end":{"line":77,"column":8}},{"start":{"line":77,"column":8},"end":{"line":77,"column":8}}]},"2":{"line":94,"type":"if","locations":[{"start":{"line":94,"column":12},"end":{"line":94,"column":12}},{"start":{"line":94,"column":12},"end":{"line":94,"column":12}}]},"3":{"line":134,"type":"if","locations":[{"start":{"line":134,"column":12},"end":{"line":134,"column":12}},{"start":{"line":134,"column":12},"end":{"line":134,"column":12}}]},"4":{"line":167,"type":"cond-expr","locations":[{"start":{"line":167,"column":44},"end":{"line":167,"column":60}},{"start":{"line":167,"column":63},"end":{"line":167,"column":83}}]},"5":{"line":170,"type":"cond-expr","locations":[{"start":{"line":170,"column":66},"end":{"line":170,"column":74}},{"start":{"line":170,"column":77},"end":{"line":170,"column":86}}]},"6":{"line":195,"type":"if","locations":[{"start":{"line":195,"column":8},"end":{"line":195,"column":8}},{"start":{"line":195,"column":8},"end":{"line":195,"column":8}}]},"7":{"line":198,"type":"if","locations":[{"start":{"line":198,"column":12},"end":{"line":198,"column":12}},{"start":{"line":198,"column":12},"end":{"line":198,"column":12}}]},"8":{"line":206,"type":"if","locations":[{"start":{"line":206,"column":15},"end":{"line":206,"column":15}},{"start":{"line":206,"column":15},"end":{"line":206,"column":15}}]},"9":{"line":207,"type":"if","locations":[{"start":{"line":207,"column":12},"end":{"line":207,"column":12}},{"start":{"line":207,"column":12},"end":{"line":207,"column":12}}]},"10":{"line":232,"type":"if","locations":[{"start":{"line":232,"column":8},"end":{"line":232,"column":8}},{"start":{"line":232,"column":8},"end":{"line":232,"column":8}}]},"11":{"line":232,"type":"binary-expr","locations":[{"start":{"line":232,"column":12},"end":{"line":232,"column":22}},{"start":{"line":232,"column":26},"end":{"line":232,"column":35}}]},"12":{"line":254,"type":"if","locations":[{"start":{"line":254,"column":8},"end":{"line":254,"column":8}},{"start":{"line":254,"column":8},"end":{"line":254,"column":8}}]},"13":{"line":345,"type":"if","locations":[{"start":{"line":345,"column":8},"end":{"line":345,"column":8}},{"start":{"line":345,"column":8},"end":{"line":345,"column":8}}]},"14":{"line":359,"type":"if","locations":[{"start":{"line":359,"column":12},"end":{"line":359,"column":12}},{"start":{"line":359,"column":12},"end":{"line":359,"column":12}}]},"15":{"line":413,"type":"if","locations":[{"start":{"line":413,"column":8},"end":{"line":413,"column":8}},{"start":{"line":413,"column":8},"end":{"line":413,"column":8}}]},"16":{"line":427,"type":"if","locations":[{"start":{"line":427,"column":12},"end":{"line":427,"column":12}},{"start":{"line":427,"column":12},"end":{"line":427,"column":12}}]},"17":{"line":482,"type":"if","locations":[{"start":{"line":482,"column":8},"end":{"line":482,"column":8}},{"start":{"line":482,"column":8},"end":{"line":482,"column":8}}]},"18":{"line":488,"type":"if","locations":[{"start":{"line":488,"column":16},"end":{"line":488,"column":16}},{"start":{"line":488,"column":16},"end":{"line":488,"column":16}}]},"19":{"line":527,"type":"if","locations":[{"start":{"line":527,"column":8},"end":{"line":527,"column":8}},{"start":{"line":527,"column":8},"end":{"line":527,"column":8}}]}},"code":["(function () { YUI.add('moodle-atto_multilang2-button', function (Y, NAME) {","","// This file is part of Moodle - http://moodle.org/","//","// Moodle is free software: you can redistribute it and/or modify","// it under the terms of the GNU General Public License as published by","// the Free Software Foundation, either version 3 of the License, or","// (at your option) any later version.","//","// Moodle is distributed in the hope that it will be useful,","// but WITHOUT ANY WARRANTY; without even the implied warranty of","// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the","// GNU General Public License for more details.","//","// You should have received a copy of the GNU General Public License","// along with Moodle. If not, see .","","/**"," * @package atto_multilang2"," * @copyright 2015 onwards Julen Pardo & Mondragon Unibertsitatea"," * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later"," */","","/**"," * @module moodle-atto_multilang2-button"," */","","var CLASSES = {"," TAG: 'filter-multilang-tag'"," },",""," LANG_WILDCARD = '%lang',"," CONTENT_WILDCARD = '%content',"," ATTR_LANGUAGES = 'languages',"," ATTR_CAPABILITY = 'capability',"," ATTR_HIGHLIGHT = 'highlight',"," ATTR_CSS = 'css',"," DEFAULT_LANGUAGE = '{\"en\":\"English (en)\"}',"," DEFAULT_CAPABILITY = true,"," DEFAULT_HIGHLIGHT = true,"," DEFAULT_CSS = 'outline: 1px dotted;' +"," 'padding: 0.1em;' +"," 'margin: 0em 0.1em;' +"," 'background-color: #ffffaa;',"," TEMPLATES = {"," SPANED: ' {mlang ' + LANG_WILDCARD + '}' +"," CONTENT_WILDCARD +"," '{mlang} ',",""," NOT_SPANED: '{mlang ' + LANG_WILDCARD + '}' + CONTENT_WILDCARD + '{mlang}'"," },"," OPENING_SPAN = '';","","/**"," * Atto text editor multilanguage plugin."," *"," * @namespace M.atto_multilang2"," * @class button"," * @extends M.editor_atto.EditorPlugin"," */","","Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {",""," /**"," * If the {mlang} tags have to be highlighted or not. Received as parameter from lib.php."," *"," * @property _highlight"," * @type boolean"," * @private"," */"," _highlight: true,",""," initializer: function() {"," var hascapability = this.get(ATTR_CAPABILITY),"," toolbarItems = [];",""," if (hascapability) {"," toolbarItems = this._initializeToolbarItems();"," this._highlight = this.get(ATTR_HIGHLIGHT);",""," this.addToolbarMenu({"," globalItemConfig: {"," callback: this._addTags"," },"," icon: 'icon',"," iconComponent: 'atto_multilang2',"," items: toolbarItems"," });",""," this.get('host').on('atto:selectionchanged', this._checkSelectionChange, this);",""," this._addDelimiterCss();",""," if (this._highlight) {"," this._decorateTagsOnInit();"," this._setSubmitListeners();"," }"," }"," },",""," /**"," * Adds the CSS rules for the delimiters, received as parameter from lib.php."," *"," * @method _addDelimiterCss"," * @private"," */"," _addDelimiterCss: function() {"," var css = '.' + CLASSES.TAG + '{' + this.get(ATTR_CSS) + '}',"," style;",""," style = document.createElement('style');"," style.type = 'text/css';"," style.innerHTML = css;",""," document.head.appendChild(style);"," },",""," /**"," * Initializes the toolbar items, which will be the installed languages,"," * received as parameter."," *"," * @method _initializeToolbarItems"," * @private"," * @return {Array} installed language strings"," */"," _initializeToolbarItems: function() {"," var toolbarItems = [],"," languages,"," langCode;",""," languages = JSON.parse(this.get(ATTR_LANGUAGES));",""," for (langCode in languages) {"," if (languages.hasOwnProperty(langCode)) {"," toolbarItems.push({"," text: languages[langCode],"," callbackArgs: langCode"," });"," }"," }",""," return toolbarItems;"," },",""," /**"," * Retrieves the selected text, wraps it with the multilang tags,"," * and replaces the selected text in the editor with with it."," *"," * If the 'highlight' setting is checked, the {mlang} will be wrapped between"," * the tags with the class for the CSS highlight; if not, they will not"," * be wrapped."," *"," * If there is no content selected, a \" \" will be inserted; otherwhise,"," * it's impossible to place the cursor inside the {mlang} tags."," *"," * @method _addTags"," * @param {EventFacade} e"," * @param {string} langCode the language code"," * @private"," */"," _addTags: function(e, langCode) {"," var selection,"," host = this.get('host'),"," taggedContent,"," content;",""," taggedContent = (this._highlight) ? TEMPLATES.SPANED : TEMPLATES.NOT_SPANED;",""," selection = this._getSelectionHTML();"," content = (host.getSelection().toString().length === 0) ? ' ' : selection;",""," taggedContent = taggedContent.replace(LANG_WILDCARD, langCode);"," taggedContent = taggedContent.replace(CONTENT_WILDCARD, content);",""," host.insertContentAtFocusPoint(taggedContent);",""," this.markUpdated();"," },",""," /**"," * Retrieves selected text with its HTML."," * Took from: http://stackoverflow.com/questions/4176923/html-of-selected-text/4177234#4177234"," *"," * @method _getSelectionHTML"," * @private"," * @return {string} selected text's html; empty if nothing selected"," */"," _getSelectionHTML: function() {"," var html = '',"," selection,"," container,"," index,"," lenght;",""," if (typeof window.getSelection !== 'undefined') {"," selection = window.getSelection();",""," if (selection.rangeCount) {"," container = document.createElement('div');"," for (index = 0, lenght = selection.rangeCount; index < lenght; ++index) {"," container.appendChild(selection.getRangeAt(index).cloneContents());"," }"," html = container.innerHTML;"," }",""," } else if (typeof document.selection !== 'undefined') {"," if (document.selection.type === 'Text') {"," html = document.selection.createRange().htmlText;"," }"," }",""," return html;"," },",""," /**"," * Listens to every change of the text cursor in the text area. If the"," * cursor is placed within a multilang tag, the whole tag is selected."," *"," * @method _checkSelectionChange"," * @private"," */"," _checkSelectionChange: function() {"," var host = this.get('host'),"," node = host.getSelectionParentNode(),"," nodeValue = Y.one(node).get('text'),"," isTextNode,"," isLangTag;",""," isTextNode = Y.one(node).toString().indexOf('#text') > - 1;"," isLangTag = (nodeValue.match(/\\{mlang/g).length === 1);",""," if (isTextNode && isLangTag) {"," host.setSelection(host.getSelectionFromNode(Y.one(node)));"," }"," },",""," /**"," * Sets the submit listener to the function that finds the spaned {mlang} tags."," *"," * In some forms, there may be two different submit buttons, so we add the listener"," * to the second, if this exists."," *"," * These submit listeners are set only if the \"highlight\" plugin setting is checked."," *"," * @method _setSubmitListener"," * @private"," */"," _setSubmitListeners: function() {"," var submitbutton = Y.one('#id_submitbutton'),"," submitbutton2 = Y.one('#id_submitbutton2');",""," submitbutton.on('click', this._cleanTagsOnSubmit, this);",""," if (submitbutton2 !== null) {"," submitbutton2.on('click', this._cleanTagsOnSubmitSecondButton, this);"," }"," },",""," /**"," * When submit button clicked, this function is invoked. It has to stop the submission,"," * in order to process the textarea to clean the tags."," *"," * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default,"," * an then simulates the click, to submit the form."," *"," * @method _cleanTagsOnSubmit"," * @param {EventFacade} e"," * @private"," */"," _cleanTagsOnSubmit: function(e) {"," var submitbutton;",""," e.preventDefault();",""," submitbutton = Y.one('#id_submitbutton');",""," this._cleanTagsWithNoYuiId();"," this._cleanTagsWithYuiId();","",""," submitbutton.detach('click', this._cleanTagsOnSubmit);"," submitbutton.simulate('click');"," },",""," /**"," * When submit button clicked, this function is invoked. It has to stop the submission,"," * in order to process the textarea to clean the tags."," *"," * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default,"," * an then simulates the click, to submit the form."," *"," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * @method _cleanTagsOnSubmit"," * @param {EventFacade} e"," * @private"," */"," _cleanTagsOnSubmitSecondButton: function(e) {"," var submitbutton;",""," e.preventDefault();",""," submitbutton = Y.one('#id_submitbutton2');",""," this._cleanTagsWithNoYuiId();"," this._cleanTagsWithYuiId();",""," submitbutton.detach('click', this._cleanTagsOnSubmitSecondButton);"," submitbutton.simulate('click');"," },",""," /**"," * Cleans the tags around the {mlang} tags when the form is submitted,"," * that do not have \"id\" attribute."," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * There may be more than one atto editor textarea in the page. So, we have to retrieve"," * the textareas by the class name. If there is only one, the object will be only the"," * reference, but, if there are more, we will have an array. So, the easiest way is to"," * check if what we have is an array, and if it not, create it manually, and iterate it"," * later."," *"," * issue #15: the textareas are now retrieved passing to YUI selector the whole element,"," * instead of the id string, due to problems with special characters."," * See discussion: https://moodle.org/mod/forum/discuss.php?d=332217"," *"," * @method _cleanTagsWithNoYuiId"," * @private"," */"," _cleanTagsWithNoYuiId: function() {"," var textareas = Y.all('.editor_atto_content'),"," textarea,"," textareaIndex,"," innerHTML,"," spanedmlangtags,"," spanedmlangtag,"," index,"," cleanmlangtag,"," regularExpression;",""," regularExpression = new RegExp(OPENING_SPAN + '.*?' + '', 'g');",""," if (!textareas instanceof Array) {"," textarea = textareas;"," textareas = [];"," textareas[0] = textarea;"," }",""," for (textareaIndex = 0; textareaIndex < textareas._nodes.length; textareaIndex++) {"," textarea = textareas._nodes[textareaIndex].id;"," textarea = Y.one(document.getElementById(textarea));",""," innerHTML = textarea.get('innerHTML');",""," spanedmlangtags = innerHTML.match(regularExpression);",""," if (spanedmlangtags === null) {"," continue;"," }"," "," for (index = 0; index < spanedmlangtags.length; index++) {"," spanedmlangtag = spanedmlangtags[index];"," cleanmlangtag = spanedmlangtag.replace(OPENING_SPAN, '');",""," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }",""," textarea.set('innerHTML', innerHTML);"," }",""," this.markUpdated();"," },",""," /**"," * Cleans the tags around the {mlang} tags when the form is submitted,"," * that have \"id\" attribute, generated by YUI, when the cursor is placed on the tags."," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * There may be more than one atto editor textarea in the page. So, we have to retrieve"," * the textareas by the class name. If there is only one, the object will be only the"," * reference, but, if there are more, we will have an array. So, the easiest way is to"," * check if what we have is an array, and if it not, create it manually, and iterate it"," * later."," *"," * issue #15: the textareas are now retrieved passing to YUI selector the whole element,"," * instead of the id string, due to problems with special characters."," * See discussion: https://moodle.org/mod/forum/discuss.php?d=332217"," *"," * @method anTagsWithYuiId"," * @private"," */"," _cleanTagsWithYuiId: function() {"," var textareas = Y.all('.editor_atto_content'),"," textarea,"," textareaIndex,"," innerHTML,"," spanedmlangtag,"," index,"," cleanmlangtag,"," regularExpression,"," openingspanwithyui,"," spanedmlangtagsdwithyui,"," mlangtag;",""," openingspanwithyui = OPENING_SPAN.replace('', 'g');",""," if (!textareas instanceof Array) {"," textarea = textareas;"," textareas = [];"," textareas[0] = textarea;"," }"," "," for (textareaIndex = 0; textareaIndex < textareas._nodes.length; textareaIndex++) {"," textarea = textareas._nodes[textareaIndex].id;"," textarea = Y.one(document.getElementById(textarea));",""," innerHTML = textarea.get('innerHTML');",""," spanedmlangtagsdwithyui = innerHTML.match(regularExpression);",""," if (spanedmlangtagsdwithyui === null) {"," continue;"," }"," "," for (index = 0; index < spanedmlangtagsdwithyui.length; index++) {"," spanedmlangtag = spanedmlangtagsdwithyui[index];"," mlangtag = spanedmlangtag.match(/\\{mlang.*?\\}/g)[0];",""," cleanmlangtag = spanedmlangtag.replace(regularExpression, mlangtag);"," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }",""," textarea.set('innerHTML', innerHTML);",""," this.markUpdated();"," }"," },",""," /**"," * Adds the tags to the {mlang} tags when the editor is loaded."," * In this case, we DON'T HAVE TO CALL TO markUpdated(). Why? Honestly,"," * I don't know. But, if we call it after setting the HTML, the {mlang}"," * tags flicker with the decoration, and returns to their original state."," *"," * Instead of taking the HTML directly from the textarea, we have to"," * retrieve it, first, without the tags that can be stored"," * in database, due to a bug in version 2015120501 that stores the"," * {mlang} tags in database, with the tags."," * More info about this bug: https://github.com/julenpardo/moodle-atto_multilang2/issues/8"," *"," * Every different {mlang} tag has to be replaced only once, otherwise,"," * nested s will be created in every repeated replacement. So, we"," * have to have a track of which replacements have been made."," *"," * @method _decorateTagsOnInit"," * @private"," */"," _decorateTagsOnInit: function() {"," var textarea = Y.all('.editor_atto_content'),"," innerHTML,"," regularExpression,"," mlangtags,"," mlangtag,"," index,"," decoratedmlangtag,"," replacementsmade = [],"," notreplacedyet;",""," innerHTML = this._getHTMLwithCleanedTags();",""," regularExpression = new RegExp('{mlang.*?}', 'g');"," mlangtags = innerHTML.match(regularExpression);",""," if (mlangtags !== null) {"," for (index = 0; index < mlangtags.length; index++) {"," mlangtag = mlangtags[index];",""," notreplacedyet = replacementsmade.indexOf(mlangtag) === -1;",""," if (notreplacedyet) {"," replacementsmade.push(mlangtag);",""," decoratedmlangtag = OPENING_SPAN + mlangtag + '';"," regularExpression = new RegExp(mlangtag, 'g');",""," innerHTML = innerHTML.replace(regularExpression, decoratedmlangtag);"," }"," }",""," textarea.set('innerHTML', innerHTML);"," }",""," },",""," /**"," * This function returns the HTML as it is in the textarea, but cleaning every"," * tag around the {mlang} tags. This is necessary for decorating tags on"," * init, because it could happen that in database are stored the {mlang} tags with"," * their tags, due to a bug in version 2015120501."," * More info about this bug: https://github.com/julenpardo/moodle-atto_multilang2/issues/8"," *"," * @method _getHTMLwithCleanedTags"," * @return {string} HTML in textarea, without any around {mlang} tags"," */"," _getHTMLwithCleanedTags: function() {"," var host = this.get('host'),"," innerHTML = host.getCleanHTML(),"," regexString,"," regularExpression,"," spanedmlangtags,"," spanedmlangtag,"," cleanmlangtag,"," index;",""," regexString = OPENING_SPAN + '.*?' + '';"," regularExpression = new RegExp(regexString, 'g');"," spanedmlangtags = innerHTML.match(regularExpression);",""," if (spanedmlangtags !== null) {"," for (index = 0; index < spanedmlangtags.length; index++) {"," spanedmlangtag = spanedmlangtags[index];",""," cleanmlangtag = spanedmlangtag.replace(OPENING_SPAN, '');"," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }"," }",""," return innerHTML;"," }","","}, {"," ATTRS: {"," /**"," * The list of installed languages."," *"," * @attribute languages"," * @type array"," * @default {\"en\":\"English (en)\"}"," */"," languages: DEFAULT_LANGUAGE,",""," /**"," * If the current user has the capability to use the plugin."," *"," * @attribute capability"," * @type boolean"," * @default true"," */"," capability: DEFAULT_CAPABILITY,",""," /**"," * If the {mlang} tags have to be highlighted or not."," *"," * @property highlight"," * @type boolean"," * @default true"," */"," highlight: DEFAULT_HIGHLIGHT,",""," /**"," * The CSS for delimiters."," *"," * @property css"," * @type string"," * @default DEFAULT_CSS"," */"," css: DEFAULT_CSS"," }","});","","","}, '@VERSION@', {\"requires\": [\"moodle-editor_atto-plugin\"]});","","}());"]}; + __coverage__['build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js'] = {"path":"build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0,"100":0,"101":0,"102":0,"103":0,"104":0,"105":0,"106":0,"107":0,"108":0,"109":0,"110":0,"111":0,"112":0,"113":0,"114":0,"115":0,"116":0,"117":0,"118":0,"119":0,"120":0,"121":0,"122":0,"123":0,"124":0,"125":0,"126":0,"127":0,"128":0,"129":0,"130":0,"131":0,"132":0,"133":0,"134":0,"135":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0],"14":[0,0],"15":[0,0],"16":[0,0],"17":[0,0],"18":[0,0],"19":[0,0],"20":[0,0],"21":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0},"fnMap":{"1":{"name":"(anonymous_1)","line":1,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":60}}},"2":{"name":"(anonymous_2)","line":75,"loc":{"start":{"line":75,"column":17},"end":{"line":75,"column":28}}},"3":{"name":"(anonymous_3)","line":109,"loc":{"start":{"line":109,"column":22},"end":{"line":109,"column":33}}},"4":{"name":"(anonymous_4)","line":128,"loc":{"start":{"line":128,"column":29},"end":{"line":128,"column":40}}},"5":{"name":"(anonymous_5)","line":163,"loc":{"start":{"line":163,"column":14},"end":{"line":163,"column":36}}},"6":{"name":"(anonymous_6)","line":190,"loc":{"start":{"line":190,"column":23},"end":{"line":190,"column":34}}},"7":{"name":"(anonymous_7)","line":224,"loc":{"start":{"line":224,"column":27},"end":{"line":224,"column":38}}},"8":{"name":"(anonymous_8)","line":250,"loc":{"start":{"line":250,"column":25},"end":{"line":250,"column":36}}},"9":{"name":"(anonymous_9)","line":256,"loc":{"start":{"line":256,"column":33},"end":{"line":256,"column":54}}},"10":{"name":"(anonymous_10)","line":279,"loc":{"start":{"line":279,"column":24},"end":{"line":279,"column":36}}},"11":{"name":"(anonymous_11)","line":312,"loc":{"start":{"line":312,"column":27},"end":{"line":312,"column":38}}},"12":{"name":"(anonymous_12)","line":377,"loc":{"start":{"line":377,"column":26},"end":{"line":377,"column":37}}},"13":{"name":"(anonymous_13)","line":446,"loc":{"start":{"line":446,"column":25},"end":{"line":446,"column":36}}},"14":{"name":"(anonymous_14)","line":493,"loc":{"start":{"line":493,"column":29},"end":{"line":493,"column":40}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":562,"column":61}},"2":{"start":{"line":28,"column":0},"end":{"line":52,"column":56}},"3":{"start":{"line":62,"column":0},"end":{"line":559,"column":3}},"4":{"start":{"line":76,"column":8},"end":{"line":77,"column":30}},"5":{"start":{"line":79,"column":8},"end":{"line":100,"column":9}},"6":{"start":{"line":80,"column":12},"end":{"line":80,"column":58}},"7":{"start":{"line":81,"column":12},"end":{"line":81,"column":55}},"8":{"start":{"line":83,"column":12},"end":{"line":90,"column":15}},"9":{"start":{"line":92,"column":12},"end":{"line":92,"column":91}},"10":{"start":{"line":94,"column":12},"end":{"line":94,"column":36}},"11":{"start":{"line":96,"column":12},"end":{"line":99,"column":13}},"12":{"start":{"line":97,"column":16},"end":{"line":97,"column":43}},"13":{"start":{"line":98,"column":16},"end":{"line":98,"column":43}},"14":{"start":{"line":110,"column":8},"end":{"line":111,"column":18}},"15":{"start":{"line":113,"column":8},"end":{"line":113,"column":48}},"16":{"start":{"line":114,"column":8},"end":{"line":114,"column":32}},"17":{"start":{"line":115,"column":8},"end":{"line":115,"column":30}},"18":{"start":{"line":117,"column":8},"end":{"line":117,"column":41}},"19":{"start":{"line":129,"column":8},"end":{"line":131,"column":21}},"20":{"start":{"line":133,"column":8},"end":{"line":133,"column":57}},"21":{"start":{"line":135,"column":8},"end":{"line":142,"column":9}},"22":{"start":{"line":136,"column":12},"end":{"line":141,"column":13}},"23":{"start":{"line":137,"column":16},"end":{"line":140,"column":19}},"24":{"start":{"line":144,"column":8},"end":{"line":144,"column":28}},"25":{"start":{"line":164,"column":8},"end":{"line":167,"column":20}},"26":{"start":{"line":169,"column":8},"end":{"line":169,"column":84}},"27":{"start":{"line":171,"column":8},"end":{"line":171,"column":45}},"28":{"start":{"line":172,"column":8},"end":{"line":172,"column":87}},"29":{"start":{"line":174,"column":8},"end":{"line":174,"column":71}},"30":{"start":{"line":175,"column":8},"end":{"line":175,"column":73}},"31":{"start":{"line":177,"column":8},"end":{"line":177,"column":54}},"32":{"start":{"line":179,"column":8},"end":{"line":179,"column":27}},"33":{"start":{"line":191,"column":8},"end":{"line":195,"column":19}},"34":{"start":{"line":197,"column":8},"end":{"line":212,"column":9}},"35":{"start":{"line":198,"column":12},"end":{"line":198,"column":46}},"36":{"start":{"line":200,"column":12},"end":{"line":206,"column":13}},"37":{"start":{"line":201,"column":16},"end":{"line":201,"column":58}},"38":{"start":{"line":202,"column":16},"end":{"line":204,"column":17}},"39":{"start":{"line":203,"column":20},"end":{"line":203,"column":87}},"40":{"start":{"line":205,"column":16},"end":{"line":205,"column":43}},"41":{"start":{"line":208,"column":15},"end":{"line":212,"column":9}},"42":{"start":{"line":209,"column":12},"end":{"line":211,"column":13}},"43":{"start":{"line":210,"column":16},"end":{"line":210,"column":65}},"44":{"start":{"line":214,"column":8},"end":{"line":214,"column":20}},"45":{"start":{"line":225,"column":8},"end":{"line":229,"column":22}},"46":{"start":{"line":231,"column":8},"end":{"line":231,"column":67}},"47":{"start":{"line":232,"column":8},"end":{"line":232,"column":63}},"48":{"start":{"line":234,"column":8},"end":{"line":236,"column":9}},"49":{"start":{"line":235,"column":12},"end":{"line":235,"column":70}},"50":{"start":{"line":251,"column":8},"end":{"line":251,"column":56}},"51":{"start":{"line":253,"column":8},"end":{"line":253,"column":67}},"52":{"start":{"line":257,"column":8},"end":{"line":261,"column":28}},"53":{"start":{"line":263,"column":8},"end":{"line":263,"column":69}},"54":{"start":{"line":265,"column":8},"end":{"line":276,"column":9}},"55":{"start":{"line":266,"column":12},"end":{"line":266,"column":47}},"56":{"start":{"line":267,"column":12},"end":{"line":267,"column":62}},"57":{"start":{"line":269,"column":12},"end":{"line":269,"column":70}},"58":{"start":{"line":270,"column":12},"end":{"line":270,"column":77}},"59":{"start":{"line":272,"column":12},"end":{"line":275,"column":13}},"60":{"start":{"line":273,"column":16},"end":{"line":273,"column":60}},"61":{"start":{"line":274,"column":16},"end":{"line":274,"column":70}},"62":{"start":{"line":280,"column":8},"end":{"line":280,"column":25}},"63":{"start":{"line":282,"column":8},"end":{"line":282,"column":27}},"64":{"start":{"line":284,"column":8},"end":{"line":284,"column":61}},"65":{"start":{"line":286,"column":8},"end":{"line":286,"column":37}},"66":{"start":{"line":287,"column":8},"end":{"line":287,"column":35}},"67":{"start":{"line":289,"column":8},"end":{"line":289,"column":62}},"68":{"start":{"line":290,"column":8},"end":{"line":290,"column":39}},"69":{"start":{"line":313,"column":8},"end":{"line":321,"column":30}},"70":{"start":{"line":323,"column":8},"end":{"line":323,"column":78}},"71":{"start":{"line":325,"column":8},"end":{"line":329,"column":9}},"72":{"start":{"line":326,"column":12},"end":{"line":326,"column":33}},"73":{"start":{"line":327,"column":12},"end":{"line":327,"column":27}},"74":{"start":{"line":328,"column":12},"end":{"line":328,"column":36}},"75":{"start":{"line":331,"column":8},"end":{"line":353,"column":9}},"76":{"start":{"line":332,"column":12},"end":{"line":332,"column":58}},"77":{"start":{"line":333,"column":12},"end":{"line":333,"column":64}},"78":{"start":{"line":335,"column":12},"end":{"line":335,"column":50}},"79":{"start":{"line":337,"column":12},"end":{"line":337,"column":65}},"80":{"start":{"line":339,"column":12},"end":{"line":341,"column":13}},"81":{"start":{"line":340,"column":16},"end":{"line":340,"column":25}},"82":{"start":{"line":343,"column":12},"end":{"line":350,"column":13}},"83":{"start":{"line":344,"column":16},"end":{"line":344,"column":56}},"84":{"start":{"line":345,"column":16},"end":{"line":345,"column":73}},"85":{"start":{"line":347,"column":16},"end":{"line":347,"column":69}},"86":{"start":{"line":349,"column":16},"end":{"line":349,"column":77}},"87":{"start":{"line":352,"column":12},"end":{"line":352,"column":49}},"88":{"start":{"line":355,"column":8},"end":{"line":355,"column":27}},"89":{"start":{"line":378,"column":8},"end":{"line":388,"column":21}},"90":{"start":{"line":390,"column":8},"end":{"line":390,"column":81}},"91":{"start":{"line":391,"column":8},"end":{"line":391,"column":89}},"92":{"start":{"line":393,"column":8},"end":{"line":397,"column":9}},"93":{"start":{"line":394,"column":12},"end":{"line":394,"column":33}},"94":{"start":{"line":395,"column":12},"end":{"line":395,"column":27}},"95":{"start":{"line":396,"column":12},"end":{"line":396,"column":36}},"96":{"start":{"line":399,"column":8},"end":{"line":424,"column":9}},"97":{"start":{"line":400,"column":12},"end":{"line":400,"column":58}},"98":{"start":{"line":401,"column":12},"end":{"line":401,"column":64}},"99":{"start":{"line":403,"column":12},"end":{"line":403,"column":50}},"100":{"start":{"line":405,"column":12},"end":{"line":405,"column":73}},"101":{"start":{"line":407,"column":12},"end":{"line":409,"column":13}},"102":{"start":{"line":408,"column":16},"end":{"line":408,"column":25}},"103":{"start":{"line":411,"column":12},"end":{"line":419,"column":13}},"104":{"start":{"line":412,"column":16},"end":{"line":412,"column":64}},"105":{"start":{"line":413,"column":16},"end":{"line":413,"column":68}},"106":{"start":{"line":415,"column":16},"end":{"line":415,"column":84}},"107":{"start":{"line":416,"column":16},"end":{"line":416,"column":69}},"108":{"start":{"line":418,"column":16},"end":{"line":418,"column":77}},"109":{"start":{"line":421,"column":12},"end":{"line":421,"column":49}},"110":{"start":{"line":423,"column":12},"end":{"line":423,"column":31}},"111":{"start":{"line":447,"column":8},"end":{"line":455,"column":27}},"112":{"start":{"line":457,"column":8},"end":{"line":457,"column":51}},"113":{"start":{"line":459,"column":8},"end":{"line":459,"column":58}},"114":{"start":{"line":460,"column":8},"end":{"line":460,"column":55}},"115":{"start":{"line":462,"column":8},"end":{"line":479,"column":9}},"116":{"start":{"line":463,"column":12},"end":{"line":476,"column":13}},"117":{"start":{"line":464,"column":16},"end":{"line":464,"column":44}},"118":{"start":{"line":466,"column":16},"end":{"line":466,"column":75}},"119":{"start":{"line":468,"column":16},"end":{"line":475,"column":17}},"120":{"start":{"line":469,"column":20},"end":{"line":469,"column":52}},"121":{"start":{"line":471,"column":20},"end":{"line":471,"column":76}},"122":{"start":{"line":472,"column":20},"end":{"line":472,"column":66}},"123":{"start":{"line":474,"column":20},"end":{"line":474,"column":88}},"124":{"start":{"line":478,"column":12},"end":{"line":478,"column":49}},"125":{"start":{"line":494,"column":8},"end":{"line":501,"column":18}},"126":{"start":{"line":503,"column":8},"end":{"line":503,"column":55}},"127":{"start":{"line":504,"column":8},"end":{"line":504,"column":57}},"128":{"start":{"line":505,"column":8},"end":{"line":505,"column":61}},"129":{"start":{"line":507,"column":8},"end":{"line":516,"column":9}},"130":{"start":{"line":508,"column":12},"end":{"line":515,"column":13}},"131":{"start":{"line":509,"column":16},"end":{"line":509,"column":56}},"132":{"start":{"line":511,"column":16},"end":{"line":511,"column":73}},"133":{"start":{"line":512,"column":16},"end":{"line":512,"column":69}},"134":{"start":{"line":514,"column":16},"end":{"line":514,"column":77}},"135":{"start":{"line":518,"column":8},"end":{"line":518,"column":25}}},"branchMap":{"1":{"line":79,"type":"if","locations":[{"start":{"line":79,"column":8},"end":{"line":79,"column":8}},{"start":{"line":79,"column":8},"end":{"line":79,"column":8}}]},"2":{"line":96,"type":"if","locations":[{"start":{"line":96,"column":12},"end":{"line":96,"column":12}},{"start":{"line":96,"column":12},"end":{"line":96,"column":12}}]},"3":{"line":136,"type":"if","locations":[{"start":{"line":136,"column":12},"end":{"line":136,"column":12}},{"start":{"line":136,"column":12},"end":{"line":136,"column":12}}]},"4":{"line":169,"type":"cond-expr","locations":[{"start":{"line":169,"column":44},"end":{"line":169,"column":60}},{"start":{"line":169,"column":63},"end":{"line":169,"column":83}}]},"5":{"line":172,"type":"cond-expr","locations":[{"start":{"line":172,"column":66},"end":{"line":172,"column":74}},{"start":{"line":172,"column":77},"end":{"line":172,"column":86}}]},"6":{"line":197,"type":"if","locations":[{"start":{"line":197,"column":8},"end":{"line":197,"column":8}},{"start":{"line":197,"column":8},"end":{"line":197,"column":8}}]},"7":{"line":200,"type":"if","locations":[{"start":{"line":200,"column":12},"end":{"line":200,"column":12}},{"start":{"line":200,"column":12},"end":{"line":200,"column":12}}]},"8":{"line":208,"type":"if","locations":[{"start":{"line":208,"column":15},"end":{"line":208,"column":15}},{"start":{"line":208,"column":15},"end":{"line":208,"column":15}}]},"9":{"line":209,"type":"if","locations":[{"start":{"line":209,"column":12},"end":{"line":209,"column":12}},{"start":{"line":209,"column":12},"end":{"line":209,"column":12}}]},"10":{"line":234,"type":"if","locations":[{"start":{"line":234,"column":8},"end":{"line":234,"column":8}},{"start":{"line":234,"column":8},"end":{"line":234,"column":8}}]},"11":{"line":234,"type":"binary-expr","locations":[{"start":{"line":234,"column":12},"end":{"line":234,"column":22}},{"start":{"line":234,"column":26},"end":{"line":234,"column":35}}]},"12":{"line":265,"type":"if","locations":[{"start":{"line":265,"column":8},"end":{"line":265,"column":8}},{"start":{"line":265,"column":8},"end":{"line":265,"column":8}}]},"13":{"line":272,"type":"if","locations":[{"start":{"line":272,"column":12},"end":{"line":272,"column":12}},{"start":{"line":272,"column":12},"end":{"line":272,"column":12}}]},"14":{"line":272,"type":"binary-expr","locations":[{"start":{"line":272,"column":16},"end":{"line":272,"column":31}},{"start":{"line":272,"column":35},"end":{"line":272,"column":50}}]},"15":{"line":325,"type":"if","locations":[{"start":{"line":325,"column":8},"end":{"line":325,"column":8}},{"start":{"line":325,"column":8},"end":{"line":325,"column":8}}]},"16":{"line":339,"type":"if","locations":[{"start":{"line":339,"column":12},"end":{"line":339,"column":12}},{"start":{"line":339,"column":12},"end":{"line":339,"column":12}}]},"17":{"line":393,"type":"if","locations":[{"start":{"line":393,"column":8},"end":{"line":393,"column":8}},{"start":{"line":393,"column":8},"end":{"line":393,"column":8}}]},"18":{"line":407,"type":"if","locations":[{"start":{"line":407,"column":12},"end":{"line":407,"column":12}},{"start":{"line":407,"column":12},"end":{"line":407,"column":12}}]},"19":{"line":462,"type":"if","locations":[{"start":{"line":462,"column":8},"end":{"line":462,"column":8}},{"start":{"line":462,"column":8},"end":{"line":462,"column":8}}]},"20":{"line":468,"type":"if","locations":[{"start":{"line":468,"column":16},"end":{"line":468,"column":16}},{"start":{"line":468,"column":16},"end":{"line":468,"column":16}}]},"21":{"line":507,"type":"if","locations":[{"start":{"line":507,"column":8},"end":{"line":507,"column":8}},{"start":{"line":507,"column":8},"end":{"line":507,"column":8}}]}},"code":["(function () { YUI.add('moodle-atto_multilang2-button', function (Y, NAME) {","","// This file is part of Moodle - http://moodle.org/","//","// Moodle is free software: you can redistribute it and/or modify","// it under the terms of the GNU General Public License as published by","// the Free Software Foundation, either version 3 of the License, or","// (at your option) any later version.","//","// Moodle is distributed in the hope that it will be useful,","// but WITHOUT ANY WARRANTY; without even the implied warranty of","// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the","// GNU General Public License for more details.","//","// You should have received a copy of the GNU General Public License","// along with Moodle. If not, see .","","/**"," * @package atto_multilang2"," * @copyright 2015 onwards Julen Pardo & Mondragon Unibertsitatea"," * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later"," */","","/**"," * @module moodle-atto_multilang2-button"," */","","var CLASSES = {"," TAG: 'filter-multilang-tag'"," },",""," LANG_WILDCARD = '%lang',"," CONTENT_WILDCARD = '%content',"," ATTR_LANGUAGES = 'languages',"," ATTR_CAPABILITY = 'capability',"," ATTR_HIGHLIGHT = 'highlight',"," ATTR_CSS = 'css',"," DEFAULT_LANGUAGE = '{\"en\":\"English (en)\"}',"," DEFAULT_CAPABILITY = true,"," DEFAULT_HIGHLIGHT = true,"," DEFAULT_CSS = 'outline: 1px dotted;' +"," 'padding: 0.1em;' +"," 'margin: 0em 0.1em;' +"," 'background-color: #ffffaa;',"," TEMPLATES = {"," SPANED: ' {mlang ' + LANG_WILDCARD + '}' +"," CONTENT_WILDCARD +"," '{mlang} ',",""," NOT_SPANED: '{mlang ' + LANG_WILDCARD + '}' + CONTENT_WILDCARD + '{mlang}'"," },"," OPENING_SPAN = '';","","/**"," * Atto text editor multilanguage plugin."," *"," * @namespace M.atto_multilang2"," * @class button"," * @extends M.editor_atto.EditorPlugin"," */","","Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {",""," /**"," * If the {mlang} tags have to be highlighted or not. Received as parameter from lib.php."," *"," * @property _highlight"," * @type boolean"," * @private"," */"," _highlight: true,",""," _auxiliarSubmitButtonNode: null,",""," initializer: function() {"," var hascapability = this.get(ATTR_CAPABILITY),"," toolbarItems = [];",""," if (hascapability) {"," toolbarItems = this._initializeToolbarItems();"," this._highlight = this.get(ATTR_HIGHLIGHT);",""," this.addToolbarMenu({"," globalItemConfig: {"," callback: this._addTags"," },"," icon: 'icon',"," iconComponent: 'atto_multilang2',"," items: toolbarItems"," });",""," this.get('host').on('atto:selectionchanged', this._checkSelectionChange, this);",""," this._addDelimiterCss();",""," if (this._highlight) {"," this._decorateTagsOnInit();"," this._setSubmitListeners();"," }"," }"," },",""," /**"," * Adds the CSS rules for the delimiters, received as parameter from lib.php."," *"," * @method _addDelimiterCss"," * @private"," */"," _addDelimiterCss: function() {"," var css = '.' + CLASSES.TAG + '{' + this.get(ATTR_CSS) + '}',"," style;",""," style = document.createElement('style');"," style.type = 'text/css';"," style.innerHTML = css;",""," document.head.appendChild(style);"," },",""," /**"," * Initializes the toolbar items, which will be the installed languages,"," * received as parameter."," *"," * @method _initializeToolbarItems"," * @private"," * @return {Array} installed language strings"," */"," _initializeToolbarItems: function() {"," var toolbarItems = [],"," languages,"," langCode;",""," languages = JSON.parse(this.get(ATTR_LANGUAGES));",""," for (langCode in languages) {"," if (languages.hasOwnProperty(langCode)) {"," toolbarItems.push({"," text: languages[langCode],"," callbackArgs: langCode"," });"," }"," }",""," return toolbarItems;"," },",""," /**"," * Retrieves the selected text, wraps it with the multilang tags,"," * and replaces the selected text in the editor with with it."," *"," * If the 'highlight' setting is checked, the {mlang} will be wrapped between"," * the tags with the class for the CSS highlight; if not, they will not"," * be wrapped."," *"," * If there is no content selected, a \" \" will be inserted; otherwhise,"," * it's impossible to place the cursor inside the {mlang} tags."," *"," * @method _addTags"," * @param {EventFacade} e"," * @param {string} langCode the language code"," * @private"," */"," _addTags: function(e, langCode) {"," var selection,"," host = this.get('host'),"," taggedContent,"," content;",""," taggedContent = (this._highlight) ? TEMPLATES.SPANED : TEMPLATES.NOT_SPANED;",""," selection = this._getSelectionHTML();"," content = (host.getSelection().toString().length === 0) ? ' ' : selection;",""," taggedContent = taggedContent.replace(LANG_WILDCARD, langCode);"," taggedContent = taggedContent.replace(CONTENT_WILDCARD, content);",""," host.insertContentAtFocusPoint(taggedContent);",""," this.markUpdated();"," },",""," /**"," * Retrieves selected text with its HTML."," * Took from: http://stackoverflow.com/questions/4176923/html-of-selected-text/4177234#4177234"," *"," * @method _getSelectionHTML"," * @private"," * @return {string} selected text's html; empty if nothing selected"," */"," _getSelectionHTML: function() {"," var html = '',"," selection,"," container,"," index,"," lenght;",""," if (typeof window.getSelection !== 'undefined') {"," selection = window.getSelection();",""," if (selection.rangeCount) {"," container = document.createElement('div');"," for (index = 0, lenght = selection.rangeCount; index < lenght; ++index) {"," container.appendChild(selection.getRangeAt(index).cloneContents());"," }"," html = container.innerHTML;"," }",""," } else if (typeof document.selection !== 'undefined') {"," if (document.selection.type === 'Text') {"," html = document.selection.createRange().htmlText;"," }"," }",""," return html;"," },",""," /**"," * Listens to every change of the text cursor in the text area. If the"," * cursor is placed within a multilang tag, the whole tag is selected."," *"," * @method _checkSelectionChange"," * @private"," */"," _checkSelectionChange: function() {"," var host = this.get('host'),"," node = host.getSelectionParentNode(),"," nodeValue = Y.one(node).get('text'),"," isTextNode,"," isLangTag;",""," isTextNode = Y.one(node).toString().indexOf('#text') > - 1;"," isLangTag = (nodeValue.match(/\\{mlang/g).length === 1);",""," if (isTextNode && isLangTag) {"," host.setSelection(host.getSelectionFromNode(Y.one(node)));"," }"," },",""," /**"," * Sets the submit listener to the function that finds the spaned {mlang} tags."," *"," * In some forms, there may be two different submit buttons, so we add the listener"," * to the second, if this exists."," *"," * These submit listeners are set only if the \"highlight\" plugin setting is checked."," *"," * @method _setSubmitListener"," * @private"," */"," _setSubmitListeners: function() {"," var submitButtons = Y.all('input[type=submit]');",""," submitButtons.each(this._addListenerToSubmitButtons, this);"," },",""," _addListenerToSubmitButtons: function(buttonNode) {"," var buttonObject,"," className,"," parentFormClassName,"," notCancelButton,"," notSearchButton;",""," buttonObject = document.getElementById(buttonNode.get('id'));",""," if (buttonObject !== null) {"," className = buttonObject.className;"," parentFormClassName = buttonObject.form.className;",""," notCancelButton = className.match(/btn-cancel/g) === null;"," notSearchButton = parentFormClassName.match(/mform/g).length > 0;",""," if (notCancelButton && notSearchButton) {"," this._auxiliarSubmitButtonNode = buttonNode;"," buttonNode.on('click', this._cleanTagsOnSubmit, this);"," }"," }"," },",""," _cleanTagsOnSubmit: function(e) {"," var submitButton;",""," e.preventDefault();",""," submitButton = Y.one(this._auxiliarSubmitButtonNode);",""," this._cleanTagsWithNoYuiId();"," this._cleanTagsWithYuiId();",""," submitButton.detach('click', this._cleanTagsOnSubmit);"," submitButton.simulate('click');"," },",""," /**"," * Cleans the tags around the {mlang} tags when the form is submitted,"," * that do not have \"id\" attribute."," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * There may be more than one atto editor textarea in the page. So, we have to retrieve"," * the textareas by the class name. If there is only one, the object will be only the"," * reference, but, if there are more, we will have an array. So, the easiest way is to"," * check if what we have is an array, and if it not, create it manually, and iterate it"," * later."," *"," * issue #15: the textareas are now retrieved passing to YUI selector the whole element,"," * instead of the id string, due to problems with special characters."," * See discussion: https://moodle.org/mod/forum/discuss.php?d=332217"," *"," * @method _cleanTagsWithNoYuiId"," * @private"," */"," _cleanTagsWithNoYuiId: function() {"," var textareas = Y.all('.editor_atto_content'),"," textarea,"," textareaIndex,"," innerHTML,"," spanedmlangtags,"," spanedmlangtag,"," index,"," cleanmlangtag,"," regularExpression;",""," regularExpression = new RegExp(OPENING_SPAN + '.*?' + '', 'g');",""," if (!textareas instanceof Array) {"," textarea = textareas;"," textareas = [];"," textareas[0] = textarea;"," }",""," for (textareaIndex = 0; textareaIndex < textareas._nodes.length; textareaIndex++) {"," textarea = textareas._nodes[textareaIndex].id;"," textarea = Y.one(document.getElementById(textarea));",""," innerHTML = textarea.get('innerHTML');",""," spanedmlangtags = innerHTML.match(regularExpression);",""," if (spanedmlangtags === null) {"," continue;"," }"," "," for (index = 0; index < spanedmlangtags.length; index++) {"," spanedmlangtag = spanedmlangtags[index];"," cleanmlangtag = spanedmlangtag.replace(OPENING_SPAN, '');",""," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }",""," textarea.set('innerHTML', innerHTML);"," }",""," this.markUpdated();"," },",""," /**"," * Cleans the tags around the {mlang} tags when the form is submitted,"," * that have \"id\" attribute, generated by YUI, when the cursor is placed on the tags."," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * There may be more than one atto editor textarea in the page. So, we have to retrieve"," * the textareas by the class name. If there is only one, the object will be only the"," * reference, but, if there are more, we will have an array. So, the easiest way is to"," * check if what we have is an array, and if it not, create it manually, and iterate it"," * later."," *"," * issue #15: the textareas are now retrieved passing to YUI selector the whole element,"," * instead of the id string, due to problems with special characters."," * See discussion: https://moodle.org/mod/forum/discuss.php?d=332217"," *"," * @method anTagsWithYuiId"," * @private"," */"," _cleanTagsWithYuiId: function() {"," var textareas = Y.all('.editor_atto_content'),"," textarea,"," textareaIndex,"," innerHTML,"," spanedmlangtag,"," index,"," cleanmlangtag,"," regularExpression,"," openingspanwithyui,"," spanedmlangtagsdwithyui,"," mlangtag;",""," openingspanwithyui = OPENING_SPAN.replace('', 'g');",""," if (!textareas instanceof Array) {"," textarea = textareas;"," textareas = [];"," textareas[0] = textarea;"," }"," "," for (textareaIndex = 0; textareaIndex < textareas._nodes.length; textareaIndex++) {"," textarea = textareas._nodes[textareaIndex].id;"," textarea = Y.one(document.getElementById(textarea));",""," innerHTML = textarea.get('innerHTML');",""," spanedmlangtagsdwithyui = innerHTML.match(regularExpression);",""," if (spanedmlangtagsdwithyui === null) {"," continue;"," }"," "," for (index = 0; index < spanedmlangtagsdwithyui.length; index++) {"," spanedmlangtag = spanedmlangtagsdwithyui[index];"," mlangtag = spanedmlangtag.match(/\\{mlang.*?\\}/g)[0];",""," cleanmlangtag = spanedmlangtag.replace(regularExpression, mlangtag);"," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }",""," textarea.set('innerHTML', innerHTML);",""," this.markUpdated();"," }"," },",""," /**"," * Adds the tags to the {mlang} tags when the editor is loaded."," * In this case, we DON'T HAVE TO CALL TO markUpdated(). Why? Honestly,"," * I don't know. But, if we call it after setting the HTML, the {mlang}"," * tags flicker with the decoration, and returns to their original state."," *"," * Instead of taking the HTML directly from the textarea, we have to"," * retrieve it, first, without the tags that can be stored"," * in database, due to a bug in version 2015120501 that stores the"," * {mlang} tags in database, with the tags."," * More info about this bug: https://github.com/julenpardo/moodle-atto_multilang2/issues/8"," *"," * Every different {mlang} tag has to be replaced only once, otherwise,"," * nested s will be created in every repeated replacement. So, we"," * have to have a track of which replacements have been made."," *"," * @method _decorateTagsOnInit"," * @private"," */"," _decorateTagsOnInit: function() {"," var textarea = Y.all('.editor_atto_content'),"," innerHTML,"," regularExpression,"," mlangtags,"," mlangtag,"," index,"," decoratedmlangtag,"," replacementsmade = [],"," notreplacedyet;",""," innerHTML = this._getHTMLwithCleanedTags();",""," regularExpression = new RegExp('{mlang.*?}', 'g');"," mlangtags = innerHTML.match(regularExpression);",""," if (mlangtags !== null) {"," for (index = 0; index < mlangtags.length; index++) {"," mlangtag = mlangtags[index];",""," notreplacedyet = replacementsmade.indexOf(mlangtag) === -1;",""," if (notreplacedyet) {"," replacementsmade.push(mlangtag);",""," decoratedmlangtag = OPENING_SPAN + mlangtag + '';"," regularExpression = new RegExp(mlangtag, 'g');",""," innerHTML = innerHTML.replace(regularExpression, decoratedmlangtag);"," }"," }",""," textarea.set('innerHTML', innerHTML);"," }",""," },",""," /**"," * This function returns the HTML as it is in the textarea, but cleaning every"," * tag around the {mlang} tags. This is necessary for decorating tags on"," * init, because it could happen that in database are stored the {mlang} tags with"," * their tags, due to a bug in version 2015120501."," * More info about this bug: https://github.com/julenpardo/moodle-atto_multilang2/issues/8"," *"," * @method _getHTMLwithCleanedTags"," * @return {string} HTML in textarea, without any around {mlang} tags"," */"," _getHTMLwithCleanedTags: function() {"," var host = this.get('host'),"," innerHTML = host.getCleanHTML(),"," regexString,"," regularExpression,"," spanedmlangtags,"," spanedmlangtag,"," cleanmlangtag,"," index;",""," regexString = OPENING_SPAN + '.*?' + '';"," regularExpression = new RegExp(regexString, 'g');"," spanedmlangtags = innerHTML.match(regularExpression);",""," if (spanedmlangtags !== null) {"," for (index = 0; index < spanedmlangtags.length; index++) {"," spanedmlangtag = spanedmlangtags[index];",""," cleanmlangtag = spanedmlangtag.replace(OPENING_SPAN, '');"," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }"," }",""," return innerHTML;"," }","","}, {"," ATTRS: {"," /**"," * The list of installed languages."," *"," * @attribute languages"," * @type array"," * @default {\"en\":\"English (en)\"}"," */"," languages: DEFAULT_LANGUAGE,",""," /**"," * If the current user has the capability to use the plugin."," *"," * @attribute capability"," * @type boolean"," * @default true"," */"," capability: DEFAULT_CAPABILITY,",""," /**"," * If the {mlang} tags have to be highlighted or not."," *"," * @property highlight"," * @type boolean"," * @default true"," */"," highlight: DEFAULT_HIGHLIGHT,",""," /**"," * The CSS for delimiters."," *"," * @property css"," * @type string"," * @default DEFAULT_CSS"," */"," css: DEFAULT_CSS"," }","});","","","}, '@VERSION@', {\"requires\": [\"moodle-editor_atto-plugin\"]});","","}());"]}; } var __cov_xlcucJyua6odXhLRctX6xg = __coverage__['build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js']; -__cov_xlcucJyua6odXhLRctX6xg.s['1']++;YUI.add('moodle-atto_multilang2-button',function(Y,NAME){__cov_xlcucJyua6odXhLRctX6xg.f['1']++;__cov_xlcucJyua6odXhLRctX6xg.s['2']++;var CLASSES={TAG:'filter-multilang-tag'},LANG_WILDCARD='%lang',CONTENT_WILDCARD='%content',ATTR_LANGUAGES='languages',ATTR_CAPABILITY='capability',ATTR_HIGHLIGHT='highlight',ATTR_CSS='css',DEFAULT_LANGUAGE='{"en":"English (en)"}',DEFAULT_CAPABILITY=true,DEFAULT_HIGHLIGHT=true,DEFAULT_CSS='outline: 1px dotted;'+'padding: 0.1em;'+'margin: 0em 0.1em;'+'background-color: #ffffaa;',TEMPLATES={SPANED:' {mlang '+LANG_WILDCARD+'}'+CONTENT_WILDCARD+'{mlang} ',NOT_SPANED:'{mlang '+LANG_WILDCARD+'}'+CONTENT_WILDCARD+'{mlang}'},OPENING_SPAN='';__cov_xlcucJyua6odXhLRctX6xg.s['3']++;Y.namespace('M.atto_multilang2').Button=Y.Base.create('button',Y.M.editor_atto.EditorPlugin,[],{_highlight:true,initializer:function(){__cov_xlcucJyua6odXhLRctX6xg.f['2']++;__cov_xlcucJyua6odXhLRctX6xg.s['4']++;var hascapability=this.get(ATTR_CAPABILITY),toolbarItems=[];__cov_xlcucJyua6odXhLRctX6xg.s['5']++;if(hascapability){__cov_xlcucJyua6odXhLRctX6xg.b['1'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['6']++;toolbarItems=this._initializeToolbarItems();__cov_xlcucJyua6odXhLRctX6xg.s['7']++;this._highlight=this.get(ATTR_HIGHLIGHT);__cov_xlcucJyua6odXhLRctX6xg.s['8']++;this.addToolbarMenu({globalItemConfig:{callback:this._addTags},icon:'icon',iconComponent:'atto_multilang2',items:toolbarItems});__cov_xlcucJyua6odXhLRctX6xg.s['9']++;this.get('host').on('atto:selectionchanged',this._checkSelectionChange,this);__cov_xlcucJyua6odXhLRctX6xg.s['10']++;this._addDelimiterCss();__cov_xlcucJyua6odXhLRctX6xg.s['11']++;if(this._highlight){__cov_xlcucJyua6odXhLRctX6xg.b['2'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['12']++;this._decorateTagsOnInit();__cov_xlcucJyua6odXhLRctX6xg.s['13']++;this._setSubmitListeners();}else{__cov_xlcucJyua6odXhLRctX6xg.b['2'][1]++;}}else{__cov_xlcucJyua6odXhLRctX6xg.b['1'][1]++;}},_addDelimiterCss:function(){__cov_xlcucJyua6odXhLRctX6xg.f['3']++;__cov_xlcucJyua6odXhLRctX6xg.s['14']++;var css='.'+CLASSES.TAG+'{'+this.get(ATTR_CSS)+'}',style;__cov_xlcucJyua6odXhLRctX6xg.s['15']++;style=document.createElement('style');__cov_xlcucJyua6odXhLRctX6xg.s['16']++;style.type='text/css';__cov_xlcucJyua6odXhLRctX6xg.s['17']++;style.innerHTML=css;__cov_xlcucJyua6odXhLRctX6xg.s['18']++;document.head.appendChild(style);},_initializeToolbarItems:function(){__cov_xlcucJyua6odXhLRctX6xg.f['4']++;__cov_xlcucJyua6odXhLRctX6xg.s['19']++;var toolbarItems=[],languages,langCode;__cov_xlcucJyua6odXhLRctX6xg.s['20']++;languages=JSON.parse(this.get(ATTR_LANGUAGES));__cov_xlcucJyua6odXhLRctX6xg.s['21']++;for(langCode in languages){__cov_xlcucJyua6odXhLRctX6xg.s['22']++;if(languages.hasOwnProperty(langCode)){__cov_xlcucJyua6odXhLRctX6xg.b['3'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['23']++;toolbarItems.push({text:languages[langCode],callbackArgs:langCode});}else{__cov_xlcucJyua6odXhLRctX6xg.b['3'][1]++;}}__cov_xlcucJyua6odXhLRctX6xg.s['24']++;return toolbarItems;},_addTags:function(e,langCode){__cov_xlcucJyua6odXhLRctX6xg.f['5']++;__cov_xlcucJyua6odXhLRctX6xg.s['25']++;var selection,host=this.get('host'),taggedContent,content;__cov_xlcucJyua6odXhLRctX6xg.s['26']++;taggedContent=this._highlight?(__cov_xlcucJyua6odXhLRctX6xg.b['4'][0]++,TEMPLATES.SPANED):(__cov_xlcucJyua6odXhLRctX6xg.b['4'][1]++,TEMPLATES.NOT_SPANED);__cov_xlcucJyua6odXhLRctX6xg.s['27']++;selection=this._getSelectionHTML();__cov_xlcucJyua6odXhLRctX6xg.s['28']++;content=host.getSelection().toString().length===0?(__cov_xlcucJyua6odXhLRctX6xg.b['5'][0]++,' '):(__cov_xlcucJyua6odXhLRctX6xg.b['5'][1]++,selection);__cov_xlcucJyua6odXhLRctX6xg.s['29']++;taggedContent=taggedContent.replace(LANG_WILDCARD,langCode);__cov_xlcucJyua6odXhLRctX6xg.s['30']++;taggedContent=taggedContent.replace(CONTENT_WILDCARD,content);__cov_xlcucJyua6odXhLRctX6xg.s['31']++;host.insertContentAtFocusPoint(taggedContent);__cov_xlcucJyua6odXhLRctX6xg.s['32']++;this.markUpdated();},_getSelectionHTML:function(){__cov_xlcucJyua6odXhLRctX6xg.f['6']++;__cov_xlcucJyua6odXhLRctX6xg.s['33']++;var html='',selection,container,index,lenght;__cov_xlcucJyua6odXhLRctX6xg.s['34']++;if(typeof window.getSelection!=='undefined'){__cov_xlcucJyua6odXhLRctX6xg.b['6'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['35']++;selection=window.getSelection();__cov_xlcucJyua6odXhLRctX6xg.s['36']++;if(selection.rangeCount){__cov_xlcucJyua6odXhLRctX6xg.b['7'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['37']++;container=document.createElement('div');__cov_xlcucJyua6odXhLRctX6xg.s['38']++;for(index=0,lenght=selection.rangeCount;index-1;__cov_xlcucJyua6odXhLRctX6xg.s['47']++;isLangTag=nodeValue.match(/\{mlang/g).length===1;__cov_xlcucJyua6odXhLRctX6xg.s['48']++;if((__cov_xlcucJyua6odXhLRctX6xg.b['11'][0]++,isTextNode)&&(__cov_xlcucJyua6odXhLRctX6xg.b['11'][1]++,isLangTag)){__cov_xlcucJyua6odXhLRctX6xg.b['10'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['49']++;host.setSelection(host.getSelectionFromNode(Y.one(node)));}else{__cov_xlcucJyua6odXhLRctX6xg.b['10'][1]++;}},_setSubmitListeners:function(){__cov_xlcucJyua6odXhLRctX6xg.f['8']++;__cov_xlcucJyua6odXhLRctX6xg.s['50']++;var submitbutton=Y.one('#id_submitbutton'),submitbutton2=Y.one('#id_submitbutton2');__cov_xlcucJyua6odXhLRctX6xg.s['51']++;submitbutton.on('click',this._cleanTagsOnSubmit,this);__cov_xlcucJyua6odXhLRctX6xg.s['52']++;if(submitbutton2!==null){__cov_xlcucJyua6odXhLRctX6xg.b['12'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['53']++;submitbutton2.on('click',this._cleanTagsOnSubmitSecondButton,this);}else{__cov_xlcucJyua6odXhLRctX6xg.b['12'][1]++;}},_cleanTagsOnSubmit:function(e){__cov_xlcucJyua6odXhLRctX6xg.f['9']++;__cov_xlcucJyua6odXhLRctX6xg.s['54']++;var submitbutton;__cov_xlcucJyua6odXhLRctX6xg.s['55']++;e.preventDefault();__cov_xlcucJyua6odXhLRctX6xg.s['56']++;submitbutton=Y.one('#id_submitbutton');__cov_xlcucJyua6odXhLRctX6xg.s['57']++;this._cleanTagsWithNoYuiId();__cov_xlcucJyua6odXhLRctX6xg.s['58']++;this._cleanTagsWithYuiId();__cov_xlcucJyua6odXhLRctX6xg.s['59']++;submitbutton.detach('click',this._cleanTagsOnSubmit);__cov_xlcucJyua6odXhLRctX6xg.s['60']++;submitbutton.simulate('click');},_cleanTagsOnSubmitSecondButton:function(e){__cov_xlcucJyua6odXhLRctX6xg.f['10']++;__cov_xlcucJyua6odXhLRctX6xg.s['61']++;var submitbutton;__cov_xlcucJyua6odXhLRctX6xg.s['62']++;e.preventDefault();__cov_xlcucJyua6odXhLRctX6xg.s['63']++;submitbutton=Y.one('#id_submitbutton2');__cov_xlcucJyua6odXhLRctX6xg.s['64']++;this._cleanTagsWithNoYuiId();__cov_xlcucJyua6odXhLRctX6xg.s['65']++;this._cleanTagsWithYuiId();__cov_xlcucJyua6odXhLRctX6xg.s['66']++;submitbutton.detach('click',this._cleanTagsOnSubmitSecondButton);__cov_xlcucJyua6odXhLRctX6xg.s['67']++;submitbutton.simulate('click');},_cleanTagsWithNoYuiId:function(){__cov_xlcucJyua6odXhLRctX6xg.f['11']++;__cov_xlcucJyua6odXhLRctX6xg.s['68']++;var textareas=Y.all('.editor_atto_content'),textarea,textareaIndex,innerHTML,spanedmlangtags,spanedmlangtag,index,cleanmlangtag,regularExpression;__cov_xlcucJyua6odXhLRctX6xg.s['69']++;regularExpression=new RegExp(OPENING_SPAN+'.*?'+'','g');__cov_xlcucJyua6odXhLRctX6xg.s['70']++;if(!textareas instanceof Array){__cov_xlcucJyua6odXhLRctX6xg.b['13'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['71']++;textarea=textareas;__cov_xlcucJyua6odXhLRctX6xg.s['72']++;textareas=[];__cov_xlcucJyua6odXhLRctX6xg.s['73']++;textareas[0]=textarea;}else{__cov_xlcucJyua6odXhLRctX6xg.b['13'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['74']++;for(textareaIndex=0;textareaIndex','');__cov_xlcucJyua6odXhLRctX6xg.s['85']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}__cov_xlcucJyua6odXhLRctX6xg.s['86']++;textarea.set('innerHTML',innerHTML);}__cov_xlcucJyua6odXhLRctX6xg.s['87']++;this.markUpdated();},_cleanTagsWithYuiId:function(){__cov_xlcucJyua6odXhLRctX6xg.f['12']++;__cov_xlcucJyua6odXhLRctX6xg.s['88']++;var textareas=Y.all('.editor_atto_content'),textarea,textareaIndex,innerHTML,spanedmlangtag,index,cleanmlangtag,regularExpression,openingspanwithyui,spanedmlangtagsdwithyui,mlangtag;__cov_xlcucJyua6odXhLRctX6xg.s['89']++;openingspanwithyui=OPENING_SPAN.replace('','g');__cov_xlcucJyua6odXhLRctX6xg.s['91']++;if(!textareas instanceof Array){__cov_xlcucJyua6odXhLRctX6xg.b['15'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['92']++;textarea=textareas;__cov_xlcucJyua6odXhLRctX6xg.s['93']++;textareas=[];__cov_xlcucJyua6odXhLRctX6xg.s['94']++;textareas[0]=textarea;}else{__cov_xlcucJyua6odXhLRctX6xg.b['15'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['95']++;for(textareaIndex=0;textareaIndex','');__cov_xlcucJyua6odXhLRctX6xg.s['107']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}__cov_xlcucJyua6odXhLRctX6xg.s['108']++;textarea.set('innerHTML',innerHTML);__cov_xlcucJyua6odXhLRctX6xg.s['109']++;this.markUpdated();}},_decorateTagsOnInit:function(){__cov_xlcucJyua6odXhLRctX6xg.f['13']++;__cov_xlcucJyua6odXhLRctX6xg.s['110']++;var textarea=Y.all('.editor_atto_content'),innerHTML,regularExpression,mlangtags,mlangtag,index,decoratedmlangtag,replacementsmade=[],notreplacedyet;__cov_xlcucJyua6odXhLRctX6xg.s['111']++;innerHTML=this._getHTMLwithCleanedTags();__cov_xlcucJyua6odXhLRctX6xg.s['112']++;regularExpression=new RegExp('{mlang.*?}','g');__cov_xlcucJyua6odXhLRctX6xg.s['113']++;mlangtags=innerHTML.match(regularExpression);__cov_xlcucJyua6odXhLRctX6xg.s['114']++;if(mlangtags!==null){__cov_xlcucJyua6odXhLRctX6xg.b['17'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['115']++;for(index=0;index';__cov_xlcucJyua6odXhLRctX6xg.s['121']++;regularExpression=new RegExp(mlangtag,'g');__cov_xlcucJyua6odXhLRctX6xg.s['122']++;innerHTML=innerHTML.replace(regularExpression,decoratedmlangtag);}else{__cov_xlcucJyua6odXhLRctX6xg.b['18'][1]++;}}__cov_xlcucJyua6odXhLRctX6xg.s['123']++;textarea.set('innerHTML',innerHTML);}else{__cov_xlcucJyua6odXhLRctX6xg.b['17'][1]++;}},_getHTMLwithCleanedTags:function(){__cov_xlcucJyua6odXhLRctX6xg.f['14']++;__cov_xlcucJyua6odXhLRctX6xg.s['124']++;var host=this.get('host'),innerHTML=host.getCleanHTML(),regexString,regularExpression,spanedmlangtags,spanedmlangtag,cleanmlangtag,index;__cov_xlcucJyua6odXhLRctX6xg.s['125']++;regexString=OPENING_SPAN+'.*?'+'';__cov_xlcucJyua6odXhLRctX6xg.s['126']++;regularExpression=new RegExp(regexString,'g');__cov_xlcucJyua6odXhLRctX6xg.s['127']++;spanedmlangtags=innerHTML.match(regularExpression);__cov_xlcucJyua6odXhLRctX6xg.s['128']++;if(spanedmlangtags!==null){__cov_xlcucJyua6odXhLRctX6xg.b['19'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['129']++;for(index=0;index','');__cov_xlcucJyua6odXhLRctX6xg.s['133']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}}else{__cov_xlcucJyua6odXhLRctX6xg.b['19'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['134']++;return innerHTML;}},{ATTRS:{languages:DEFAULT_LANGUAGE,capability:DEFAULT_CAPABILITY,highlight:DEFAULT_HIGHLIGHT,css:DEFAULT_CSS}});},'@VERSION@',{'requires':['moodle-editor_atto-plugin']}); +__cov_xlcucJyua6odXhLRctX6xg.s['1']++;YUI.add('moodle-atto_multilang2-button',function(Y,NAME){__cov_xlcucJyua6odXhLRctX6xg.f['1']++;__cov_xlcucJyua6odXhLRctX6xg.s['2']++;var CLASSES={TAG:'filter-multilang-tag'},LANG_WILDCARD='%lang',CONTENT_WILDCARD='%content',ATTR_LANGUAGES='languages',ATTR_CAPABILITY='capability',ATTR_HIGHLIGHT='highlight',ATTR_CSS='css',DEFAULT_LANGUAGE='{"en":"English (en)"}',DEFAULT_CAPABILITY=true,DEFAULT_HIGHLIGHT=true,DEFAULT_CSS='outline: 1px dotted;'+'padding: 0.1em;'+'margin: 0em 0.1em;'+'background-color: #ffffaa;',TEMPLATES={SPANED:' {mlang '+LANG_WILDCARD+'}'+CONTENT_WILDCARD+'{mlang} ',NOT_SPANED:'{mlang '+LANG_WILDCARD+'}'+CONTENT_WILDCARD+'{mlang}'},OPENING_SPAN='';__cov_xlcucJyua6odXhLRctX6xg.s['3']++;Y.namespace('M.atto_multilang2').Button=Y.Base.create('button',Y.M.editor_atto.EditorPlugin,[],{_highlight:true,_auxiliarSubmitButtonNode:null,initializer:function(){__cov_xlcucJyua6odXhLRctX6xg.f['2']++;__cov_xlcucJyua6odXhLRctX6xg.s['4']++;var hascapability=this.get(ATTR_CAPABILITY),toolbarItems=[];__cov_xlcucJyua6odXhLRctX6xg.s['5']++;if(hascapability){__cov_xlcucJyua6odXhLRctX6xg.b['1'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['6']++;toolbarItems=this._initializeToolbarItems();__cov_xlcucJyua6odXhLRctX6xg.s['7']++;this._highlight=this.get(ATTR_HIGHLIGHT);__cov_xlcucJyua6odXhLRctX6xg.s['8']++;this.addToolbarMenu({globalItemConfig:{callback:this._addTags},icon:'icon',iconComponent:'atto_multilang2',items:toolbarItems});__cov_xlcucJyua6odXhLRctX6xg.s['9']++;this.get('host').on('atto:selectionchanged',this._checkSelectionChange,this);__cov_xlcucJyua6odXhLRctX6xg.s['10']++;this._addDelimiterCss();__cov_xlcucJyua6odXhLRctX6xg.s['11']++;if(this._highlight){__cov_xlcucJyua6odXhLRctX6xg.b['2'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['12']++;this._decorateTagsOnInit();__cov_xlcucJyua6odXhLRctX6xg.s['13']++;this._setSubmitListeners();}else{__cov_xlcucJyua6odXhLRctX6xg.b['2'][1]++;}}else{__cov_xlcucJyua6odXhLRctX6xg.b['1'][1]++;}},_addDelimiterCss:function(){__cov_xlcucJyua6odXhLRctX6xg.f['3']++;__cov_xlcucJyua6odXhLRctX6xg.s['14']++;var css='.'+CLASSES.TAG+'{'+this.get(ATTR_CSS)+'}',style;__cov_xlcucJyua6odXhLRctX6xg.s['15']++;style=document.createElement('style');__cov_xlcucJyua6odXhLRctX6xg.s['16']++;style.type='text/css';__cov_xlcucJyua6odXhLRctX6xg.s['17']++;style.innerHTML=css;__cov_xlcucJyua6odXhLRctX6xg.s['18']++;document.head.appendChild(style);},_initializeToolbarItems:function(){__cov_xlcucJyua6odXhLRctX6xg.f['4']++;__cov_xlcucJyua6odXhLRctX6xg.s['19']++;var toolbarItems=[],languages,langCode;__cov_xlcucJyua6odXhLRctX6xg.s['20']++;languages=JSON.parse(this.get(ATTR_LANGUAGES));__cov_xlcucJyua6odXhLRctX6xg.s['21']++;for(langCode in languages){__cov_xlcucJyua6odXhLRctX6xg.s['22']++;if(languages.hasOwnProperty(langCode)){__cov_xlcucJyua6odXhLRctX6xg.b['3'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['23']++;toolbarItems.push({text:languages[langCode],callbackArgs:langCode});}else{__cov_xlcucJyua6odXhLRctX6xg.b['3'][1]++;}}__cov_xlcucJyua6odXhLRctX6xg.s['24']++;return toolbarItems;},_addTags:function(e,langCode){__cov_xlcucJyua6odXhLRctX6xg.f['5']++;__cov_xlcucJyua6odXhLRctX6xg.s['25']++;var selection,host=this.get('host'),taggedContent,content;__cov_xlcucJyua6odXhLRctX6xg.s['26']++;taggedContent=this._highlight?(__cov_xlcucJyua6odXhLRctX6xg.b['4'][0]++,TEMPLATES.SPANED):(__cov_xlcucJyua6odXhLRctX6xg.b['4'][1]++,TEMPLATES.NOT_SPANED);__cov_xlcucJyua6odXhLRctX6xg.s['27']++;selection=this._getSelectionHTML();__cov_xlcucJyua6odXhLRctX6xg.s['28']++;content=host.getSelection().toString().length===0?(__cov_xlcucJyua6odXhLRctX6xg.b['5'][0]++,' '):(__cov_xlcucJyua6odXhLRctX6xg.b['5'][1]++,selection);__cov_xlcucJyua6odXhLRctX6xg.s['29']++;taggedContent=taggedContent.replace(LANG_WILDCARD,langCode);__cov_xlcucJyua6odXhLRctX6xg.s['30']++;taggedContent=taggedContent.replace(CONTENT_WILDCARD,content);__cov_xlcucJyua6odXhLRctX6xg.s['31']++;host.insertContentAtFocusPoint(taggedContent);__cov_xlcucJyua6odXhLRctX6xg.s['32']++;this.markUpdated();},_getSelectionHTML:function(){__cov_xlcucJyua6odXhLRctX6xg.f['6']++;__cov_xlcucJyua6odXhLRctX6xg.s['33']++;var html='',selection,container,index,lenght;__cov_xlcucJyua6odXhLRctX6xg.s['34']++;if(typeof window.getSelection!=='undefined'){__cov_xlcucJyua6odXhLRctX6xg.b['6'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['35']++;selection=window.getSelection();__cov_xlcucJyua6odXhLRctX6xg.s['36']++;if(selection.rangeCount){__cov_xlcucJyua6odXhLRctX6xg.b['7'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['37']++;container=document.createElement('div');__cov_xlcucJyua6odXhLRctX6xg.s['38']++;for(index=0,lenght=selection.rangeCount;index-1;__cov_xlcucJyua6odXhLRctX6xg.s['47']++;isLangTag=nodeValue.match(/\{mlang/g).length===1;__cov_xlcucJyua6odXhLRctX6xg.s['48']++;if((__cov_xlcucJyua6odXhLRctX6xg.b['11'][0]++,isTextNode)&&(__cov_xlcucJyua6odXhLRctX6xg.b['11'][1]++,isLangTag)){__cov_xlcucJyua6odXhLRctX6xg.b['10'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['49']++;host.setSelection(host.getSelectionFromNode(Y.one(node)));}else{__cov_xlcucJyua6odXhLRctX6xg.b['10'][1]++;}},_setSubmitListeners:function(){__cov_xlcucJyua6odXhLRctX6xg.f['8']++;__cov_xlcucJyua6odXhLRctX6xg.s['50']++;var submitButtons=Y.all('input[type=submit]');__cov_xlcucJyua6odXhLRctX6xg.s['51']++;submitButtons.each(this._addListenerToSubmitButtons,this);},_addListenerToSubmitButtons:function(buttonNode){__cov_xlcucJyua6odXhLRctX6xg.f['9']++;__cov_xlcucJyua6odXhLRctX6xg.s['52']++;var buttonObject,className,parentFormClassName,notCancelButton,notSearchButton;__cov_xlcucJyua6odXhLRctX6xg.s['53']++;buttonObject=document.getElementById(buttonNode.get('id'));__cov_xlcucJyua6odXhLRctX6xg.s['54']++;if(buttonObject!==null){__cov_xlcucJyua6odXhLRctX6xg.b['12'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['55']++;className=buttonObject.className;__cov_xlcucJyua6odXhLRctX6xg.s['56']++;parentFormClassName=buttonObject.form.className;__cov_xlcucJyua6odXhLRctX6xg.s['57']++;notCancelButton=className.match(/btn-cancel/g)===null;__cov_xlcucJyua6odXhLRctX6xg.s['58']++;notSearchButton=parentFormClassName.match(/mform/g).length>0;__cov_xlcucJyua6odXhLRctX6xg.s['59']++;if((__cov_xlcucJyua6odXhLRctX6xg.b['14'][0]++,notCancelButton)&&(__cov_xlcucJyua6odXhLRctX6xg.b['14'][1]++,notSearchButton)){__cov_xlcucJyua6odXhLRctX6xg.b['13'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['60']++;this._auxiliarSubmitButtonNode=buttonNode;__cov_xlcucJyua6odXhLRctX6xg.s['61']++;buttonNode.on('click',this._cleanTagsOnSubmit,this);}else{__cov_xlcucJyua6odXhLRctX6xg.b['13'][1]++;}}else{__cov_xlcucJyua6odXhLRctX6xg.b['12'][1]++;}},_cleanTagsOnSubmit:function(e){__cov_xlcucJyua6odXhLRctX6xg.f['10']++;__cov_xlcucJyua6odXhLRctX6xg.s['62']++;var submitButton;__cov_xlcucJyua6odXhLRctX6xg.s['63']++;e.preventDefault();__cov_xlcucJyua6odXhLRctX6xg.s['64']++;submitButton=Y.one(this._auxiliarSubmitButtonNode);__cov_xlcucJyua6odXhLRctX6xg.s['65']++;this._cleanTagsWithNoYuiId();__cov_xlcucJyua6odXhLRctX6xg.s['66']++;this._cleanTagsWithYuiId();__cov_xlcucJyua6odXhLRctX6xg.s['67']++;submitButton.detach('click',this._cleanTagsOnSubmit);__cov_xlcucJyua6odXhLRctX6xg.s['68']++;submitButton.simulate('click');},_cleanTagsWithNoYuiId:function(){__cov_xlcucJyua6odXhLRctX6xg.f['11']++;__cov_xlcucJyua6odXhLRctX6xg.s['69']++;var textareas=Y.all('.editor_atto_content'),textarea,textareaIndex,innerHTML,spanedmlangtags,spanedmlangtag,index,cleanmlangtag,regularExpression;__cov_xlcucJyua6odXhLRctX6xg.s['70']++;regularExpression=new RegExp(OPENING_SPAN+'.*?'+'','g');__cov_xlcucJyua6odXhLRctX6xg.s['71']++;if(!textareas instanceof Array){__cov_xlcucJyua6odXhLRctX6xg.b['15'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['72']++;textarea=textareas;__cov_xlcucJyua6odXhLRctX6xg.s['73']++;textareas=[];__cov_xlcucJyua6odXhLRctX6xg.s['74']++;textareas[0]=textarea;}else{__cov_xlcucJyua6odXhLRctX6xg.b['15'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['75']++;for(textareaIndex=0;textareaIndex','');__cov_xlcucJyua6odXhLRctX6xg.s['86']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}__cov_xlcucJyua6odXhLRctX6xg.s['87']++;textarea.set('innerHTML',innerHTML);}__cov_xlcucJyua6odXhLRctX6xg.s['88']++;this.markUpdated();},_cleanTagsWithYuiId:function(){__cov_xlcucJyua6odXhLRctX6xg.f['12']++;__cov_xlcucJyua6odXhLRctX6xg.s['89']++;var textareas=Y.all('.editor_atto_content'),textarea,textareaIndex,innerHTML,spanedmlangtag,index,cleanmlangtag,regularExpression,openingspanwithyui,spanedmlangtagsdwithyui,mlangtag;__cov_xlcucJyua6odXhLRctX6xg.s['90']++;openingspanwithyui=OPENING_SPAN.replace('','g');__cov_xlcucJyua6odXhLRctX6xg.s['92']++;if(!textareas instanceof Array){__cov_xlcucJyua6odXhLRctX6xg.b['17'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['93']++;textarea=textareas;__cov_xlcucJyua6odXhLRctX6xg.s['94']++;textareas=[];__cov_xlcucJyua6odXhLRctX6xg.s['95']++;textareas[0]=textarea;}else{__cov_xlcucJyua6odXhLRctX6xg.b['17'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['96']++;for(textareaIndex=0;textareaIndex','');__cov_xlcucJyua6odXhLRctX6xg.s['108']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}__cov_xlcucJyua6odXhLRctX6xg.s['109']++;textarea.set('innerHTML',innerHTML);__cov_xlcucJyua6odXhLRctX6xg.s['110']++;this.markUpdated();}},_decorateTagsOnInit:function(){__cov_xlcucJyua6odXhLRctX6xg.f['13']++;__cov_xlcucJyua6odXhLRctX6xg.s['111']++;var textarea=Y.all('.editor_atto_content'),innerHTML,regularExpression,mlangtags,mlangtag,index,decoratedmlangtag,replacementsmade=[],notreplacedyet;__cov_xlcucJyua6odXhLRctX6xg.s['112']++;innerHTML=this._getHTMLwithCleanedTags();__cov_xlcucJyua6odXhLRctX6xg.s['113']++;regularExpression=new RegExp('{mlang.*?}','g');__cov_xlcucJyua6odXhLRctX6xg.s['114']++;mlangtags=innerHTML.match(regularExpression);__cov_xlcucJyua6odXhLRctX6xg.s['115']++;if(mlangtags!==null){__cov_xlcucJyua6odXhLRctX6xg.b['19'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['116']++;for(index=0;index';__cov_xlcucJyua6odXhLRctX6xg.s['122']++;regularExpression=new RegExp(mlangtag,'g');__cov_xlcucJyua6odXhLRctX6xg.s['123']++;innerHTML=innerHTML.replace(regularExpression,decoratedmlangtag);}else{__cov_xlcucJyua6odXhLRctX6xg.b['20'][1]++;}}__cov_xlcucJyua6odXhLRctX6xg.s['124']++;textarea.set('innerHTML',innerHTML);}else{__cov_xlcucJyua6odXhLRctX6xg.b['19'][1]++;}},_getHTMLwithCleanedTags:function(){__cov_xlcucJyua6odXhLRctX6xg.f['14']++;__cov_xlcucJyua6odXhLRctX6xg.s['125']++;var host=this.get('host'),innerHTML=host.getCleanHTML(),regexString,regularExpression,spanedmlangtags,spanedmlangtag,cleanmlangtag,index;__cov_xlcucJyua6odXhLRctX6xg.s['126']++;regexString=OPENING_SPAN+'.*?'+'';__cov_xlcucJyua6odXhLRctX6xg.s['127']++;regularExpression=new RegExp(regexString,'g');__cov_xlcucJyua6odXhLRctX6xg.s['128']++;spanedmlangtags=innerHTML.match(regularExpression);__cov_xlcucJyua6odXhLRctX6xg.s['129']++;if(spanedmlangtags!==null){__cov_xlcucJyua6odXhLRctX6xg.b['21'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['130']++;for(index=0;index','');__cov_xlcucJyua6odXhLRctX6xg.s['134']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}}else{__cov_xlcucJyua6odXhLRctX6xg.b['21'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['135']++;return innerHTML;}},{ATTRS:{languages:DEFAULT_LANGUAGE,capability:DEFAULT_CAPABILITY,highlight:DEFAULT_HIGHLIGHT,css:DEFAULT_CSS}});},'@VERSION@',{'requires':['moodle-editor_atto-plugin']}); diff --git a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-debug.js b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-debug.js index a4c0797..0aa97a3 100644 --- a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-debug.js +++ b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-debug.js @@ -70,6 +70,8 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att */ _highlight: true, + _auxiliarSubmitButtonNode: null, + initializer: function() { var hascapability = this.get(ATTR_CAPABILITY), toolbarItems = []; @@ -246,68 +248,46 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att * @private */ _setSubmitListeners: function() { - var submitbutton = Y.one('#id_submitbutton'), - submitbutton2 = Y.one('#id_submitbutton2'); - - submitbutton.on('click', this._cleanTagsOnSubmit, this); + var submitButtons = Y.all('input[type=submit]'); - if (submitbutton2 !== null) { - submitbutton2.on('click', this._cleanTagsOnSubmitSecondButton, this); - } + submitButtons.each(this._addListenerToSubmitButtons, this); }, - /** - * When submit button clicked, this function is invoked. It has to stop the submission, - * in order to process the textarea to clean the tags. - * - * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default, - * an then simulates the click, to submit the form. - * - * @method _cleanTagsOnSubmit - * @param {EventFacade} e - * @private - */ - _cleanTagsOnSubmit: function(e) { - var submitbutton; + _addListenerToSubmitButtons: function(buttonNode) { + var buttonObject, + className, + parentFormClassName, + notCancelButton, + notSearchButton; - e.preventDefault(); - - submitbutton = Y.one('#id_submitbutton'); + buttonObject = document.getElementById(buttonNode.get('id')); - this._cleanTagsWithNoYuiId(); - this._cleanTagsWithYuiId(); + if (buttonObject !== null) { + className = buttonObject.className; + parentFormClassName = buttonObject.form.className; + notCancelButton = className.match(/btn-cancel/g) === null; + notSearchButton = parentFormClassName.match(/mform/g).length > 0; - submitbutton.detach('click', this._cleanTagsOnSubmit); - submitbutton.simulate('click'); + if (notCancelButton && notSearchButton) { + this._auxiliarSubmitButtonNode = buttonNode; + buttonNode.on('click', this._cleanTagsOnSubmit, this); + } + } }, - /** - * When submit button clicked, this function is invoked. It has to stop the submission, - * in order to process the textarea to clean the tags. - * - * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default, - * an then simulates the click, to submit the form. - * - * The cleanup with "id" attribute and without it is made separately, to avoid an evil - * regular expression. - * - * @method _cleanTagsOnSubmit - * @param {EventFacade} e - * @private - */ - _cleanTagsOnSubmitSecondButton: function(e) { - var submitbutton; + _cleanTagsOnSubmit: function(e) { + var submitButton; e.preventDefault(); - submitbutton = Y.one('#id_submitbutton2'); + submitButton = Y.one(this._auxiliarSubmitButtonNode); this._cleanTagsWithNoYuiId(); this._cleanTagsWithYuiId(); - submitbutton.detach('click', this._cleanTagsOnSubmitSecondButton); - submitbutton.simulate('click'); + submitButton.detach('click', this._cleanTagsOnSubmit); + submitButton.simulate('click'); }, /** diff --git a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-min.js b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-min.js index 1fd970f..21e4a6c 100644 --- a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-min.js +++ b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-min.js @@ -1 +1 @@ -YUI.add("moodle-atto_multilang2-button",function(e,t){var n={TAG:"filter-multilang-tag"},r="%lang",i="%content",s="languages",o="capability",u="highlight",a="css",f='{"en":"English (en)"}',l=!0,c=!0,h="outline: 1px dotted;padding: 0.1em;margin: 0em 0.1em;background-color: #ffffaa;",p={SPANED:' {mlang '+r+"}"+i+'{mlang} ',NOT_SPANED:"{mlang "+r+"}"+i+"{mlang}"},d='';e.namespace("M.atto_multilang2").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_highlight:!0,initializer:function(){var e=this.get(o),t=[];e&&(t=this._initializeToolbarItems(),this._highlight=this.get(u),this.addToolbarMenu({globalItemConfig:{callback:this._addTags},icon:"icon",iconComponent:"atto_multilang2",items:t}),this.get("host").on("atto:selectionchanged",this._checkSelectionChange,this),this._addDelimiterCss(),this._highlight&&(this._decorateTagsOnInit(),this._setSubmitListeners()))},_addDelimiterCss:function(){var e="."+n.TAG+"{"+this.get(a)+"}",t;t=document.createElement("style"),t.type="text/css",t.innerHTML=e,document.head.appendChild(t)},_initializeToolbarItems:function(){var e=[],t,n;t=JSON.parse(this.get(s));for(n in t)t.hasOwnProperty(n)&&e.push({text:t[n],callbackArgs:n});return e},_addTags:function(e,t){var n,s=this.get("host"),o,u;o=this._highlight?p.SPANED:p.NOT_SPANED,n=this._getSelectionHTML(),u=s.getSelection().toString().length===0?" ":n,o=o.replace(r,t),o=o.replace(i,u),s.insertContentAtFocusPoint(o),this.markUpdated()},_getSelectionHTML:function(){var e="",t,n,r,i;if(typeof window.getSelection!="undefined"){t=window.getSelection();if(t.rangeCount){n=document.createElement("div");for(r=0,i=t.rangeCount;r-1,s=r.match(/\{mlang/g).length===1,i&&s&&t.setSelection(t.getSelectionFromNode(e.one(n)))},_setSubmitListeners:function(){var t=e.one("#id_submitbutton"),n=e.one("#id_submitbutton2");t.on("click",this._cleanTagsOnSubmit,this),n!==null&&n.on("click",this._cleanTagsOnSubmitSecondButton,this)},_cleanTagsOnSubmit:function(t){var n;t.preventDefault(),n=e.one("#id_submitbutton"),this._cleanTagsWithNoYuiId(),this._cleanTagsWithYuiId(),n.detach("click",this._cleanTagsOnSubmit),n.simulate("click")},_cleanTagsOnSubmitSecondButton:function(t){var n;t.preventDefault(),n=e.one("#id_submitbutton2"),this._cleanTagsWithNoYuiId(),this._cleanTagsWithYuiId(),n.detach("click",this._cleanTagsOnSubmitSecondButton),n.simulate("click")},_cleanTagsWithNoYuiId:function(){var t=e.all(".editor_atto_content"),n,r,i,s,o,u,a,f;f=new RegExp(d+".*?"+"","g"),!t instanceof Array&&(n=t,t=[],t[0]=n);for(r=0;r",""),i=i.replace(o,a);n.set("innerHTML",i)}this.markUpdated()},_cleanTagsWithYuiId:function(){var t=e.all(".editor_atto_content"),n,r,i,s,o,u,a,f,l,c;f=d.replace("","g"),!t instanceof Array&&(n=t,t=[],t[0]=n);for(r=0;r",""),i=i.replace(s,u);n.set("innerHTML",i),this.markUpdated()}},_decorateTagsOnInit:function(){var t=e.all(".editor_atto_content"),n,r,i,s,o,u,a=[],f;n=this._getHTMLwithCleanedTags(),r=new RegExp("{mlang.*?}","g"),i=n.match(r);if(i!==null){for(o=0;o",r=new RegExp(s,"g"),n=n.replace(r,u));t.set("innerHTML",n)}},_getHTMLwithCleanedTags:function(){var e=this.get("host"),t=e.getCleanHTML(),n,r,i,s,o,u;n=d+".*?"+"",r=new RegExp(n,"g"),i=t.match(r);if(i!==null)for(u=0;u",""),t=t.replace(s,o);return t}},{ATTRS:{languages:f,capability:l,highlight:c,css:h}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); +YUI.add("moodle-atto_multilang2-button",function(e,t){var n={TAG:"filter-multilang-tag"},r="%lang",i="%content",s="languages",o="capability",u="highlight",a="css",f='{"en":"English (en)"}',l=!0,c=!0,h="outline: 1px dotted;padding: 0.1em;margin: 0em 0.1em;background-color: #ffffaa;",p={SPANED:' {mlang '+r+"}"+i+'{mlang} ',NOT_SPANED:"{mlang "+r+"}"+i+"{mlang}"},d='';e.namespace("M.atto_multilang2").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_highlight:!0,_auxiliarSubmitButtonNode:null,initializer:function(){var e=this.get(o),t=[];e&&(t=this._initializeToolbarItems(),this._highlight=this.get(u),this.addToolbarMenu({globalItemConfig:{callback:this._addTags},icon:"icon",iconComponent:"atto_multilang2",items:t}),this.get("host").on("atto:selectionchanged",this._checkSelectionChange,this),this._addDelimiterCss(),this._highlight&&(this._decorateTagsOnInit(),this._setSubmitListeners()))},_addDelimiterCss:function(){var e="."+n.TAG+"{"+this.get(a)+"}",t;t=document.createElement("style"),t.type="text/css",t.innerHTML=e,document.head.appendChild(t)},_initializeToolbarItems:function(){var e=[],t,n;t=JSON.parse(this.get(s));for(n in t)t.hasOwnProperty(n)&&e.push({text:t[n],callbackArgs:n});return e},_addTags:function(e,t){var n,s=this.get("host"),o,u;o=this._highlight?p.SPANED:p.NOT_SPANED,n=this._getSelectionHTML(),u=s.getSelection().toString().length===0?" ":n,o=o.replace(r,t),o=o.replace(i,u),s.insertContentAtFocusPoint(o),this.markUpdated()},_getSelectionHTML:function(){var e="",t,n,r,i;if(typeof window.getSelection!="undefined"){t=window.getSelection();if(t.rangeCount){n=document.createElement("div");for(r=0,i=t.rangeCount;r-1,s=r.match(/\{mlang/g).length===1,i&&s&&t.setSelection(t.getSelectionFromNode(e.one(n)))},_setSubmitListeners:function(){var t=e.all("input[type=submit]");t.each(this._addListenerToSubmitButtons,this)},_addListenerToSubmitButtons:function(e){var t,n,r,i,s;t=document.getElementById(e.get("id")),t!==null&&(n=t.className,r=t.form.className,i=n.match(/btn-cancel/g)===null,s=r.match(/mform/g).length>0,i&&s&&(this._auxiliarSubmitButtonNode=e,e.on("click",this._cleanTagsOnSubmit,this)))},_cleanTagsOnSubmit:function(t){var n;t.preventDefault(),n=e.one(this._auxiliarSubmitButtonNode),this._cleanTagsWithNoYuiId(),this._cleanTagsWithYuiId(),n.detach("click",this._cleanTagsOnSubmit),n.simulate("click")},_cleanTagsWithNoYuiId:function(){var t=e.all(".editor_atto_content"),n,r,i,s,o,u,a,f;f=new RegExp(d+".*?"+"","g"),!t instanceof Array&&(n=t,t=[],t[0]=n);for(r=0;r",""),i=i.replace(o,a);n.set("innerHTML",i)}this.markUpdated()},_cleanTagsWithYuiId:function(){var t=e.all(".editor_atto_content"),n,r,i,s,o,u,a,f,l,c;f=d.replace("","g"),!t instanceof Array&&(n=t,t=[],t[0]=n);for(r=0;r",""),i=i.replace(s,u);n.set("innerHTML",i),this.markUpdated()}},_decorateTagsOnInit:function(){var t=e.all(".editor_atto_content"),n,r,i,s,o,u,a=[],f;n=this._getHTMLwithCleanedTags(),r=new RegExp("{mlang.*?}","g"),i=n.match(r);if(i!==null){for(o=0;o",r=new RegExp(s,"g"),n=n.replace(r,u));t.set("innerHTML",n)}},_getHTMLwithCleanedTags:function(){var e=this.get("host"),t=e.getCleanHTML(),n,r,i,s,o,u;n=d+".*?"+"",r=new RegExp(n,"g"),i=t.match(r);if(i!==null)for(u=0;u",""),t=t.replace(s,o);return t}},{ATTRS:{languages:f,capability:l,highlight:c,css:h}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); diff --git a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js index a4c0797..0aa97a3 100644 --- a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js +++ b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js @@ -70,6 +70,8 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att */ _highlight: true, + _auxiliarSubmitButtonNode: null, + initializer: function() { var hascapability = this.get(ATTR_CAPABILITY), toolbarItems = []; @@ -246,68 +248,46 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att * @private */ _setSubmitListeners: function() { - var submitbutton = Y.one('#id_submitbutton'), - submitbutton2 = Y.one('#id_submitbutton2'); - - submitbutton.on('click', this._cleanTagsOnSubmit, this); + var submitButtons = Y.all('input[type=submit]'); - if (submitbutton2 !== null) { - submitbutton2.on('click', this._cleanTagsOnSubmitSecondButton, this); - } + submitButtons.each(this._addListenerToSubmitButtons, this); }, - /** - * When submit button clicked, this function is invoked. It has to stop the submission, - * in order to process the textarea to clean the tags. - * - * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default, - * an then simulates the click, to submit the form. - * - * @method _cleanTagsOnSubmit - * @param {EventFacade} e - * @private - */ - _cleanTagsOnSubmit: function(e) { - var submitbutton; + _addListenerToSubmitButtons: function(buttonNode) { + var buttonObject, + className, + parentFormClassName, + notCancelButton, + notSearchButton; - e.preventDefault(); - - submitbutton = Y.one('#id_submitbutton'); + buttonObject = document.getElementById(buttonNode.get('id')); - this._cleanTagsWithNoYuiId(); - this._cleanTagsWithYuiId(); + if (buttonObject !== null) { + className = buttonObject.className; + parentFormClassName = buttonObject.form.className; + notCancelButton = className.match(/btn-cancel/g) === null; + notSearchButton = parentFormClassName.match(/mform/g).length > 0; - submitbutton.detach('click', this._cleanTagsOnSubmit); - submitbutton.simulate('click'); + if (notCancelButton && notSearchButton) { + this._auxiliarSubmitButtonNode = buttonNode; + buttonNode.on('click', this._cleanTagsOnSubmit, this); + } + } }, - /** - * When submit button clicked, this function is invoked. It has to stop the submission, - * in order to process the textarea to clean the tags. - * - * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default, - * an then simulates the click, to submit the form. - * - * The cleanup with "id" attribute and without it is made separately, to avoid an evil - * regular expression. - * - * @method _cleanTagsOnSubmit - * @param {EventFacade} e - * @private - */ - _cleanTagsOnSubmitSecondButton: function(e) { - var submitbutton; + _cleanTagsOnSubmit: function(e) { + var submitButton; e.preventDefault(); - submitbutton = Y.one('#id_submitbutton2'); + submitButton = Y.one(this._auxiliarSubmitButtonNode); this._cleanTagsWithNoYuiId(); this._cleanTagsWithYuiId(); - submitbutton.detach('click', this._cleanTagsOnSubmitSecondButton); - submitbutton.simulate('click'); + submitButton.detach('click', this._cleanTagsOnSubmit); + submitButton.simulate('click'); }, /** diff --git a/yui/src/button/js/button.js b/yui/src/button/js/button.js index dc4c5d7..c32506b 100644 --- a/yui/src/button/js/button.js +++ b/yui/src/button/js/button.js @@ -68,6 +68,8 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att */ _highlight: true, + _auxiliarSubmitButtonNode: null, + initializer: function() { var hascapability = this.get(ATTR_CAPABILITY), toolbarItems = []; @@ -244,68 +246,46 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att * @private */ _setSubmitListeners: function() { - var submitbutton = Y.one('#id_submitbutton'), - submitbutton2 = Y.one('#id_submitbutton2'); - - submitbutton.on('click', this._cleanTagsOnSubmit, this); + var submitButtons = Y.all('input[type=submit]'); - if (submitbutton2 !== null) { - submitbutton2.on('click', this._cleanTagsOnSubmitSecondButton, this); - } + submitButtons.each(this._addListenerToSubmitButtons, this); }, - /** - * When submit button clicked, this function is invoked. It has to stop the submission, - * in order to process the textarea to clean the tags. - * - * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default, - * an then simulates the click, to submit the form. - * - * @method _cleanTagsOnSubmit - * @param {EventFacade} e - * @private - */ - _cleanTagsOnSubmit: function(e) { - var submitbutton; + _addListenerToSubmitButtons: function(buttonNode) { + var buttonObject, + className, + parentFormClassName, + notCancelButton, + notSearchButton; - e.preventDefault(); - - submitbutton = Y.one('#id_submitbutton'); + buttonObject = document.getElementById(buttonNode.get('id')); - this._cleanTagsWithNoYuiId(); - this._cleanTagsWithYuiId(); + if (buttonObject !== null) { + className = buttonObject.className; + parentFormClassName = buttonObject.form.className; + notCancelButton = className.match(/btn-cancel/g) === null; + notSearchButton = parentFormClassName.match(/mform/g).length > 0; - submitbutton.detach('click', this._cleanTagsOnSubmit); - submitbutton.simulate('click'); + if (notCancelButton && notSearchButton) { + this._auxiliarSubmitButtonNode = buttonNode; + buttonNode.on('click', this._cleanTagsOnSubmit, this); + } + } }, - /** - * When submit button clicked, this function is invoked. It has to stop the submission, - * in order to process the textarea to clean the tags. - * - * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default, - * an then simulates the click, to submit the form. - * - * The cleanup with "id" attribute and without it is made separately, to avoid an evil - * regular expression. - * - * @method _cleanTagsOnSubmit - * @param {EventFacade} e - * @private - */ - _cleanTagsOnSubmitSecondButton: function(e) { - var submitbutton; + _cleanTagsOnSubmit: function(e) { + var submitButton; e.preventDefault(); - submitbutton = Y.one('#id_submitbutton2'); + submitButton = Y.one(this._auxiliarSubmitButtonNode); this._cleanTagsWithNoYuiId(); this._cleanTagsWithYuiId(); - submitbutton.detach('click', this._cleanTagsOnSubmitSecondButton); - submitbutton.simulate('click'); + submitButton.detach('click', this._cleanTagsOnSubmit); + submitButton.simulate('click'); }, /** From 3366156af9b4280394ed93de999f36b88e235c3b Mon Sep 17 00:00:00 2001 From: Julen Pardo Date: Wed, 25 May 2016 12:25:28 +0200 Subject: [PATCH 5/7] issue #17: add missing docblocks --- .../moodle-atto_multilang2-button-coverage.js | 2 +- .../moodle-atto_multilang2-button-debug.js | 45 ++++++++++++++++--- .../moodle-atto_multilang2-button.js | 45 ++++++++++++++++--- yui/src/button/js/button.js | 45 ++++++++++++++++--- 4 files changed, 115 insertions(+), 22 deletions(-) diff --git a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-coverage.js b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-coverage.js index c884c22..0a0e413 100644 --- a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-coverage.js +++ b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-coverage.js @@ -1,6 +1,6 @@ if (typeof __coverage__ === 'undefined') { __coverage__ = {}; } if (!__coverage__['build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js']) { - __coverage__['build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js'] = {"path":"build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0,"100":0,"101":0,"102":0,"103":0,"104":0,"105":0,"106":0,"107":0,"108":0,"109":0,"110":0,"111":0,"112":0,"113":0,"114":0,"115":0,"116":0,"117":0,"118":0,"119":0,"120":0,"121":0,"122":0,"123":0,"124":0,"125":0,"126":0,"127":0,"128":0,"129":0,"130":0,"131":0,"132":0,"133":0,"134":0,"135":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0],"14":[0,0],"15":[0,0],"16":[0,0],"17":[0,0],"18":[0,0],"19":[0,0],"20":[0,0],"21":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0},"fnMap":{"1":{"name":"(anonymous_1)","line":1,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":60}}},"2":{"name":"(anonymous_2)","line":75,"loc":{"start":{"line":75,"column":17},"end":{"line":75,"column":28}}},"3":{"name":"(anonymous_3)","line":109,"loc":{"start":{"line":109,"column":22},"end":{"line":109,"column":33}}},"4":{"name":"(anonymous_4)","line":128,"loc":{"start":{"line":128,"column":29},"end":{"line":128,"column":40}}},"5":{"name":"(anonymous_5)","line":163,"loc":{"start":{"line":163,"column":14},"end":{"line":163,"column":36}}},"6":{"name":"(anonymous_6)","line":190,"loc":{"start":{"line":190,"column":23},"end":{"line":190,"column":34}}},"7":{"name":"(anonymous_7)","line":224,"loc":{"start":{"line":224,"column":27},"end":{"line":224,"column":38}}},"8":{"name":"(anonymous_8)","line":250,"loc":{"start":{"line":250,"column":25},"end":{"line":250,"column":36}}},"9":{"name":"(anonymous_9)","line":256,"loc":{"start":{"line":256,"column":33},"end":{"line":256,"column":54}}},"10":{"name":"(anonymous_10)","line":279,"loc":{"start":{"line":279,"column":24},"end":{"line":279,"column":36}}},"11":{"name":"(anonymous_11)","line":312,"loc":{"start":{"line":312,"column":27},"end":{"line":312,"column":38}}},"12":{"name":"(anonymous_12)","line":377,"loc":{"start":{"line":377,"column":26},"end":{"line":377,"column":37}}},"13":{"name":"(anonymous_13)","line":446,"loc":{"start":{"line":446,"column":25},"end":{"line":446,"column":36}}},"14":{"name":"(anonymous_14)","line":493,"loc":{"start":{"line":493,"column":29},"end":{"line":493,"column":40}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":562,"column":61}},"2":{"start":{"line":28,"column":0},"end":{"line":52,"column":56}},"3":{"start":{"line":62,"column":0},"end":{"line":559,"column":3}},"4":{"start":{"line":76,"column":8},"end":{"line":77,"column":30}},"5":{"start":{"line":79,"column":8},"end":{"line":100,"column":9}},"6":{"start":{"line":80,"column":12},"end":{"line":80,"column":58}},"7":{"start":{"line":81,"column":12},"end":{"line":81,"column":55}},"8":{"start":{"line":83,"column":12},"end":{"line":90,"column":15}},"9":{"start":{"line":92,"column":12},"end":{"line":92,"column":91}},"10":{"start":{"line":94,"column":12},"end":{"line":94,"column":36}},"11":{"start":{"line":96,"column":12},"end":{"line":99,"column":13}},"12":{"start":{"line":97,"column":16},"end":{"line":97,"column":43}},"13":{"start":{"line":98,"column":16},"end":{"line":98,"column":43}},"14":{"start":{"line":110,"column":8},"end":{"line":111,"column":18}},"15":{"start":{"line":113,"column":8},"end":{"line":113,"column":48}},"16":{"start":{"line":114,"column":8},"end":{"line":114,"column":32}},"17":{"start":{"line":115,"column":8},"end":{"line":115,"column":30}},"18":{"start":{"line":117,"column":8},"end":{"line":117,"column":41}},"19":{"start":{"line":129,"column":8},"end":{"line":131,"column":21}},"20":{"start":{"line":133,"column":8},"end":{"line":133,"column":57}},"21":{"start":{"line":135,"column":8},"end":{"line":142,"column":9}},"22":{"start":{"line":136,"column":12},"end":{"line":141,"column":13}},"23":{"start":{"line":137,"column":16},"end":{"line":140,"column":19}},"24":{"start":{"line":144,"column":8},"end":{"line":144,"column":28}},"25":{"start":{"line":164,"column":8},"end":{"line":167,"column":20}},"26":{"start":{"line":169,"column":8},"end":{"line":169,"column":84}},"27":{"start":{"line":171,"column":8},"end":{"line":171,"column":45}},"28":{"start":{"line":172,"column":8},"end":{"line":172,"column":87}},"29":{"start":{"line":174,"column":8},"end":{"line":174,"column":71}},"30":{"start":{"line":175,"column":8},"end":{"line":175,"column":73}},"31":{"start":{"line":177,"column":8},"end":{"line":177,"column":54}},"32":{"start":{"line":179,"column":8},"end":{"line":179,"column":27}},"33":{"start":{"line":191,"column":8},"end":{"line":195,"column":19}},"34":{"start":{"line":197,"column":8},"end":{"line":212,"column":9}},"35":{"start":{"line":198,"column":12},"end":{"line":198,"column":46}},"36":{"start":{"line":200,"column":12},"end":{"line":206,"column":13}},"37":{"start":{"line":201,"column":16},"end":{"line":201,"column":58}},"38":{"start":{"line":202,"column":16},"end":{"line":204,"column":17}},"39":{"start":{"line":203,"column":20},"end":{"line":203,"column":87}},"40":{"start":{"line":205,"column":16},"end":{"line":205,"column":43}},"41":{"start":{"line":208,"column":15},"end":{"line":212,"column":9}},"42":{"start":{"line":209,"column":12},"end":{"line":211,"column":13}},"43":{"start":{"line":210,"column":16},"end":{"line":210,"column":65}},"44":{"start":{"line":214,"column":8},"end":{"line":214,"column":20}},"45":{"start":{"line":225,"column":8},"end":{"line":229,"column":22}},"46":{"start":{"line":231,"column":8},"end":{"line":231,"column":67}},"47":{"start":{"line":232,"column":8},"end":{"line":232,"column":63}},"48":{"start":{"line":234,"column":8},"end":{"line":236,"column":9}},"49":{"start":{"line":235,"column":12},"end":{"line":235,"column":70}},"50":{"start":{"line":251,"column":8},"end":{"line":251,"column":56}},"51":{"start":{"line":253,"column":8},"end":{"line":253,"column":67}},"52":{"start":{"line":257,"column":8},"end":{"line":261,"column":28}},"53":{"start":{"line":263,"column":8},"end":{"line":263,"column":69}},"54":{"start":{"line":265,"column":8},"end":{"line":276,"column":9}},"55":{"start":{"line":266,"column":12},"end":{"line":266,"column":47}},"56":{"start":{"line":267,"column":12},"end":{"line":267,"column":62}},"57":{"start":{"line":269,"column":12},"end":{"line":269,"column":70}},"58":{"start":{"line":270,"column":12},"end":{"line":270,"column":77}},"59":{"start":{"line":272,"column":12},"end":{"line":275,"column":13}},"60":{"start":{"line":273,"column":16},"end":{"line":273,"column":60}},"61":{"start":{"line":274,"column":16},"end":{"line":274,"column":70}},"62":{"start":{"line":280,"column":8},"end":{"line":280,"column":25}},"63":{"start":{"line":282,"column":8},"end":{"line":282,"column":27}},"64":{"start":{"line":284,"column":8},"end":{"line":284,"column":61}},"65":{"start":{"line":286,"column":8},"end":{"line":286,"column":37}},"66":{"start":{"line":287,"column":8},"end":{"line":287,"column":35}},"67":{"start":{"line":289,"column":8},"end":{"line":289,"column":62}},"68":{"start":{"line":290,"column":8},"end":{"line":290,"column":39}},"69":{"start":{"line":313,"column":8},"end":{"line":321,"column":30}},"70":{"start":{"line":323,"column":8},"end":{"line":323,"column":78}},"71":{"start":{"line":325,"column":8},"end":{"line":329,"column":9}},"72":{"start":{"line":326,"column":12},"end":{"line":326,"column":33}},"73":{"start":{"line":327,"column":12},"end":{"line":327,"column":27}},"74":{"start":{"line":328,"column":12},"end":{"line":328,"column":36}},"75":{"start":{"line":331,"column":8},"end":{"line":353,"column":9}},"76":{"start":{"line":332,"column":12},"end":{"line":332,"column":58}},"77":{"start":{"line":333,"column":12},"end":{"line":333,"column":64}},"78":{"start":{"line":335,"column":12},"end":{"line":335,"column":50}},"79":{"start":{"line":337,"column":12},"end":{"line":337,"column":65}},"80":{"start":{"line":339,"column":12},"end":{"line":341,"column":13}},"81":{"start":{"line":340,"column":16},"end":{"line":340,"column":25}},"82":{"start":{"line":343,"column":12},"end":{"line":350,"column":13}},"83":{"start":{"line":344,"column":16},"end":{"line":344,"column":56}},"84":{"start":{"line":345,"column":16},"end":{"line":345,"column":73}},"85":{"start":{"line":347,"column":16},"end":{"line":347,"column":69}},"86":{"start":{"line":349,"column":16},"end":{"line":349,"column":77}},"87":{"start":{"line":352,"column":12},"end":{"line":352,"column":49}},"88":{"start":{"line":355,"column":8},"end":{"line":355,"column":27}},"89":{"start":{"line":378,"column":8},"end":{"line":388,"column":21}},"90":{"start":{"line":390,"column":8},"end":{"line":390,"column":81}},"91":{"start":{"line":391,"column":8},"end":{"line":391,"column":89}},"92":{"start":{"line":393,"column":8},"end":{"line":397,"column":9}},"93":{"start":{"line":394,"column":12},"end":{"line":394,"column":33}},"94":{"start":{"line":395,"column":12},"end":{"line":395,"column":27}},"95":{"start":{"line":396,"column":12},"end":{"line":396,"column":36}},"96":{"start":{"line":399,"column":8},"end":{"line":424,"column":9}},"97":{"start":{"line":400,"column":12},"end":{"line":400,"column":58}},"98":{"start":{"line":401,"column":12},"end":{"line":401,"column":64}},"99":{"start":{"line":403,"column":12},"end":{"line":403,"column":50}},"100":{"start":{"line":405,"column":12},"end":{"line":405,"column":73}},"101":{"start":{"line":407,"column":12},"end":{"line":409,"column":13}},"102":{"start":{"line":408,"column":16},"end":{"line":408,"column":25}},"103":{"start":{"line":411,"column":12},"end":{"line":419,"column":13}},"104":{"start":{"line":412,"column":16},"end":{"line":412,"column":64}},"105":{"start":{"line":413,"column":16},"end":{"line":413,"column":68}},"106":{"start":{"line":415,"column":16},"end":{"line":415,"column":84}},"107":{"start":{"line":416,"column":16},"end":{"line":416,"column":69}},"108":{"start":{"line":418,"column":16},"end":{"line":418,"column":77}},"109":{"start":{"line":421,"column":12},"end":{"line":421,"column":49}},"110":{"start":{"line":423,"column":12},"end":{"line":423,"column":31}},"111":{"start":{"line":447,"column":8},"end":{"line":455,"column":27}},"112":{"start":{"line":457,"column":8},"end":{"line":457,"column":51}},"113":{"start":{"line":459,"column":8},"end":{"line":459,"column":58}},"114":{"start":{"line":460,"column":8},"end":{"line":460,"column":55}},"115":{"start":{"line":462,"column":8},"end":{"line":479,"column":9}},"116":{"start":{"line":463,"column":12},"end":{"line":476,"column":13}},"117":{"start":{"line":464,"column":16},"end":{"line":464,"column":44}},"118":{"start":{"line":466,"column":16},"end":{"line":466,"column":75}},"119":{"start":{"line":468,"column":16},"end":{"line":475,"column":17}},"120":{"start":{"line":469,"column":20},"end":{"line":469,"column":52}},"121":{"start":{"line":471,"column":20},"end":{"line":471,"column":76}},"122":{"start":{"line":472,"column":20},"end":{"line":472,"column":66}},"123":{"start":{"line":474,"column":20},"end":{"line":474,"column":88}},"124":{"start":{"line":478,"column":12},"end":{"line":478,"column":49}},"125":{"start":{"line":494,"column":8},"end":{"line":501,"column":18}},"126":{"start":{"line":503,"column":8},"end":{"line":503,"column":55}},"127":{"start":{"line":504,"column":8},"end":{"line":504,"column":57}},"128":{"start":{"line":505,"column":8},"end":{"line":505,"column":61}},"129":{"start":{"line":507,"column":8},"end":{"line":516,"column":9}},"130":{"start":{"line":508,"column":12},"end":{"line":515,"column":13}},"131":{"start":{"line":509,"column":16},"end":{"line":509,"column":56}},"132":{"start":{"line":511,"column":16},"end":{"line":511,"column":73}},"133":{"start":{"line":512,"column":16},"end":{"line":512,"column":69}},"134":{"start":{"line":514,"column":16},"end":{"line":514,"column":77}},"135":{"start":{"line":518,"column":8},"end":{"line":518,"column":25}}},"branchMap":{"1":{"line":79,"type":"if","locations":[{"start":{"line":79,"column":8},"end":{"line":79,"column":8}},{"start":{"line":79,"column":8},"end":{"line":79,"column":8}}]},"2":{"line":96,"type":"if","locations":[{"start":{"line":96,"column":12},"end":{"line":96,"column":12}},{"start":{"line":96,"column":12},"end":{"line":96,"column":12}}]},"3":{"line":136,"type":"if","locations":[{"start":{"line":136,"column":12},"end":{"line":136,"column":12}},{"start":{"line":136,"column":12},"end":{"line":136,"column":12}}]},"4":{"line":169,"type":"cond-expr","locations":[{"start":{"line":169,"column":44},"end":{"line":169,"column":60}},{"start":{"line":169,"column":63},"end":{"line":169,"column":83}}]},"5":{"line":172,"type":"cond-expr","locations":[{"start":{"line":172,"column":66},"end":{"line":172,"column":74}},{"start":{"line":172,"column":77},"end":{"line":172,"column":86}}]},"6":{"line":197,"type":"if","locations":[{"start":{"line":197,"column":8},"end":{"line":197,"column":8}},{"start":{"line":197,"column":8},"end":{"line":197,"column":8}}]},"7":{"line":200,"type":"if","locations":[{"start":{"line":200,"column":12},"end":{"line":200,"column":12}},{"start":{"line":200,"column":12},"end":{"line":200,"column":12}}]},"8":{"line":208,"type":"if","locations":[{"start":{"line":208,"column":15},"end":{"line":208,"column":15}},{"start":{"line":208,"column":15},"end":{"line":208,"column":15}}]},"9":{"line":209,"type":"if","locations":[{"start":{"line":209,"column":12},"end":{"line":209,"column":12}},{"start":{"line":209,"column":12},"end":{"line":209,"column":12}}]},"10":{"line":234,"type":"if","locations":[{"start":{"line":234,"column":8},"end":{"line":234,"column":8}},{"start":{"line":234,"column":8},"end":{"line":234,"column":8}}]},"11":{"line":234,"type":"binary-expr","locations":[{"start":{"line":234,"column":12},"end":{"line":234,"column":22}},{"start":{"line":234,"column":26},"end":{"line":234,"column":35}}]},"12":{"line":265,"type":"if","locations":[{"start":{"line":265,"column":8},"end":{"line":265,"column":8}},{"start":{"line":265,"column":8},"end":{"line":265,"column":8}}]},"13":{"line":272,"type":"if","locations":[{"start":{"line":272,"column":12},"end":{"line":272,"column":12}},{"start":{"line":272,"column":12},"end":{"line":272,"column":12}}]},"14":{"line":272,"type":"binary-expr","locations":[{"start":{"line":272,"column":16},"end":{"line":272,"column":31}},{"start":{"line":272,"column":35},"end":{"line":272,"column":50}}]},"15":{"line":325,"type":"if","locations":[{"start":{"line":325,"column":8},"end":{"line":325,"column":8}},{"start":{"line":325,"column":8},"end":{"line":325,"column":8}}]},"16":{"line":339,"type":"if","locations":[{"start":{"line":339,"column":12},"end":{"line":339,"column":12}},{"start":{"line":339,"column":12},"end":{"line":339,"column":12}}]},"17":{"line":393,"type":"if","locations":[{"start":{"line":393,"column":8},"end":{"line":393,"column":8}},{"start":{"line":393,"column":8},"end":{"line":393,"column":8}}]},"18":{"line":407,"type":"if","locations":[{"start":{"line":407,"column":12},"end":{"line":407,"column":12}},{"start":{"line":407,"column":12},"end":{"line":407,"column":12}}]},"19":{"line":462,"type":"if","locations":[{"start":{"line":462,"column":8},"end":{"line":462,"column":8}},{"start":{"line":462,"column":8},"end":{"line":462,"column":8}}]},"20":{"line":468,"type":"if","locations":[{"start":{"line":468,"column":16},"end":{"line":468,"column":16}},{"start":{"line":468,"column":16},"end":{"line":468,"column":16}}]},"21":{"line":507,"type":"if","locations":[{"start":{"line":507,"column":8},"end":{"line":507,"column":8}},{"start":{"line":507,"column":8},"end":{"line":507,"column":8}}]}},"code":["(function () { YUI.add('moodle-atto_multilang2-button', function (Y, NAME) {","","// This file is part of Moodle - http://moodle.org/","//","// Moodle is free software: you can redistribute it and/or modify","// it under the terms of the GNU General Public License as published by","// the Free Software Foundation, either version 3 of the License, or","// (at your option) any later version.","//","// Moodle is distributed in the hope that it will be useful,","// but WITHOUT ANY WARRANTY; without even the implied warranty of","// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the","// GNU General Public License for more details.","//","// You should have received a copy of the GNU General Public License","// along with Moodle. If not, see .","","/**"," * @package atto_multilang2"," * @copyright 2015 onwards Julen Pardo & Mondragon Unibertsitatea"," * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later"," */","","/**"," * @module moodle-atto_multilang2-button"," */","","var CLASSES = {"," TAG: 'filter-multilang-tag'"," },",""," LANG_WILDCARD = '%lang',"," CONTENT_WILDCARD = '%content',"," ATTR_LANGUAGES = 'languages',"," ATTR_CAPABILITY = 'capability',"," ATTR_HIGHLIGHT = 'highlight',"," ATTR_CSS = 'css',"," DEFAULT_LANGUAGE = '{\"en\":\"English (en)\"}',"," DEFAULT_CAPABILITY = true,"," DEFAULT_HIGHLIGHT = true,"," DEFAULT_CSS = 'outline: 1px dotted;' +"," 'padding: 0.1em;' +"," 'margin: 0em 0.1em;' +"," 'background-color: #ffffaa;',"," TEMPLATES = {"," SPANED: ' {mlang ' + LANG_WILDCARD + '}' +"," CONTENT_WILDCARD +"," '{mlang} ',",""," NOT_SPANED: '{mlang ' + LANG_WILDCARD + '}' + CONTENT_WILDCARD + '{mlang}'"," },"," OPENING_SPAN = '';","","/**"," * Atto text editor multilanguage plugin."," *"," * @namespace M.atto_multilang2"," * @class button"," * @extends M.editor_atto.EditorPlugin"," */","","Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {",""," /**"," * If the {mlang} tags have to be highlighted or not. Received as parameter from lib.php."," *"," * @property _highlight"," * @type boolean"," * @private"," */"," _highlight: true,",""," _auxiliarSubmitButtonNode: null,",""," initializer: function() {"," var hascapability = this.get(ATTR_CAPABILITY),"," toolbarItems = [];",""," if (hascapability) {"," toolbarItems = this._initializeToolbarItems();"," this._highlight = this.get(ATTR_HIGHLIGHT);",""," this.addToolbarMenu({"," globalItemConfig: {"," callback: this._addTags"," },"," icon: 'icon',"," iconComponent: 'atto_multilang2',"," items: toolbarItems"," });",""," this.get('host').on('atto:selectionchanged', this._checkSelectionChange, this);",""," this._addDelimiterCss();",""," if (this._highlight) {"," this._decorateTagsOnInit();"," this._setSubmitListeners();"," }"," }"," },",""," /**"," * Adds the CSS rules for the delimiters, received as parameter from lib.php."," *"," * @method _addDelimiterCss"," * @private"," */"," _addDelimiterCss: function() {"," var css = '.' + CLASSES.TAG + '{' + this.get(ATTR_CSS) + '}',"," style;",""," style = document.createElement('style');"," style.type = 'text/css';"," style.innerHTML = css;",""," document.head.appendChild(style);"," },",""," /**"," * Initializes the toolbar items, which will be the installed languages,"," * received as parameter."," *"," * @method _initializeToolbarItems"," * @private"," * @return {Array} installed language strings"," */"," _initializeToolbarItems: function() {"," var toolbarItems = [],"," languages,"," langCode;",""," languages = JSON.parse(this.get(ATTR_LANGUAGES));",""," for (langCode in languages) {"," if (languages.hasOwnProperty(langCode)) {"," toolbarItems.push({"," text: languages[langCode],"," callbackArgs: langCode"," });"," }"," }",""," return toolbarItems;"," },",""," /**"," * Retrieves the selected text, wraps it with the multilang tags,"," * and replaces the selected text in the editor with with it."," *"," * If the 'highlight' setting is checked, the {mlang} will be wrapped between"," * the tags with the class for the CSS highlight; if not, they will not"," * be wrapped."," *"," * If there is no content selected, a \" \" will be inserted; otherwhise,"," * it's impossible to place the cursor inside the {mlang} tags."," *"," * @method _addTags"," * @param {EventFacade} e"," * @param {string} langCode the language code"," * @private"," */"," _addTags: function(e, langCode) {"," var selection,"," host = this.get('host'),"," taggedContent,"," content;",""," taggedContent = (this._highlight) ? TEMPLATES.SPANED : TEMPLATES.NOT_SPANED;",""," selection = this._getSelectionHTML();"," content = (host.getSelection().toString().length === 0) ? ' ' : selection;",""," taggedContent = taggedContent.replace(LANG_WILDCARD, langCode);"," taggedContent = taggedContent.replace(CONTENT_WILDCARD, content);",""," host.insertContentAtFocusPoint(taggedContent);",""," this.markUpdated();"," },",""," /**"," * Retrieves selected text with its HTML."," * Took from: http://stackoverflow.com/questions/4176923/html-of-selected-text/4177234#4177234"," *"," * @method _getSelectionHTML"," * @private"," * @return {string} selected text's html; empty if nothing selected"," */"," _getSelectionHTML: function() {"," var html = '',"," selection,"," container,"," index,"," lenght;",""," if (typeof window.getSelection !== 'undefined') {"," selection = window.getSelection();",""," if (selection.rangeCount) {"," container = document.createElement('div');"," for (index = 0, lenght = selection.rangeCount; index < lenght; ++index) {"," container.appendChild(selection.getRangeAt(index).cloneContents());"," }"," html = container.innerHTML;"," }",""," } else if (typeof document.selection !== 'undefined') {"," if (document.selection.type === 'Text') {"," html = document.selection.createRange().htmlText;"," }"," }",""," return html;"," },",""," /**"," * Listens to every change of the text cursor in the text area. If the"," * cursor is placed within a multilang tag, the whole tag is selected."," *"," * @method _checkSelectionChange"," * @private"," */"," _checkSelectionChange: function() {"," var host = this.get('host'),"," node = host.getSelectionParentNode(),"," nodeValue = Y.one(node).get('text'),"," isTextNode,"," isLangTag;",""," isTextNode = Y.one(node).toString().indexOf('#text') > - 1;"," isLangTag = (nodeValue.match(/\\{mlang/g).length === 1);",""," if (isTextNode && isLangTag) {"," host.setSelection(host.getSelectionFromNode(Y.one(node)));"," }"," },",""," /**"," * Sets the submit listener to the function that finds the spaned {mlang} tags."," *"," * In some forms, there may be two different submit buttons, so we add the listener"," * to the second, if this exists."," *"," * These submit listeners are set only if the \"highlight\" plugin setting is checked."," *"," * @method _setSubmitListener"," * @private"," */"," _setSubmitListeners: function() {"," var submitButtons = Y.all('input[type=submit]');",""," submitButtons.each(this._addListenerToSubmitButtons, this);"," },",""," _addListenerToSubmitButtons: function(buttonNode) {"," var buttonObject,"," className,"," parentFormClassName,"," notCancelButton,"," notSearchButton;",""," buttonObject = document.getElementById(buttonNode.get('id'));",""," if (buttonObject !== null) {"," className = buttonObject.className;"," parentFormClassName = buttonObject.form.className;",""," notCancelButton = className.match(/btn-cancel/g) === null;"," notSearchButton = parentFormClassName.match(/mform/g).length > 0;",""," if (notCancelButton && notSearchButton) {"," this._auxiliarSubmitButtonNode = buttonNode;"," buttonNode.on('click', this._cleanTagsOnSubmit, this);"," }"," }"," },",""," _cleanTagsOnSubmit: function(e) {"," var submitButton;",""," e.preventDefault();",""," submitButton = Y.one(this._auxiliarSubmitButtonNode);",""," this._cleanTagsWithNoYuiId();"," this._cleanTagsWithYuiId();",""," submitButton.detach('click', this._cleanTagsOnSubmit);"," submitButton.simulate('click');"," },",""," /**"," * Cleans the tags around the {mlang} tags when the form is submitted,"," * that do not have \"id\" attribute."," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * There may be more than one atto editor textarea in the page. So, we have to retrieve"," * the textareas by the class name. If there is only one, the object will be only the"," * reference, but, if there are more, we will have an array. So, the easiest way is to"," * check if what we have is an array, and if it not, create it manually, and iterate it"," * later."," *"," * issue #15: the textareas are now retrieved passing to YUI selector the whole element,"," * instead of the id string, due to problems with special characters."," * See discussion: https://moodle.org/mod/forum/discuss.php?d=332217"," *"," * @method _cleanTagsWithNoYuiId"," * @private"," */"," _cleanTagsWithNoYuiId: function() {"," var textareas = Y.all('.editor_atto_content'),"," textarea,"," textareaIndex,"," innerHTML,"," spanedmlangtags,"," spanedmlangtag,"," index,"," cleanmlangtag,"," regularExpression;",""," regularExpression = new RegExp(OPENING_SPAN + '.*?' + '', 'g');",""," if (!textareas instanceof Array) {"," textarea = textareas;"," textareas = [];"," textareas[0] = textarea;"," }",""," for (textareaIndex = 0; textareaIndex < textareas._nodes.length; textareaIndex++) {"," textarea = textareas._nodes[textareaIndex].id;"," textarea = Y.one(document.getElementById(textarea));",""," innerHTML = textarea.get('innerHTML');",""," spanedmlangtags = innerHTML.match(regularExpression);",""," if (spanedmlangtags === null) {"," continue;"," }"," "," for (index = 0; index < spanedmlangtags.length; index++) {"," spanedmlangtag = spanedmlangtags[index];"," cleanmlangtag = spanedmlangtag.replace(OPENING_SPAN, '');",""," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }",""," textarea.set('innerHTML', innerHTML);"," }",""," this.markUpdated();"," },",""," /**"," * Cleans the tags around the {mlang} tags when the form is submitted,"," * that have \"id\" attribute, generated by YUI, when the cursor is placed on the tags."," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * There may be more than one atto editor textarea in the page. So, we have to retrieve"," * the textareas by the class name. If there is only one, the object will be only the"," * reference, but, if there are more, we will have an array. So, the easiest way is to"," * check if what we have is an array, and if it not, create it manually, and iterate it"," * later."," *"," * issue #15: the textareas are now retrieved passing to YUI selector the whole element,"," * instead of the id string, due to problems with special characters."," * See discussion: https://moodle.org/mod/forum/discuss.php?d=332217"," *"," * @method anTagsWithYuiId"," * @private"," */"," _cleanTagsWithYuiId: function() {"," var textareas = Y.all('.editor_atto_content'),"," textarea,"," textareaIndex,"," innerHTML,"," spanedmlangtag,"," index,"," cleanmlangtag,"," regularExpression,"," openingspanwithyui,"," spanedmlangtagsdwithyui,"," mlangtag;",""," openingspanwithyui = OPENING_SPAN.replace('', 'g');",""," if (!textareas instanceof Array) {"," textarea = textareas;"," textareas = [];"," textareas[0] = textarea;"," }"," "," for (textareaIndex = 0; textareaIndex < textareas._nodes.length; textareaIndex++) {"," textarea = textareas._nodes[textareaIndex].id;"," textarea = Y.one(document.getElementById(textarea));",""," innerHTML = textarea.get('innerHTML');",""," spanedmlangtagsdwithyui = innerHTML.match(regularExpression);",""," if (spanedmlangtagsdwithyui === null) {"," continue;"," }"," "," for (index = 0; index < spanedmlangtagsdwithyui.length; index++) {"," spanedmlangtag = spanedmlangtagsdwithyui[index];"," mlangtag = spanedmlangtag.match(/\\{mlang.*?\\}/g)[0];",""," cleanmlangtag = spanedmlangtag.replace(regularExpression, mlangtag);"," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }",""," textarea.set('innerHTML', innerHTML);",""," this.markUpdated();"," }"," },",""," /**"," * Adds the tags to the {mlang} tags when the editor is loaded."," * In this case, we DON'T HAVE TO CALL TO markUpdated(). Why? Honestly,"," * I don't know. But, if we call it after setting the HTML, the {mlang}"," * tags flicker with the decoration, and returns to their original state."," *"," * Instead of taking the HTML directly from the textarea, we have to"," * retrieve it, first, without the tags that can be stored"," * in database, due to a bug in version 2015120501 that stores the"," * {mlang} tags in database, with the tags."," * More info about this bug: https://github.com/julenpardo/moodle-atto_multilang2/issues/8"," *"," * Every different {mlang} tag has to be replaced only once, otherwise,"," * nested s will be created in every repeated replacement. So, we"," * have to have a track of which replacements have been made."," *"," * @method _decorateTagsOnInit"," * @private"," */"," _decorateTagsOnInit: function() {"," var textarea = Y.all('.editor_atto_content'),"," innerHTML,"," regularExpression,"," mlangtags,"," mlangtag,"," index,"," decoratedmlangtag,"," replacementsmade = [],"," notreplacedyet;",""," innerHTML = this._getHTMLwithCleanedTags();",""," regularExpression = new RegExp('{mlang.*?}', 'g');"," mlangtags = innerHTML.match(regularExpression);",""," if (mlangtags !== null) {"," for (index = 0; index < mlangtags.length; index++) {"," mlangtag = mlangtags[index];",""," notreplacedyet = replacementsmade.indexOf(mlangtag) === -1;",""," if (notreplacedyet) {"," replacementsmade.push(mlangtag);",""," decoratedmlangtag = OPENING_SPAN + mlangtag + '';"," regularExpression = new RegExp(mlangtag, 'g');",""," innerHTML = innerHTML.replace(regularExpression, decoratedmlangtag);"," }"," }",""," textarea.set('innerHTML', innerHTML);"," }",""," },",""," /**"," * This function returns the HTML as it is in the textarea, but cleaning every"," * tag around the {mlang} tags. This is necessary for decorating tags on"," * init, because it could happen that in database are stored the {mlang} tags with"," * their tags, due to a bug in version 2015120501."," * More info about this bug: https://github.com/julenpardo/moodle-atto_multilang2/issues/8"," *"," * @method _getHTMLwithCleanedTags"," * @return {string} HTML in textarea, without any around {mlang} tags"," */"," _getHTMLwithCleanedTags: function() {"," var host = this.get('host'),"," innerHTML = host.getCleanHTML(),"," regexString,"," regularExpression,"," spanedmlangtags,"," spanedmlangtag,"," cleanmlangtag,"," index;",""," regexString = OPENING_SPAN + '.*?' + '';"," regularExpression = new RegExp(regexString, 'g');"," spanedmlangtags = innerHTML.match(regularExpression);",""," if (spanedmlangtags !== null) {"," for (index = 0; index < spanedmlangtags.length; index++) {"," spanedmlangtag = spanedmlangtags[index];",""," cleanmlangtag = spanedmlangtag.replace(OPENING_SPAN, '');"," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }"," }",""," return innerHTML;"," }","","}, {"," ATTRS: {"," /**"," * The list of installed languages."," *"," * @attribute languages"," * @type array"," * @default {\"en\":\"English (en)\"}"," */"," languages: DEFAULT_LANGUAGE,",""," /**"," * If the current user has the capability to use the plugin."," *"," * @attribute capability"," * @type boolean"," * @default true"," */"," capability: DEFAULT_CAPABILITY,",""," /**"," * If the {mlang} tags have to be highlighted or not."," *"," * @property highlight"," * @type boolean"," * @default true"," */"," highlight: DEFAULT_HIGHLIGHT,",""," /**"," * The CSS for delimiters."," *"," * @property css"," * @type string"," * @default DEFAULT_CSS"," */"," css: DEFAULT_CSS"," }","});","","","}, '@VERSION@', {\"requires\": [\"moodle-editor_atto-plugin\"]});","","}());"]}; + __coverage__['build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js'] = {"path":"build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0,"100":0,"101":0,"102":0,"103":0,"104":0,"105":0,"106":0,"107":0,"108":0,"109":0,"110":0,"111":0,"112":0,"113":0,"114":0,"115":0,"116":0,"117":0,"118":0,"119":0,"120":0,"121":0,"122":0,"123":0,"124":0,"125":0,"126":0,"127":0,"128":0,"129":0,"130":0,"131":0,"132":0,"133":0,"134":0,"135":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0],"14":[0,0],"15":[0,0],"16":[0,0],"17":[0,0],"18":[0,0],"19":[0,0],"20":[0,0],"21":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0},"fnMap":{"1":{"name":"(anonymous_1)","line":1,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":60}}},"2":{"name":"(anonymous_2)","line":83,"loc":{"start":{"line":83,"column":17},"end":{"line":83,"column":28}}},"3":{"name":"(anonymous_3)","line":117,"loc":{"start":{"line":117,"column":22},"end":{"line":117,"column":33}}},"4":{"name":"(anonymous_4)","line":136,"loc":{"start":{"line":136,"column":29},"end":{"line":136,"column":40}}},"5":{"name":"(anonymous_5)","line":171,"loc":{"start":{"line":171,"column":14},"end":{"line":171,"column":36}}},"6":{"name":"(anonymous_6)","line":198,"loc":{"start":{"line":198,"column":23},"end":{"line":198,"column":34}}},"7":{"name":"(anonymous_7)","line":232,"loc":{"start":{"line":232,"column":27},"end":{"line":232,"column":38}}},"8":{"name":"(anonymous_8)","line":255,"loc":{"start":{"line":255,"column":25},"end":{"line":255,"column":36}}},"9":{"name":"(anonymous_9)","line":273,"loc":{"start":{"line":273,"column":33},"end":{"line":273,"column":54}}},"10":{"name":"(anonymous_10)","line":310,"loc":{"start":{"line":310,"column":24},"end":{"line":310,"column":36}}},"11":{"name":"(anonymous_11)","line":343,"loc":{"start":{"line":343,"column":27},"end":{"line":343,"column":38}}},"12":{"name":"(anonymous_12)","line":408,"loc":{"start":{"line":408,"column":26},"end":{"line":408,"column":37}}},"13":{"name":"(anonymous_13)","line":477,"loc":{"start":{"line":477,"column":25},"end":{"line":477,"column":36}}},"14":{"name":"(anonymous_14)","line":524,"loc":{"start":{"line":524,"column":29},"end":{"line":524,"column":40}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":593,"column":61}},"2":{"start":{"line":28,"column":0},"end":{"line":52,"column":56}},"3":{"start":{"line":62,"column":0},"end":{"line":590,"column":3}},"4":{"start":{"line":84,"column":8},"end":{"line":85,"column":30}},"5":{"start":{"line":87,"column":8},"end":{"line":108,"column":9}},"6":{"start":{"line":88,"column":12},"end":{"line":88,"column":58}},"7":{"start":{"line":89,"column":12},"end":{"line":89,"column":55}},"8":{"start":{"line":91,"column":12},"end":{"line":98,"column":15}},"9":{"start":{"line":100,"column":12},"end":{"line":100,"column":91}},"10":{"start":{"line":102,"column":12},"end":{"line":102,"column":36}},"11":{"start":{"line":104,"column":12},"end":{"line":107,"column":13}},"12":{"start":{"line":105,"column":16},"end":{"line":105,"column":43}},"13":{"start":{"line":106,"column":16},"end":{"line":106,"column":43}},"14":{"start":{"line":118,"column":8},"end":{"line":119,"column":18}},"15":{"start":{"line":121,"column":8},"end":{"line":121,"column":48}},"16":{"start":{"line":122,"column":8},"end":{"line":122,"column":32}},"17":{"start":{"line":123,"column":8},"end":{"line":123,"column":30}},"18":{"start":{"line":125,"column":8},"end":{"line":125,"column":41}},"19":{"start":{"line":137,"column":8},"end":{"line":139,"column":21}},"20":{"start":{"line":141,"column":8},"end":{"line":141,"column":57}},"21":{"start":{"line":143,"column":8},"end":{"line":150,"column":9}},"22":{"start":{"line":144,"column":12},"end":{"line":149,"column":13}},"23":{"start":{"line":145,"column":16},"end":{"line":148,"column":19}},"24":{"start":{"line":152,"column":8},"end":{"line":152,"column":28}},"25":{"start":{"line":172,"column":8},"end":{"line":175,"column":20}},"26":{"start":{"line":177,"column":8},"end":{"line":177,"column":84}},"27":{"start":{"line":179,"column":8},"end":{"line":179,"column":45}},"28":{"start":{"line":180,"column":8},"end":{"line":180,"column":87}},"29":{"start":{"line":182,"column":8},"end":{"line":182,"column":71}},"30":{"start":{"line":183,"column":8},"end":{"line":183,"column":73}},"31":{"start":{"line":185,"column":8},"end":{"line":185,"column":54}},"32":{"start":{"line":187,"column":8},"end":{"line":187,"column":27}},"33":{"start":{"line":199,"column":8},"end":{"line":203,"column":19}},"34":{"start":{"line":205,"column":8},"end":{"line":220,"column":9}},"35":{"start":{"line":206,"column":12},"end":{"line":206,"column":46}},"36":{"start":{"line":208,"column":12},"end":{"line":214,"column":13}},"37":{"start":{"line":209,"column":16},"end":{"line":209,"column":58}},"38":{"start":{"line":210,"column":16},"end":{"line":212,"column":17}},"39":{"start":{"line":211,"column":20},"end":{"line":211,"column":87}},"40":{"start":{"line":213,"column":16},"end":{"line":213,"column":43}},"41":{"start":{"line":216,"column":15},"end":{"line":220,"column":9}},"42":{"start":{"line":217,"column":12},"end":{"line":219,"column":13}},"43":{"start":{"line":218,"column":16},"end":{"line":218,"column":65}},"44":{"start":{"line":222,"column":8},"end":{"line":222,"column":20}},"45":{"start":{"line":233,"column":8},"end":{"line":237,"column":22}},"46":{"start":{"line":239,"column":8},"end":{"line":239,"column":67}},"47":{"start":{"line":240,"column":8},"end":{"line":240,"column":63}},"48":{"start":{"line":242,"column":8},"end":{"line":244,"column":9}},"49":{"start":{"line":243,"column":12},"end":{"line":243,"column":70}},"50":{"start":{"line":256,"column":8},"end":{"line":256,"column":56}},"51":{"start":{"line":258,"column":8},"end":{"line":258,"column":67}},"52":{"start":{"line":274,"column":8},"end":{"line":278,"column":28}},"53":{"start":{"line":280,"column":8},"end":{"line":280,"column":69}},"54":{"start":{"line":282,"column":8},"end":{"line":293,"column":9}},"55":{"start":{"line":283,"column":12},"end":{"line":283,"column":47}},"56":{"start":{"line":284,"column":12},"end":{"line":284,"column":62}},"57":{"start":{"line":286,"column":12},"end":{"line":286,"column":70}},"58":{"start":{"line":287,"column":12},"end":{"line":287,"column":77}},"59":{"start":{"line":289,"column":12},"end":{"line":292,"column":13}},"60":{"start":{"line":290,"column":16},"end":{"line":290,"column":60}},"61":{"start":{"line":291,"column":16},"end":{"line":291,"column":70}},"62":{"start":{"line":311,"column":8},"end":{"line":311,"column":25}},"63":{"start":{"line":313,"column":8},"end":{"line":313,"column":27}},"64":{"start":{"line":315,"column":8},"end":{"line":315,"column":61}},"65":{"start":{"line":317,"column":8},"end":{"line":317,"column":37}},"66":{"start":{"line":318,"column":8},"end":{"line":318,"column":35}},"67":{"start":{"line":320,"column":8},"end":{"line":320,"column":62}},"68":{"start":{"line":321,"column":8},"end":{"line":321,"column":39}},"69":{"start":{"line":344,"column":8},"end":{"line":352,"column":30}},"70":{"start":{"line":354,"column":8},"end":{"line":354,"column":78}},"71":{"start":{"line":356,"column":8},"end":{"line":360,"column":9}},"72":{"start":{"line":357,"column":12},"end":{"line":357,"column":33}},"73":{"start":{"line":358,"column":12},"end":{"line":358,"column":27}},"74":{"start":{"line":359,"column":12},"end":{"line":359,"column":36}},"75":{"start":{"line":362,"column":8},"end":{"line":384,"column":9}},"76":{"start":{"line":363,"column":12},"end":{"line":363,"column":58}},"77":{"start":{"line":364,"column":12},"end":{"line":364,"column":64}},"78":{"start":{"line":366,"column":12},"end":{"line":366,"column":50}},"79":{"start":{"line":368,"column":12},"end":{"line":368,"column":65}},"80":{"start":{"line":370,"column":12},"end":{"line":372,"column":13}},"81":{"start":{"line":371,"column":16},"end":{"line":371,"column":25}},"82":{"start":{"line":374,"column":12},"end":{"line":381,"column":13}},"83":{"start":{"line":375,"column":16},"end":{"line":375,"column":56}},"84":{"start":{"line":376,"column":16},"end":{"line":376,"column":73}},"85":{"start":{"line":378,"column":16},"end":{"line":378,"column":69}},"86":{"start":{"line":380,"column":16},"end":{"line":380,"column":77}},"87":{"start":{"line":383,"column":12},"end":{"line":383,"column":49}},"88":{"start":{"line":386,"column":8},"end":{"line":386,"column":27}},"89":{"start":{"line":409,"column":8},"end":{"line":419,"column":21}},"90":{"start":{"line":421,"column":8},"end":{"line":421,"column":81}},"91":{"start":{"line":422,"column":8},"end":{"line":422,"column":89}},"92":{"start":{"line":424,"column":8},"end":{"line":428,"column":9}},"93":{"start":{"line":425,"column":12},"end":{"line":425,"column":33}},"94":{"start":{"line":426,"column":12},"end":{"line":426,"column":27}},"95":{"start":{"line":427,"column":12},"end":{"line":427,"column":36}},"96":{"start":{"line":430,"column":8},"end":{"line":455,"column":9}},"97":{"start":{"line":431,"column":12},"end":{"line":431,"column":58}},"98":{"start":{"line":432,"column":12},"end":{"line":432,"column":64}},"99":{"start":{"line":434,"column":12},"end":{"line":434,"column":50}},"100":{"start":{"line":436,"column":12},"end":{"line":436,"column":73}},"101":{"start":{"line":438,"column":12},"end":{"line":440,"column":13}},"102":{"start":{"line":439,"column":16},"end":{"line":439,"column":25}},"103":{"start":{"line":442,"column":12},"end":{"line":450,"column":13}},"104":{"start":{"line":443,"column":16},"end":{"line":443,"column":64}},"105":{"start":{"line":444,"column":16},"end":{"line":444,"column":68}},"106":{"start":{"line":446,"column":16},"end":{"line":446,"column":84}},"107":{"start":{"line":447,"column":16},"end":{"line":447,"column":69}},"108":{"start":{"line":449,"column":16},"end":{"line":449,"column":77}},"109":{"start":{"line":452,"column":12},"end":{"line":452,"column":49}},"110":{"start":{"line":454,"column":12},"end":{"line":454,"column":31}},"111":{"start":{"line":478,"column":8},"end":{"line":486,"column":27}},"112":{"start":{"line":488,"column":8},"end":{"line":488,"column":51}},"113":{"start":{"line":490,"column":8},"end":{"line":490,"column":58}},"114":{"start":{"line":491,"column":8},"end":{"line":491,"column":55}},"115":{"start":{"line":493,"column":8},"end":{"line":510,"column":9}},"116":{"start":{"line":494,"column":12},"end":{"line":507,"column":13}},"117":{"start":{"line":495,"column":16},"end":{"line":495,"column":44}},"118":{"start":{"line":497,"column":16},"end":{"line":497,"column":75}},"119":{"start":{"line":499,"column":16},"end":{"line":506,"column":17}},"120":{"start":{"line":500,"column":20},"end":{"line":500,"column":52}},"121":{"start":{"line":502,"column":20},"end":{"line":502,"column":76}},"122":{"start":{"line":503,"column":20},"end":{"line":503,"column":66}},"123":{"start":{"line":505,"column":20},"end":{"line":505,"column":88}},"124":{"start":{"line":509,"column":12},"end":{"line":509,"column":49}},"125":{"start":{"line":525,"column":8},"end":{"line":532,"column":18}},"126":{"start":{"line":534,"column":8},"end":{"line":534,"column":55}},"127":{"start":{"line":535,"column":8},"end":{"line":535,"column":57}},"128":{"start":{"line":536,"column":8},"end":{"line":536,"column":61}},"129":{"start":{"line":538,"column":8},"end":{"line":547,"column":9}},"130":{"start":{"line":539,"column":12},"end":{"line":546,"column":13}},"131":{"start":{"line":540,"column":16},"end":{"line":540,"column":56}},"132":{"start":{"line":542,"column":16},"end":{"line":542,"column":73}},"133":{"start":{"line":543,"column":16},"end":{"line":543,"column":69}},"134":{"start":{"line":545,"column":16},"end":{"line":545,"column":77}},"135":{"start":{"line":549,"column":8},"end":{"line":549,"column":25}}},"branchMap":{"1":{"line":87,"type":"if","locations":[{"start":{"line":87,"column":8},"end":{"line":87,"column":8}},{"start":{"line":87,"column":8},"end":{"line":87,"column":8}}]},"2":{"line":104,"type":"if","locations":[{"start":{"line":104,"column":12},"end":{"line":104,"column":12}},{"start":{"line":104,"column":12},"end":{"line":104,"column":12}}]},"3":{"line":144,"type":"if","locations":[{"start":{"line":144,"column":12},"end":{"line":144,"column":12}},{"start":{"line":144,"column":12},"end":{"line":144,"column":12}}]},"4":{"line":177,"type":"cond-expr","locations":[{"start":{"line":177,"column":44},"end":{"line":177,"column":60}},{"start":{"line":177,"column":63},"end":{"line":177,"column":83}}]},"5":{"line":180,"type":"cond-expr","locations":[{"start":{"line":180,"column":66},"end":{"line":180,"column":74}},{"start":{"line":180,"column":77},"end":{"line":180,"column":86}}]},"6":{"line":205,"type":"if","locations":[{"start":{"line":205,"column":8},"end":{"line":205,"column":8}},{"start":{"line":205,"column":8},"end":{"line":205,"column":8}}]},"7":{"line":208,"type":"if","locations":[{"start":{"line":208,"column":12},"end":{"line":208,"column":12}},{"start":{"line":208,"column":12},"end":{"line":208,"column":12}}]},"8":{"line":216,"type":"if","locations":[{"start":{"line":216,"column":15},"end":{"line":216,"column":15}},{"start":{"line":216,"column":15},"end":{"line":216,"column":15}}]},"9":{"line":217,"type":"if","locations":[{"start":{"line":217,"column":12},"end":{"line":217,"column":12}},{"start":{"line":217,"column":12},"end":{"line":217,"column":12}}]},"10":{"line":242,"type":"if","locations":[{"start":{"line":242,"column":8},"end":{"line":242,"column":8}},{"start":{"line":242,"column":8},"end":{"line":242,"column":8}}]},"11":{"line":242,"type":"binary-expr","locations":[{"start":{"line":242,"column":12},"end":{"line":242,"column":22}},{"start":{"line":242,"column":26},"end":{"line":242,"column":35}}]},"12":{"line":282,"type":"if","locations":[{"start":{"line":282,"column":8},"end":{"line":282,"column":8}},{"start":{"line":282,"column":8},"end":{"line":282,"column":8}}]},"13":{"line":289,"type":"if","locations":[{"start":{"line":289,"column":12},"end":{"line":289,"column":12}},{"start":{"line":289,"column":12},"end":{"line":289,"column":12}}]},"14":{"line":289,"type":"binary-expr","locations":[{"start":{"line":289,"column":16},"end":{"line":289,"column":31}},{"start":{"line":289,"column":35},"end":{"line":289,"column":50}}]},"15":{"line":356,"type":"if","locations":[{"start":{"line":356,"column":8},"end":{"line":356,"column":8}},{"start":{"line":356,"column":8},"end":{"line":356,"column":8}}]},"16":{"line":370,"type":"if","locations":[{"start":{"line":370,"column":12},"end":{"line":370,"column":12}},{"start":{"line":370,"column":12},"end":{"line":370,"column":12}}]},"17":{"line":424,"type":"if","locations":[{"start":{"line":424,"column":8},"end":{"line":424,"column":8}},{"start":{"line":424,"column":8},"end":{"line":424,"column":8}}]},"18":{"line":438,"type":"if","locations":[{"start":{"line":438,"column":12},"end":{"line":438,"column":12}},{"start":{"line":438,"column":12},"end":{"line":438,"column":12}}]},"19":{"line":493,"type":"if","locations":[{"start":{"line":493,"column":8},"end":{"line":493,"column":8}},{"start":{"line":493,"column":8},"end":{"line":493,"column":8}}]},"20":{"line":499,"type":"if","locations":[{"start":{"line":499,"column":16},"end":{"line":499,"column":16}},{"start":{"line":499,"column":16},"end":{"line":499,"column":16}}]},"21":{"line":538,"type":"if","locations":[{"start":{"line":538,"column":8},"end":{"line":538,"column":8}},{"start":{"line":538,"column":8},"end":{"line":538,"column":8}}]}},"code":["(function () { YUI.add('moodle-atto_multilang2-button', function (Y, NAME) {","","// This file is part of Moodle - http://moodle.org/","//","// Moodle is free software: you can redistribute it and/or modify","// it under the terms of the GNU General Public License as published by","// the Free Software Foundation, either version 3 of the License, or","// (at your option) any later version.","//","// Moodle is distributed in the hope that it will be useful,","// but WITHOUT ANY WARRANTY; without even the implied warranty of","// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the","// GNU General Public License for more details.","//","// You should have received a copy of the GNU General Public License","// along with Moodle. If not, see .","","/**"," * @package atto_multilang2"," * @copyright 2015 onwards Julen Pardo & Mondragon Unibertsitatea"," * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later"," */","","/**"," * @module moodle-atto_multilang2-button"," */","","var CLASSES = {"," TAG: 'filter-multilang-tag'"," },",""," LANG_WILDCARD = '%lang',"," CONTENT_WILDCARD = '%content',"," ATTR_LANGUAGES = 'languages',"," ATTR_CAPABILITY = 'capability',"," ATTR_HIGHLIGHT = 'highlight',"," ATTR_CSS = 'css',"," DEFAULT_LANGUAGE = '{\"en\":\"English (en)\"}',"," DEFAULT_CAPABILITY = true,"," DEFAULT_HIGHLIGHT = true,"," DEFAULT_CSS = 'outline: 1px dotted;' +"," 'padding: 0.1em;' +"," 'margin: 0em 0.1em;' +"," 'background-color: #ffffaa;',"," TEMPLATES = {"," SPANED: ' {mlang ' + LANG_WILDCARD + '}' +"," CONTENT_WILDCARD +"," '{mlang} ',",""," NOT_SPANED: '{mlang ' + LANG_WILDCARD + '}' + CONTENT_WILDCARD + '{mlang}'"," },"," OPENING_SPAN = '';","","/**"," * Atto text editor multilanguage plugin."," *"," * @namespace M.atto_multilang2"," * @class button"," * @extends M.editor_atto.EditorPlugin"," */","","Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {",""," /**"," * If the {mlang} tags have to be highlighted or not. Received as parameter from lib.php."," *"," * @property _highlight"," * @type boolean"," * @private"," */"," _highlight: true,",""," /**"," * Used as \"indirect argument\" to function \"_cleanTagsOnSubmit\", since there is not"," * any (apparent) way to pass arguments to YUI callback functions."," *"," * @property _auxiliarSubmitButton"," * @type Node"," * @private"," */"," _auxiliarSubmitButtonNode: null,",""," initializer: function() {"," var hascapability = this.get(ATTR_CAPABILITY),"," toolbarItems = [];",""," if (hascapability) {"," toolbarItems = this._initializeToolbarItems();"," this._highlight = this.get(ATTR_HIGHLIGHT);",""," this.addToolbarMenu({"," globalItemConfig: {"," callback: this._addTags"," },"," icon: 'icon',"," iconComponent: 'atto_multilang2',"," items: toolbarItems"," });",""," this.get('host').on('atto:selectionchanged', this._checkSelectionChange, this);",""," this._addDelimiterCss();",""," if (this._highlight) {"," this._decorateTagsOnInit();"," this._setSubmitListeners();"," }"," }"," },",""," /**"," * Adds the CSS rules for the delimiters, received as parameter from lib.php."," *"," * @method _addDelimiterCss"," * @private"," */"," _addDelimiterCss: function() {"," var css = '.' + CLASSES.TAG + '{' + this.get(ATTR_CSS) + '}',"," style;",""," style = document.createElement('style');"," style.type = 'text/css';"," style.innerHTML = css;",""," document.head.appendChild(style);"," },",""," /**"," * Initializes the toolbar items, which will be the installed languages,"," * received as parameter."," *"," * @method _initializeToolbarItems"," * @private"," * @return {Array} installed language strings"," */"," _initializeToolbarItems: function() {"," var toolbarItems = [],"," languages,"," langCode;",""," languages = JSON.parse(this.get(ATTR_LANGUAGES));",""," for (langCode in languages) {"," if (languages.hasOwnProperty(langCode)) {"," toolbarItems.push({"," text: languages[langCode],"," callbackArgs: langCode"," });"," }"," }",""," return toolbarItems;"," },",""," /**"," * Retrieves the selected text, wraps it with the multilang tags,"," * and replaces the selected text in the editor with with it."," *"," * If the 'highlight' setting is checked, the {mlang} will be wrapped between"," * the tags with the class for the CSS highlight; if not, they will not"," * be wrapped."," *"," * If there is no content selected, a \" \" will be inserted; otherwhise,"," * it's impossible to place the cursor inside the {mlang} tags."," *"," * @method _addTags"," * @param {EventFacade} e"," * @param {string} langCode the language code"," * @private"," */"," _addTags: function(e, langCode) {"," var selection,"," host = this.get('host'),"," taggedContent,"," content;",""," taggedContent = (this._highlight) ? TEMPLATES.SPANED : TEMPLATES.NOT_SPANED;",""," selection = this._getSelectionHTML();"," content = (host.getSelection().toString().length === 0) ? ' ' : selection;",""," taggedContent = taggedContent.replace(LANG_WILDCARD, langCode);"," taggedContent = taggedContent.replace(CONTENT_WILDCARD, content);",""," host.insertContentAtFocusPoint(taggedContent);",""," this.markUpdated();"," },",""," /**"," * Retrieves selected text with its HTML."," * Took from: http://stackoverflow.com/questions/4176923/html-of-selected-text/4177234#4177234"," *"," * @method _getSelectionHTML"," * @private"," * @return {string} selected text's html; empty if nothing selected"," */"," _getSelectionHTML: function() {"," var html = '',"," selection,"," container,"," index,"," lenght;",""," if (typeof window.getSelection !== 'undefined') {"," selection = window.getSelection();",""," if (selection.rangeCount) {"," container = document.createElement('div');"," for (index = 0, lenght = selection.rangeCount; index < lenght; ++index) {"," container.appendChild(selection.getRangeAt(index).cloneContents());"," }"," html = container.innerHTML;"," }",""," } else if (typeof document.selection !== 'undefined') {"," if (document.selection.type === 'Text') {"," html = document.selection.createRange().htmlText;"," }"," }",""," return html;"," },",""," /**"," * Listens to every change of the text cursor in the text area. If the"," * cursor is placed within a multilang tag, the whole tag is selected."," *"," * @method _checkSelectionChange"," * @private"," */"," _checkSelectionChange: function() {"," var host = this.get('host'),"," node = host.getSelectionParentNode(),"," nodeValue = Y.one(node).get('text'),"," isTextNode,"," isLangTag;",""," isTextNode = Y.one(node).toString().indexOf('#text') > - 1;"," isLangTag = (nodeValue.match(/\\{mlang/g).length === 1);",""," if (isTextNode && isLangTag) {"," host.setSelection(host.getSelectionFromNode(Y.one(node)));"," }"," },",""," /**"," * Retrieves the inputs of type submit, and, for each element, calls the function"," * that sets the submit listener. Is not made in this function because there is"," * not any (apparent) way to access class scope from YUI closure. "," *"," * @method _setSubmitListeners"," * @private"," */"," _setSubmitListeners: function() {"," var submitButtons = Y.all('input[type=submit]');",""," submitButtons.each(this._addListenerToSubmitButtons, this);"," },",""," /**"," * Adds the clean tags submit listener of each input[type=\"submit\"], but only if"," * it's not 'cancel' type, and if its parent form is of 'mform' class, because there"," * may be any other submit type (such us administrator's search button)."," *"," * The button node to add the listener is passed as global property because there is"," * no (apparent) way to pass arguments to YUI callback functions."," *"," * @method _addListenerToSubmitButtons"," * @param {Node} buttonNode"," * @private"," */"," _addListenerToSubmitButtons: function(buttonNode) {"," var buttonObject,"," className,"," parentFormClassName,"," notCancelButton,"," notSearchButton;",""," buttonObject = document.getElementById(buttonNode.get('id'));",""," if (buttonObject !== null) {"," className = buttonObject.className;"," parentFormClassName = buttonObject.form.className;",""," notCancelButton = className.match(/btn-cancel/g) === null;"," notSearchButton = parentFormClassName.match(/mform/g).length > 0;",""," if (notCancelButton && notSearchButton) {"," this._auxiliarSubmitButtonNode = buttonNode;"," buttonNode.on('click', this._cleanTagsOnSubmit, this);"," }"," }"," },",""," /**"," * When submit button clicked, this function is invoked. It has to stop the submission,"," * in order to process the textarea to clean the tags."," *"," * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default,"," * an then simulates the click, to submit the form."," *"," * The clicked submit button ('save and return' or 'save and display'), is accessed globally,"," * in '_auxiliarSubmitButtonNode' property, set by '_addListenerToSubmitButtons' function."," *"," * @method _cleanTagsOnSubmit"," * @param {EventFacade} e"," * @private"," */"," _cleanTagsOnSubmit: function(e) {"," var submitButton;",""," e.preventDefault();",""," submitButton = Y.one(this._auxiliarSubmitButtonNode);",""," this._cleanTagsWithNoYuiId();"," this._cleanTagsWithYuiId();",""," submitButton.detach('click', this._cleanTagsOnSubmit);"," submitButton.simulate('click');"," },",""," /**"," * Cleans the tags around the {mlang} tags when the form is submitted,"," * that do not have \"id\" attribute."," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * There may be more than one atto editor textarea in the page. So, we have to retrieve"," * the textareas by the class name. If there is only one, the object will be only the"," * reference, but, if there are more, we will have an array. So, the easiest way is to"," * check if what we have is an array, and if it not, create it manually, and iterate it"," * later."," *"," * issue #15: the textareas are now retrieved passing to YUI selector the whole element,"," * instead of the id string, due to problems with special characters."," * See discussion: https://moodle.org/mod/forum/discuss.php?d=332217"," *"," * @method _cleanTagsWithNoYuiId"," * @private"," */"," _cleanTagsWithNoYuiId: function() {"," var textareas = Y.all('.editor_atto_content'),"," textarea,"," textareaIndex,"," innerHTML,"," spanedmlangtags,"," spanedmlangtag,"," index,"," cleanmlangtag,"," regularExpression;",""," regularExpression = new RegExp(OPENING_SPAN + '.*?' + '', 'g');",""," if (!textareas instanceof Array) {"," textarea = textareas;"," textareas = [];"," textareas[0] = textarea;"," }",""," for (textareaIndex = 0; textareaIndex < textareas._nodes.length; textareaIndex++) {"," textarea = textareas._nodes[textareaIndex].id;"," textarea = Y.one(document.getElementById(textarea));",""," innerHTML = textarea.get('innerHTML');",""," spanedmlangtags = innerHTML.match(regularExpression);",""," if (spanedmlangtags === null) {"," continue;"," }"," "," for (index = 0; index < spanedmlangtags.length; index++) {"," spanedmlangtag = spanedmlangtags[index];"," cleanmlangtag = spanedmlangtag.replace(OPENING_SPAN, '');",""," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }",""," textarea.set('innerHTML', innerHTML);"," }",""," this.markUpdated();"," },",""," /**"," * Cleans the tags around the {mlang} tags when the form is submitted,"," * that have \"id\" attribute, generated by YUI, when the cursor is placed on the tags."," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * There may be more than one atto editor textarea in the page. So, we have to retrieve"," * the textareas by the class name. If there is only one, the object will be only the"," * reference, but, if there are more, we will have an array. So, the easiest way is to"," * check if what we have is an array, and if it not, create it manually, and iterate it"," * later."," *"," * issue #15: the textareas are now retrieved passing to YUI selector the whole element,"," * instead of the id string, due to problems with special characters."," * See discussion: https://moodle.org/mod/forum/discuss.php?d=332217"," *"," * @method anTagsWithYuiId"," * @private"," */"," _cleanTagsWithYuiId: function() {"," var textareas = Y.all('.editor_atto_content'),"," textarea,"," textareaIndex,"," innerHTML,"," spanedmlangtag,"," index,"," cleanmlangtag,"," regularExpression,"," openingspanwithyui,"," spanedmlangtagsdwithyui,"," mlangtag;",""," openingspanwithyui = OPENING_SPAN.replace('', 'g');",""," if (!textareas instanceof Array) {"," textarea = textareas;"," textareas = [];"," textareas[0] = textarea;"," }"," "," for (textareaIndex = 0; textareaIndex < textareas._nodes.length; textareaIndex++) {"," textarea = textareas._nodes[textareaIndex].id;"," textarea = Y.one(document.getElementById(textarea));",""," innerHTML = textarea.get('innerHTML');",""," spanedmlangtagsdwithyui = innerHTML.match(regularExpression);",""," if (spanedmlangtagsdwithyui === null) {"," continue;"," }"," "," for (index = 0; index < spanedmlangtagsdwithyui.length; index++) {"," spanedmlangtag = spanedmlangtagsdwithyui[index];"," mlangtag = spanedmlangtag.match(/\\{mlang.*?\\}/g)[0];",""," cleanmlangtag = spanedmlangtag.replace(regularExpression, mlangtag);"," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }",""," textarea.set('innerHTML', innerHTML);",""," this.markUpdated();"," }"," },",""," /**"," * Adds the tags to the {mlang} tags when the editor is loaded."," * In this case, we DON'T HAVE TO CALL TO markUpdated(). Why? Honestly,"," * I don't know. But, if we call it after setting the HTML, the {mlang}"," * tags flicker with the decoration, and returns to their original state."," *"," * Instead of taking the HTML directly from the textarea, we have to"," * retrieve it, first, without the tags that can be stored"," * in database, due to a bug in version 2015120501 that stores the"," * {mlang} tags in database, with the tags."," * More info about this bug: https://github.com/julenpardo/moodle-atto_multilang2/issues/8"," *"," * Every different {mlang} tag has to be replaced only once, otherwise,"," * nested s will be created in every repeated replacement. So, we"," * have to have a track of which replacements have been made."," *"," * @method _decorateTagsOnInit"," * @private"," */"," _decorateTagsOnInit: function() {"," var textarea = Y.all('.editor_atto_content'),"," innerHTML,"," regularExpression,"," mlangtags,"," mlangtag,"," index,"," decoratedmlangtag,"," replacementsmade = [],"," notreplacedyet;",""," innerHTML = this._getHTMLwithCleanedTags();",""," regularExpression = new RegExp('{mlang.*?}', 'g');"," mlangtags = innerHTML.match(regularExpression);",""," if (mlangtags !== null) {"," for (index = 0; index < mlangtags.length; index++) {"," mlangtag = mlangtags[index];",""," notreplacedyet = replacementsmade.indexOf(mlangtag) === -1;",""," if (notreplacedyet) {"," replacementsmade.push(mlangtag);",""," decoratedmlangtag = OPENING_SPAN + mlangtag + '';"," regularExpression = new RegExp(mlangtag, 'g');",""," innerHTML = innerHTML.replace(regularExpression, decoratedmlangtag);"," }"," }",""," textarea.set('innerHTML', innerHTML);"," }",""," },",""," /**"," * This function returns the HTML as it is in the textarea, but cleaning every"," * tag around the {mlang} tags. This is necessary for decorating tags on"," * init, because it could happen that in database are stored the {mlang} tags with"," * their tags, due to a bug in version 2015120501."," * More info about this bug: https://github.com/julenpardo/moodle-atto_multilang2/issues/8"," *"," * @method _getHTMLwithCleanedTags"," * @return {string} HTML in textarea, without any around {mlang} tags"," */"," _getHTMLwithCleanedTags: function() {"," var host = this.get('host'),"," innerHTML = host.getCleanHTML(),"," regexString,"," regularExpression,"," spanedmlangtags,"," spanedmlangtag,"," cleanmlangtag,"," index;",""," regexString = OPENING_SPAN + '.*?' + '';"," regularExpression = new RegExp(regexString, 'g');"," spanedmlangtags = innerHTML.match(regularExpression);",""," if (spanedmlangtags !== null) {"," for (index = 0; index < spanedmlangtags.length; index++) {"," spanedmlangtag = spanedmlangtags[index];",""," cleanmlangtag = spanedmlangtag.replace(OPENING_SPAN, '');"," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }"," }",""," return innerHTML;"," }","","}, {"," ATTRS: {"," /**"," * The list of installed languages."," *"," * @attribute languages"," * @type array"," * @default {\"en\":\"English (en)\"}"," */"," languages: DEFAULT_LANGUAGE,",""," /**"," * If the current user has the capability to use the plugin."," *"," * @attribute capability"," * @type boolean"," * @default true"," */"," capability: DEFAULT_CAPABILITY,",""," /**"," * If the {mlang} tags have to be highlighted or not."," *"," * @property highlight"," * @type boolean"," * @default true"," */"," highlight: DEFAULT_HIGHLIGHT,",""," /**"," * The CSS for delimiters."," *"," * @property css"," * @type string"," * @default DEFAULT_CSS"," */"," css: DEFAULT_CSS"," }","});","","","}, '@VERSION@', {\"requires\": [\"moodle-editor_atto-plugin\"]});","","}());"]}; } var __cov_xlcucJyua6odXhLRctX6xg = __coverage__['build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js']; __cov_xlcucJyua6odXhLRctX6xg.s['1']++;YUI.add('moodle-atto_multilang2-button',function(Y,NAME){__cov_xlcucJyua6odXhLRctX6xg.f['1']++;__cov_xlcucJyua6odXhLRctX6xg.s['2']++;var CLASSES={TAG:'filter-multilang-tag'},LANG_WILDCARD='%lang',CONTENT_WILDCARD='%content',ATTR_LANGUAGES='languages',ATTR_CAPABILITY='capability',ATTR_HIGHLIGHT='highlight',ATTR_CSS='css',DEFAULT_LANGUAGE='{"en":"English (en)"}',DEFAULT_CAPABILITY=true,DEFAULT_HIGHLIGHT=true,DEFAULT_CSS='outline: 1px dotted;'+'padding: 0.1em;'+'margin: 0em 0.1em;'+'background-color: #ffffaa;',TEMPLATES={SPANED:' {mlang '+LANG_WILDCARD+'}'+CONTENT_WILDCARD+'{mlang} ',NOT_SPANED:'{mlang '+LANG_WILDCARD+'}'+CONTENT_WILDCARD+'{mlang}'},OPENING_SPAN='';__cov_xlcucJyua6odXhLRctX6xg.s['3']++;Y.namespace('M.atto_multilang2').Button=Y.Base.create('button',Y.M.editor_atto.EditorPlugin,[],{_highlight:true,_auxiliarSubmitButtonNode:null,initializer:function(){__cov_xlcucJyua6odXhLRctX6xg.f['2']++;__cov_xlcucJyua6odXhLRctX6xg.s['4']++;var hascapability=this.get(ATTR_CAPABILITY),toolbarItems=[];__cov_xlcucJyua6odXhLRctX6xg.s['5']++;if(hascapability){__cov_xlcucJyua6odXhLRctX6xg.b['1'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['6']++;toolbarItems=this._initializeToolbarItems();__cov_xlcucJyua6odXhLRctX6xg.s['7']++;this._highlight=this.get(ATTR_HIGHLIGHT);__cov_xlcucJyua6odXhLRctX6xg.s['8']++;this.addToolbarMenu({globalItemConfig:{callback:this._addTags},icon:'icon',iconComponent:'atto_multilang2',items:toolbarItems});__cov_xlcucJyua6odXhLRctX6xg.s['9']++;this.get('host').on('atto:selectionchanged',this._checkSelectionChange,this);__cov_xlcucJyua6odXhLRctX6xg.s['10']++;this._addDelimiterCss();__cov_xlcucJyua6odXhLRctX6xg.s['11']++;if(this._highlight){__cov_xlcucJyua6odXhLRctX6xg.b['2'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['12']++;this._decorateTagsOnInit();__cov_xlcucJyua6odXhLRctX6xg.s['13']++;this._setSubmitListeners();}else{__cov_xlcucJyua6odXhLRctX6xg.b['2'][1]++;}}else{__cov_xlcucJyua6odXhLRctX6xg.b['1'][1]++;}},_addDelimiterCss:function(){__cov_xlcucJyua6odXhLRctX6xg.f['3']++;__cov_xlcucJyua6odXhLRctX6xg.s['14']++;var css='.'+CLASSES.TAG+'{'+this.get(ATTR_CSS)+'}',style;__cov_xlcucJyua6odXhLRctX6xg.s['15']++;style=document.createElement('style');__cov_xlcucJyua6odXhLRctX6xg.s['16']++;style.type='text/css';__cov_xlcucJyua6odXhLRctX6xg.s['17']++;style.innerHTML=css;__cov_xlcucJyua6odXhLRctX6xg.s['18']++;document.head.appendChild(style);},_initializeToolbarItems:function(){__cov_xlcucJyua6odXhLRctX6xg.f['4']++;__cov_xlcucJyua6odXhLRctX6xg.s['19']++;var toolbarItems=[],languages,langCode;__cov_xlcucJyua6odXhLRctX6xg.s['20']++;languages=JSON.parse(this.get(ATTR_LANGUAGES));__cov_xlcucJyua6odXhLRctX6xg.s['21']++;for(langCode in languages){__cov_xlcucJyua6odXhLRctX6xg.s['22']++;if(languages.hasOwnProperty(langCode)){__cov_xlcucJyua6odXhLRctX6xg.b['3'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['23']++;toolbarItems.push({text:languages[langCode],callbackArgs:langCode});}else{__cov_xlcucJyua6odXhLRctX6xg.b['3'][1]++;}}__cov_xlcucJyua6odXhLRctX6xg.s['24']++;return toolbarItems;},_addTags:function(e,langCode){__cov_xlcucJyua6odXhLRctX6xg.f['5']++;__cov_xlcucJyua6odXhLRctX6xg.s['25']++;var selection,host=this.get('host'),taggedContent,content;__cov_xlcucJyua6odXhLRctX6xg.s['26']++;taggedContent=this._highlight?(__cov_xlcucJyua6odXhLRctX6xg.b['4'][0]++,TEMPLATES.SPANED):(__cov_xlcucJyua6odXhLRctX6xg.b['4'][1]++,TEMPLATES.NOT_SPANED);__cov_xlcucJyua6odXhLRctX6xg.s['27']++;selection=this._getSelectionHTML();__cov_xlcucJyua6odXhLRctX6xg.s['28']++;content=host.getSelection().toString().length===0?(__cov_xlcucJyua6odXhLRctX6xg.b['5'][0]++,' '):(__cov_xlcucJyua6odXhLRctX6xg.b['5'][1]++,selection);__cov_xlcucJyua6odXhLRctX6xg.s['29']++;taggedContent=taggedContent.replace(LANG_WILDCARD,langCode);__cov_xlcucJyua6odXhLRctX6xg.s['30']++;taggedContent=taggedContent.replace(CONTENT_WILDCARD,content);__cov_xlcucJyua6odXhLRctX6xg.s['31']++;host.insertContentAtFocusPoint(taggedContent);__cov_xlcucJyua6odXhLRctX6xg.s['32']++;this.markUpdated();},_getSelectionHTML:function(){__cov_xlcucJyua6odXhLRctX6xg.f['6']++;__cov_xlcucJyua6odXhLRctX6xg.s['33']++;var html='',selection,container,index,lenght;__cov_xlcucJyua6odXhLRctX6xg.s['34']++;if(typeof window.getSelection!=='undefined'){__cov_xlcucJyua6odXhLRctX6xg.b['6'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['35']++;selection=window.getSelection();__cov_xlcucJyua6odXhLRctX6xg.s['36']++;if(selection.rangeCount){__cov_xlcucJyua6odXhLRctX6xg.b['7'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['37']++;container=document.createElement('div');__cov_xlcucJyua6odXhLRctX6xg.s['38']++;for(index=0,lenght=selection.rangeCount;index-1;__cov_xlcucJyua6odXhLRctX6xg.s['47']++;isLangTag=nodeValue.match(/\{mlang/g).length===1;__cov_xlcucJyua6odXhLRctX6xg.s['48']++;if((__cov_xlcucJyua6odXhLRctX6xg.b['11'][0]++,isTextNode)&&(__cov_xlcucJyua6odXhLRctX6xg.b['11'][1]++,isLangTag)){__cov_xlcucJyua6odXhLRctX6xg.b['10'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['49']++;host.setSelection(host.getSelectionFromNode(Y.one(node)));}else{__cov_xlcucJyua6odXhLRctX6xg.b['10'][1]++;}},_setSubmitListeners:function(){__cov_xlcucJyua6odXhLRctX6xg.f['8']++;__cov_xlcucJyua6odXhLRctX6xg.s['50']++;var submitButtons=Y.all('input[type=submit]');__cov_xlcucJyua6odXhLRctX6xg.s['51']++;submitButtons.each(this._addListenerToSubmitButtons,this);},_addListenerToSubmitButtons:function(buttonNode){__cov_xlcucJyua6odXhLRctX6xg.f['9']++;__cov_xlcucJyua6odXhLRctX6xg.s['52']++;var buttonObject,className,parentFormClassName,notCancelButton,notSearchButton;__cov_xlcucJyua6odXhLRctX6xg.s['53']++;buttonObject=document.getElementById(buttonNode.get('id'));__cov_xlcucJyua6odXhLRctX6xg.s['54']++;if(buttonObject!==null){__cov_xlcucJyua6odXhLRctX6xg.b['12'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['55']++;className=buttonObject.className;__cov_xlcucJyua6odXhLRctX6xg.s['56']++;parentFormClassName=buttonObject.form.className;__cov_xlcucJyua6odXhLRctX6xg.s['57']++;notCancelButton=className.match(/btn-cancel/g)===null;__cov_xlcucJyua6odXhLRctX6xg.s['58']++;notSearchButton=parentFormClassName.match(/mform/g).length>0;__cov_xlcucJyua6odXhLRctX6xg.s['59']++;if((__cov_xlcucJyua6odXhLRctX6xg.b['14'][0]++,notCancelButton)&&(__cov_xlcucJyua6odXhLRctX6xg.b['14'][1]++,notSearchButton)){__cov_xlcucJyua6odXhLRctX6xg.b['13'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['60']++;this._auxiliarSubmitButtonNode=buttonNode;__cov_xlcucJyua6odXhLRctX6xg.s['61']++;buttonNode.on('click',this._cleanTagsOnSubmit,this);}else{__cov_xlcucJyua6odXhLRctX6xg.b['13'][1]++;}}else{__cov_xlcucJyua6odXhLRctX6xg.b['12'][1]++;}},_cleanTagsOnSubmit:function(e){__cov_xlcucJyua6odXhLRctX6xg.f['10']++;__cov_xlcucJyua6odXhLRctX6xg.s['62']++;var submitButton;__cov_xlcucJyua6odXhLRctX6xg.s['63']++;e.preventDefault();__cov_xlcucJyua6odXhLRctX6xg.s['64']++;submitButton=Y.one(this._auxiliarSubmitButtonNode);__cov_xlcucJyua6odXhLRctX6xg.s['65']++;this._cleanTagsWithNoYuiId();__cov_xlcucJyua6odXhLRctX6xg.s['66']++;this._cleanTagsWithYuiId();__cov_xlcucJyua6odXhLRctX6xg.s['67']++;submitButton.detach('click',this._cleanTagsOnSubmit);__cov_xlcucJyua6odXhLRctX6xg.s['68']++;submitButton.simulate('click');},_cleanTagsWithNoYuiId:function(){__cov_xlcucJyua6odXhLRctX6xg.f['11']++;__cov_xlcucJyua6odXhLRctX6xg.s['69']++;var textareas=Y.all('.editor_atto_content'),textarea,textareaIndex,innerHTML,spanedmlangtags,spanedmlangtag,index,cleanmlangtag,regularExpression;__cov_xlcucJyua6odXhLRctX6xg.s['70']++;regularExpression=new RegExp(OPENING_SPAN+'.*?'+'','g');__cov_xlcucJyua6odXhLRctX6xg.s['71']++;if(!textareas instanceof Array){__cov_xlcucJyua6odXhLRctX6xg.b['15'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['72']++;textarea=textareas;__cov_xlcucJyua6odXhLRctX6xg.s['73']++;textareas=[];__cov_xlcucJyua6odXhLRctX6xg.s['74']++;textareas[0]=textarea;}else{__cov_xlcucJyua6odXhLRctX6xg.b['15'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['75']++;for(textareaIndex=0;textareaIndex','');__cov_xlcucJyua6odXhLRctX6xg.s['86']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}__cov_xlcucJyua6odXhLRctX6xg.s['87']++;textarea.set('innerHTML',innerHTML);}__cov_xlcucJyua6odXhLRctX6xg.s['88']++;this.markUpdated();},_cleanTagsWithYuiId:function(){__cov_xlcucJyua6odXhLRctX6xg.f['12']++;__cov_xlcucJyua6odXhLRctX6xg.s['89']++;var textareas=Y.all('.editor_atto_content'),textarea,textareaIndex,innerHTML,spanedmlangtag,index,cleanmlangtag,regularExpression,openingspanwithyui,spanedmlangtagsdwithyui,mlangtag;__cov_xlcucJyua6odXhLRctX6xg.s['90']++;openingspanwithyui=OPENING_SPAN.replace('','g');__cov_xlcucJyua6odXhLRctX6xg.s['92']++;if(!textareas instanceof Array){__cov_xlcucJyua6odXhLRctX6xg.b['17'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['93']++;textarea=textareas;__cov_xlcucJyua6odXhLRctX6xg.s['94']++;textareas=[];__cov_xlcucJyua6odXhLRctX6xg.s['95']++;textareas[0]=textarea;}else{__cov_xlcucJyua6odXhLRctX6xg.b['17'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['96']++;for(textareaIndex=0;textareaIndex','');__cov_xlcucJyua6odXhLRctX6xg.s['108']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}__cov_xlcucJyua6odXhLRctX6xg.s['109']++;textarea.set('innerHTML',innerHTML);__cov_xlcucJyua6odXhLRctX6xg.s['110']++;this.markUpdated();}},_decorateTagsOnInit:function(){__cov_xlcucJyua6odXhLRctX6xg.f['13']++;__cov_xlcucJyua6odXhLRctX6xg.s['111']++;var textarea=Y.all('.editor_atto_content'),innerHTML,regularExpression,mlangtags,mlangtag,index,decoratedmlangtag,replacementsmade=[],notreplacedyet;__cov_xlcucJyua6odXhLRctX6xg.s['112']++;innerHTML=this._getHTMLwithCleanedTags();__cov_xlcucJyua6odXhLRctX6xg.s['113']++;regularExpression=new RegExp('{mlang.*?}','g');__cov_xlcucJyua6odXhLRctX6xg.s['114']++;mlangtags=innerHTML.match(regularExpression);__cov_xlcucJyua6odXhLRctX6xg.s['115']++;if(mlangtags!==null){__cov_xlcucJyua6odXhLRctX6xg.b['19'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['116']++;for(index=0;index';__cov_xlcucJyua6odXhLRctX6xg.s['122']++;regularExpression=new RegExp(mlangtag,'g');__cov_xlcucJyua6odXhLRctX6xg.s['123']++;innerHTML=innerHTML.replace(regularExpression,decoratedmlangtag);}else{__cov_xlcucJyua6odXhLRctX6xg.b['20'][1]++;}}__cov_xlcucJyua6odXhLRctX6xg.s['124']++;textarea.set('innerHTML',innerHTML);}else{__cov_xlcucJyua6odXhLRctX6xg.b['19'][1]++;}},_getHTMLwithCleanedTags:function(){__cov_xlcucJyua6odXhLRctX6xg.f['14']++;__cov_xlcucJyua6odXhLRctX6xg.s['125']++;var host=this.get('host'),innerHTML=host.getCleanHTML(),regexString,regularExpression,spanedmlangtags,spanedmlangtag,cleanmlangtag,index;__cov_xlcucJyua6odXhLRctX6xg.s['126']++;regexString=OPENING_SPAN+'.*?'+'';__cov_xlcucJyua6odXhLRctX6xg.s['127']++;regularExpression=new RegExp(regexString,'g');__cov_xlcucJyua6odXhLRctX6xg.s['128']++;spanedmlangtags=innerHTML.match(regularExpression);__cov_xlcucJyua6odXhLRctX6xg.s['129']++;if(spanedmlangtags!==null){__cov_xlcucJyua6odXhLRctX6xg.b['21'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['130']++;for(index=0;index','');__cov_xlcucJyua6odXhLRctX6xg.s['134']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}}else{__cov_xlcucJyua6odXhLRctX6xg.b['21'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['135']++;return innerHTML;}},{ATTRS:{languages:DEFAULT_LANGUAGE,capability:DEFAULT_CAPABILITY,highlight:DEFAULT_HIGHLIGHT,css:DEFAULT_CSS}});},'@VERSION@',{'requires':['moodle-editor_atto-plugin']}); diff --git a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-debug.js b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-debug.js index 0aa97a3..9deb971 100644 --- a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-debug.js +++ b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-debug.js @@ -70,6 +70,14 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att */ _highlight: true, + /** + * Used as "indirect argument" to function "_cleanTagsOnSubmit", since there is not + * any (apparent) way to pass arguments to YUI callback functions. + * + * @property _auxiliarSubmitButton + * @type Node + * @private + */ _auxiliarSubmitButtonNode: null, initializer: function() { @@ -237,14 +245,11 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att }, /** - * Sets the submit listener to the function that finds the spaned {mlang} tags. - * - * In some forms, there may be two different submit buttons, so we add the listener - * to the second, if this exists. + * Retrieves the inputs of type submit, and, for each element, calls the function + * that sets the submit listener. Is not made in this function because there is + * not any (apparent) way to access class scope from YUI closure. * - * These submit listeners are set only if the "highlight" plugin setting is checked. - * - * @method _setSubmitListener + * @method _setSubmitListeners * @private */ _setSubmitListeners: function() { @@ -253,6 +258,18 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att submitButtons.each(this._addListenerToSubmitButtons, this); }, + /** + * Adds the clean tags submit listener of each input[type="submit"], but only if + * it's not 'cancel' type, and if its parent form is of 'mform' class, because there + * may be any other submit type (such us administrator's search button). + * + * The button node to add the listener is passed as global property because there is + * no (apparent) way to pass arguments to YUI callback functions. + * + * @method _addListenerToSubmitButtons + * @param {Node} buttonNode + * @private + */ _addListenerToSubmitButtons: function(buttonNode) { var buttonObject, className, @@ -276,6 +293,20 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att } }, + /** + * When submit button clicked, this function is invoked. It has to stop the submission, + * in order to process the textarea to clean the tags. + * + * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default, + * an then simulates the click, to submit the form. + * + * The clicked submit button ('save and return' or 'save and display'), is accessed globally, + * in '_auxiliarSubmitButtonNode' property, set by '_addListenerToSubmitButtons' function. + * + * @method _cleanTagsOnSubmit + * @param {EventFacade} e + * @private + */ _cleanTagsOnSubmit: function(e) { var submitButton; diff --git a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js index 0aa97a3..9deb971 100644 --- a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js +++ b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js @@ -70,6 +70,14 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att */ _highlight: true, + /** + * Used as "indirect argument" to function "_cleanTagsOnSubmit", since there is not + * any (apparent) way to pass arguments to YUI callback functions. + * + * @property _auxiliarSubmitButton + * @type Node + * @private + */ _auxiliarSubmitButtonNode: null, initializer: function() { @@ -237,14 +245,11 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att }, /** - * Sets the submit listener to the function that finds the spaned {mlang} tags. - * - * In some forms, there may be two different submit buttons, so we add the listener - * to the second, if this exists. + * Retrieves the inputs of type submit, and, for each element, calls the function + * that sets the submit listener. Is not made in this function because there is + * not any (apparent) way to access class scope from YUI closure. * - * These submit listeners are set only if the "highlight" plugin setting is checked. - * - * @method _setSubmitListener + * @method _setSubmitListeners * @private */ _setSubmitListeners: function() { @@ -253,6 +258,18 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att submitButtons.each(this._addListenerToSubmitButtons, this); }, + /** + * Adds the clean tags submit listener of each input[type="submit"], but only if + * it's not 'cancel' type, and if its parent form is of 'mform' class, because there + * may be any other submit type (such us administrator's search button). + * + * The button node to add the listener is passed as global property because there is + * no (apparent) way to pass arguments to YUI callback functions. + * + * @method _addListenerToSubmitButtons + * @param {Node} buttonNode + * @private + */ _addListenerToSubmitButtons: function(buttonNode) { var buttonObject, className, @@ -276,6 +293,20 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att } }, + /** + * When submit button clicked, this function is invoked. It has to stop the submission, + * in order to process the textarea to clean the tags. + * + * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default, + * an then simulates the click, to submit the form. + * + * The clicked submit button ('save and return' or 'save and display'), is accessed globally, + * in '_auxiliarSubmitButtonNode' property, set by '_addListenerToSubmitButtons' function. + * + * @method _cleanTagsOnSubmit + * @param {EventFacade} e + * @private + */ _cleanTagsOnSubmit: function(e) { var submitButton; diff --git a/yui/src/button/js/button.js b/yui/src/button/js/button.js index c32506b..592339a 100644 --- a/yui/src/button/js/button.js +++ b/yui/src/button/js/button.js @@ -68,6 +68,14 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att */ _highlight: true, + /** + * Used as "indirect argument" to function "_cleanTagsOnSubmit", since there is not + * any (apparent) way to pass arguments to YUI callback functions. + * + * @property _auxiliarSubmitButton + * @type Node + * @private + */ _auxiliarSubmitButtonNode: null, initializer: function() { @@ -235,14 +243,11 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att }, /** - * Sets the submit listener to the function that finds the spaned {mlang} tags. - * - * In some forms, there may be two different submit buttons, so we add the listener - * to the second, if this exists. + * Retrieves the inputs of type submit, and, for each element, calls the function + * that sets the submit listener. Is not made in this function because there is + * not any (apparent) way to access class scope from YUI closure. * - * These submit listeners are set only if the "highlight" plugin setting is checked. - * - * @method _setSubmitListener + * @method _setSubmitListeners * @private */ _setSubmitListeners: function() { @@ -251,6 +256,18 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att submitButtons.each(this._addListenerToSubmitButtons, this); }, + /** + * Adds the clean tags submit listener of each input[type="submit"], but only if + * it's not 'cancel' type, and if its parent form is of 'mform' class, because there + * may be any other submit type (such us administrator's search button). + * + * The button node to add the listener is passed as global property because there is + * no (apparent) way to pass arguments to YUI callback functions. + * + * @method _addListenerToSubmitButtons + * @param {Node} buttonNode + * @private + */ _addListenerToSubmitButtons: function(buttonNode) { var buttonObject, className, @@ -274,6 +291,20 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att } }, + /** + * When submit button clicked, this function is invoked. It has to stop the submission, + * in order to process the textarea to clean the tags. + * + * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default, + * an then simulates the click, to submit the form. + * + * The clicked submit button ('save and return' or 'save and display'), is accessed globally, + * in '_auxiliarSubmitButtonNode' property, set by '_addListenerToSubmitButtons' function. + * + * @method _cleanTagsOnSubmit + * @param {EventFacade} e + * @private + */ _cleanTagsOnSubmit: function(e) { var submitButton; From 56c6c4404bc2a54751c02a614fe3e246ceabc76e Mon Sep 17 00:00:00 2001 From: Julen Pardo Date: Wed, 25 May 2016 13:21:46 +0200 Subject: [PATCH 6/7] issue #17: fix submissions when more than one submit button exists, passing the button node as parameter --- .../moodle-atto_multilang2-button-coverage.js | 4 +-- .../moodle-atto_multilang2-button-debug.js | 36 +++++-------------- .../moodle-atto_multilang2-button-min.js | 2 +- .../moodle-atto_multilang2-button.js | 36 +++++-------------- yui/src/button/js/button.js | 36 +++++-------------- 5 files changed, 27 insertions(+), 87 deletions(-) diff --git a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-coverage.js b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-coverage.js index 0a0e413..8aa9f76 100644 --- a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-coverage.js +++ b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-coverage.js @@ -1,6 +1,6 @@ if (typeof __coverage__ === 'undefined') { __coverage__ = {}; } if (!__coverage__['build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js']) { - __coverage__['build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js'] = {"path":"build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0,"100":0,"101":0,"102":0,"103":0,"104":0,"105":0,"106":0,"107":0,"108":0,"109":0,"110":0,"111":0,"112":0,"113":0,"114":0,"115":0,"116":0,"117":0,"118":0,"119":0,"120":0,"121":0,"122":0,"123":0,"124":0,"125":0,"126":0,"127":0,"128":0,"129":0,"130":0,"131":0,"132":0,"133":0,"134":0,"135":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0],"14":[0,0],"15":[0,0],"16":[0,0],"17":[0,0],"18":[0,0],"19":[0,0],"20":[0,0],"21":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0},"fnMap":{"1":{"name":"(anonymous_1)","line":1,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":60}}},"2":{"name":"(anonymous_2)","line":83,"loc":{"start":{"line":83,"column":17},"end":{"line":83,"column":28}}},"3":{"name":"(anonymous_3)","line":117,"loc":{"start":{"line":117,"column":22},"end":{"line":117,"column":33}}},"4":{"name":"(anonymous_4)","line":136,"loc":{"start":{"line":136,"column":29},"end":{"line":136,"column":40}}},"5":{"name":"(anonymous_5)","line":171,"loc":{"start":{"line":171,"column":14},"end":{"line":171,"column":36}}},"6":{"name":"(anonymous_6)","line":198,"loc":{"start":{"line":198,"column":23},"end":{"line":198,"column":34}}},"7":{"name":"(anonymous_7)","line":232,"loc":{"start":{"line":232,"column":27},"end":{"line":232,"column":38}}},"8":{"name":"(anonymous_8)","line":255,"loc":{"start":{"line":255,"column":25},"end":{"line":255,"column":36}}},"9":{"name":"(anonymous_9)","line":273,"loc":{"start":{"line":273,"column":33},"end":{"line":273,"column":54}}},"10":{"name":"(anonymous_10)","line":310,"loc":{"start":{"line":310,"column":24},"end":{"line":310,"column":36}}},"11":{"name":"(anonymous_11)","line":343,"loc":{"start":{"line":343,"column":27},"end":{"line":343,"column":38}}},"12":{"name":"(anonymous_12)","line":408,"loc":{"start":{"line":408,"column":26},"end":{"line":408,"column":37}}},"13":{"name":"(anonymous_13)","line":477,"loc":{"start":{"line":477,"column":25},"end":{"line":477,"column":36}}},"14":{"name":"(anonymous_14)","line":524,"loc":{"start":{"line":524,"column":29},"end":{"line":524,"column":40}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":593,"column":61}},"2":{"start":{"line":28,"column":0},"end":{"line":52,"column":56}},"3":{"start":{"line":62,"column":0},"end":{"line":590,"column":3}},"4":{"start":{"line":84,"column":8},"end":{"line":85,"column":30}},"5":{"start":{"line":87,"column":8},"end":{"line":108,"column":9}},"6":{"start":{"line":88,"column":12},"end":{"line":88,"column":58}},"7":{"start":{"line":89,"column":12},"end":{"line":89,"column":55}},"8":{"start":{"line":91,"column":12},"end":{"line":98,"column":15}},"9":{"start":{"line":100,"column":12},"end":{"line":100,"column":91}},"10":{"start":{"line":102,"column":12},"end":{"line":102,"column":36}},"11":{"start":{"line":104,"column":12},"end":{"line":107,"column":13}},"12":{"start":{"line":105,"column":16},"end":{"line":105,"column":43}},"13":{"start":{"line":106,"column":16},"end":{"line":106,"column":43}},"14":{"start":{"line":118,"column":8},"end":{"line":119,"column":18}},"15":{"start":{"line":121,"column":8},"end":{"line":121,"column":48}},"16":{"start":{"line":122,"column":8},"end":{"line":122,"column":32}},"17":{"start":{"line":123,"column":8},"end":{"line":123,"column":30}},"18":{"start":{"line":125,"column":8},"end":{"line":125,"column":41}},"19":{"start":{"line":137,"column":8},"end":{"line":139,"column":21}},"20":{"start":{"line":141,"column":8},"end":{"line":141,"column":57}},"21":{"start":{"line":143,"column":8},"end":{"line":150,"column":9}},"22":{"start":{"line":144,"column":12},"end":{"line":149,"column":13}},"23":{"start":{"line":145,"column":16},"end":{"line":148,"column":19}},"24":{"start":{"line":152,"column":8},"end":{"line":152,"column":28}},"25":{"start":{"line":172,"column":8},"end":{"line":175,"column":20}},"26":{"start":{"line":177,"column":8},"end":{"line":177,"column":84}},"27":{"start":{"line":179,"column":8},"end":{"line":179,"column":45}},"28":{"start":{"line":180,"column":8},"end":{"line":180,"column":87}},"29":{"start":{"line":182,"column":8},"end":{"line":182,"column":71}},"30":{"start":{"line":183,"column":8},"end":{"line":183,"column":73}},"31":{"start":{"line":185,"column":8},"end":{"line":185,"column":54}},"32":{"start":{"line":187,"column":8},"end":{"line":187,"column":27}},"33":{"start":{"line":199,"column":8},"end":{"line":203,"column":19}},"34":{"start":{"line":205,"column":8},"end":{"line":220,"column":9}},"35":{"start":{"line":206,"column":12},"end":{"line":206,"column":46}},"36":{"start":{"line":208,"column":12},"end":{"line":214,"column":13}},"37":{"start":{"line":209,"column":16},"end":{"line":209,"column":58}},"38":{"start":{"line":210,"column":16},"end":{"line":212,"column":17}},"39":{"start":{"line":211,"column":20},"end":{"line":211,"column":87}},"40":{"start":{"line":213,"column":16},"end":{"line":213,"column":43}},"41":{"start":{"line":216,"column":15},"end":{"line":220,"column":9}},"42":{"start":{"line":217,"column":12},"end":{"line":219,"column":13}},"43":{"start":{"line":218,"column":16},"end":{"line":218,"column":65}},"44":{"start":{"line":222,"column":8},"end":{"line":222,"column":20}},"45":{"start":{"line":233,"column":8},"end":{"line":237,"column":22}},"46":{"start":{"line":239,"column":8},"end":{"line":239,"column":67}},"47":{"start":{"line":240,"column":8},"end":{"line":240,"column":63}},"48":{"start":{"line":242,"column":8},"end":{"line":244,"column":9}},"49":{"start":{"line":243,"column":12},"end":{"line":243,"column":70}},"50":{"start":{"line":256,"column":8},"end":{"line":256,"column":56}},"51":{"start":{"line":258,"column":8},"end":{"line":258,"column":67}},"52":{"start":{"line":274,"column":8},"end":{"line":278,"column":28}},"53":{"start":{"line":280,"column":8},"end":{"line":280,"column":69}},"54":{"start":{"line":282,"column":8},"end":{"line":293,"column":9}},"55":{"start":{"line":283,"column":12},"end":{"line":283,"column":47}},"56":{"start":{"line":284,"column":12},"end":{"line":284,"column":62}},"57":{"start":{"line":286,"column":12},"end":{"line":286,"column":70}},"58":{"start":{"line":287,"column":12},"end":{"line":287,"column":77}},"59":{"start":{"line":289,"column":12},"end":{"line":292,"column":13}},"60":{"start":{"line":290,"column":16},"end":{"line":290,"column":60}},"61":{"start":{"line":291,"column":16},"end":{"line":291,"column":70}},"62":{"start":{"line":311,"column":8},"end":{"line":311,"column":25}},"63":{"start":{"line":313,"column":8},"end":{"line":313,"column":27}},"64":{"start":{"line":315,"column":8},"end":{"line":315,"column":61}},"65":{"start":{"line":317,"column":8},"end":{"line":317,"column":37}},"66":{"start":{"line":318,"column":8},"end":{"line":318,"column":35}},"67":{"start":{"line":320,"column":8},"end":{"line":320,"column":62}},"68":{"start":{"line":321,"column":8},"end":{"line":321,"column":39}},"69":{"start":{"line":344,"column":8},"end":{"line":352,"column":30}},"70":{"start":{"line":354,"column":8},"end":{"line":354,"column":78}},"71":{"start":{"line":356,"column":8},"end":{"line":360,"column":9}},"72":{"start":{"line":357,"column":12},"end":{"line":357,"column":33}},"73":{"start":{"line":358,"column":12},"end":{"line":358,"column":27}},"74":{"start":{"line":359,"column":12},"end":{"line":359,"column":36}},"75":{"start":{"line":362,"column":8},"end":{"line":384,"column":9}},"76":{"start":{"line":363,"column":12},"end":{"line":363,"column":58}},"77":{"start":{"line":364,"column":12},"end":{"line":364,"column":64}},"78":{"start":{"line":366,"column":12},"end":{"line":366,"column":50}},"79":{"start":{"line":368,"column":12},"end":{"line":368,"column":65}},"80":{"start":{"line":370,"column":12},"end":{"line":372,"column":13}},"81":{"start":{"line":371,"column":16},"end":{"line":371,"column":25}},"82":{"start":{"line":374,"column":12},"end":{"line":381,"column":13}},"83":{"start":{"line":375,"column":16},"end":{"line":375,"column":56}},"84":{"start":{"line":376,"column":16},"end":{"line":376,"column":73}},"85":{"start":{"line":378,"column":16},"end":{"line":378,"column":69}},"86":{"start":{"line":380,"column":16},"end":{"line":380,"column":77}},"87":{"start":{"line":383,"column":12},"end":{"line":383,"column":49}},"88":{"start":{"line":386,"column":8},"end":{"line":386,"column":27}},"89":{"start":{"line":409,"column":8},"end":{"line":419,"column":21}},"90":{"start":{"line":421,"column":8},"end":{"line":421,"column":81}},"91":{"start":{"line":422,"column":8},"end":{"line":422,"column":89}},"92":{"start":{"line":424,"column":8},"end":{"line":428,"column":9}},"93":{"start":{"line":425,"column":12},"end":{"line":425,"column":33}},"94":{"start":{"line":426,"column":12},"end":{"line":426,"column":27}},"95":{"start":{"line":427,"column":12},"end":{"line":427,"column":36}},"96":{"start":{"line":430,"column":8},"end":{"line":455,"column":9}},"97":{"start":{"line":431,"column":12},"end":{"line":431,"column":58}},"98":{"start":{"line":432,"column":12},"end":{"line":432,"column":64}},"99":{"start":{"line":434,"column":12},"end":{"line":434,"column":50}},"100":{"start":{"line":436,"column":12},"end":{"line":436,"column":73}},"101":{"start":{"line":438,"column":12},"end":{"line":440,"column":13}},"102":{"start":{"line":439,"column":16},"end":{"line":439,"column":25}},"103":{"start":{"line":442,"column":12},"end":{"line":450,"column":13}},"104":{"start":{"line":443,"column":16},"end":{"line":443,"column":64}},"105":{"start":{"line":444,"column":16},"end":{"line":444,"column":68}},"106":{"start":{"line":446,"column":16},"end":{"line":446,"column":84}},"107":{"start":{"line":447,"column":16},"end":{"line":447,"column":69}},"108":{"start":{"line":449,"column":16},"end":{"line":449,"column":77}},"109":{"start":{"line":452,"column":12},"end":{"line":452,"column":49}},"110":{"start":{"line":454,"column":12},"end":{"line":454,"column":31}},"111":{"start":{"line":478,"column":8},"end":{"line":486,"column":27}},"112":{"start":{"line":488,"column":8},"end":{"line":488,"column":51}},"113":{"start":{"line":490,"column":8},"end":{"line":490,"column":58}},"114":{"start":{"line":491,"column":8},"end":{"line":491,"column":55}},"115":{"start":{"line":493,"column":8},"end":{"line":510,"column":9}},"116":{"start":{"line":494,"column":12},"end":{"line":507,"column":13}},"117":{"start":{"line":495,"column":16},"end":{"line":495,"column":44}},"118":{"start":{"line":497,"column":16},"end":{"line":497,"column":75}},"119":{"start":{"line":499,"column":16},"end":{"line":506,"column":17}},"120":{"start":{"line":500,"column":20},"end":{"line":500,"column":52}},"121":{"start":{"line":502,"column":20},"end":{"line":502,"column":76}},"122":{"start":{"line":503,"column":20},"end":{"line":503,"column":66}},"123":{"start":{"line":505,"column":20},"end":{"line":505,"column":88}},"124":{"start":{"line":509,"column":12},"end":{"line":509,"column":49}},"125":{"start":{"line":525,"column":8},"end":{"line":532,"column":18}},"126":{"start":{"line":534,"column":8},"end":{"line":534,"column":55}},"127":{"start":{"line":535,"column":8},"end":{"line":535,"column":57}},"128":{"start":{"line":536,"column":8},"end":{"line":536,"column":61}},"129":{"start":{"line":538,"column":8},"end":{"line":547,"column":9}},"130":{"start":{"line":539,"column":12},"end":{"line":546,"column":13}},"131":{"start":{"line":540,"column":16},"end":{"line":540,"column":56}},"132":{"start":{"line":542,"column":16},"end":{"line":542,"column":73}},"133":{"start":{"line":543,"column":16},"end":{"line":543,"column":69}},"134":{"start":{"line":545,"column":16},"end":{"line":545,"column":77}},"135":{"start":{"line":549,"column":8},"end":{"line":549,"column":25}}},"branchMap":{"1":{"line":87,"type":"if","locations":[{"start":{"line":87,"column":8},"end":{"line":87,"column":8}},{"start":{"line":87,"column":8},"end":{"line":87,"column":8}}]},"2":{"line":104,"type":"if","locations":[{"start":{"line":104,"column":12},"end":{"line":104,"column":12}},{"start":{"line":104,"column":12},"end":{"line":104,"column":12}}]},"3":{"line":144,"type":"if","locations":[{"start":{"line":144,"column":12},"end":{"line":144,"column":12}},{"start":{"line":144,"column":12},"end":{"line":144,"column":12}}]},"4":{"line":177,"type":"cond-expr","locations":[{"start":{"line":177,"column":44},"end":{"line":177,"column":60}},{"start":{"line":177,"column":63},"end":{"line":177,"column":83}}]},"5":{"line":180,"type":"cond-expr","locations":[{"start":{"line":180,"column":66},"end":{"line":180,"column":74}},{"start":{"line":180,"column":77},"end":{"line":180,"column":86}}]},"6":{"line":205,"type":"if","locations":[{"start":{"line":205,"column":8},"end":{"line":205,"column":8}},{"start":{"line":205,"column":8},"end":{"line":205,"column":8}}]},"7":{"line":208,"type":"if","locations":[{"start":{"line":208,"column":12},"end":{"line":208,"column":12}},{"start":{"line":208,"column":12},"end":{"line":208,"column":12}}]},"8":{"line":216,"type":"if","locations":[{"start":{"line":216,"column":15},"end":{"line":216,"column":15}},{"start":{"line":216,"column":15},"end":{"line":216,"column":15}}]},"9":{"line":217,"type":"if","locations":[{"start":{"line":217,"column":12},"end":{"line":217,"column":12}},{"start":{"line":217,"column":12},"end":{"line":217,"column":12}}]},"10":{"line":242,"type":"if","locations":[{"start":{"line":242,"column":8},"end":{"line":242,"column":8}},{"start":{"line":242,"column":8},"end":{"line":242,"column":8}}]},"11":{"line":242,"type":"binary-expr","locations":[{"start":{"line":242,"column":12},"end":{"line":242,"column":22}},{"start":{"line":242,"column":26},"end":{"line":242,"column":35}}]},"12":{"line":282,"type":"if","locations":[{"start":{"line":282,"column":8},"end":{"line":282,"column":8}},{"start":{"line":282,"column":8},"end":{"line":282,"column":8}}]},"13":{"line":289,"type":"if","locations":[{"start":{"line":289,"column":12},"end":{"line":289,"column":12}},{"start":{"line":289,"column":12},"end":{"line":289,"column":12}}]},"14":{"line":289,"type":"binary-expr","locations":[{"start":{"line":289,"column":16},"end":{"line":289,"column":31}},{"start":{"line":289,"column":35},"end":{"line":289,"column":50}}]},"15":{"line":356,"type":"if","locations":[{"start":{"line":356,"column":8},"end":{"line":356,"column":8}},{"start":{"line":356,"column":8},"end":{"line":356,"column":8}}]},"16":{"line":370,"type":"if","locations":[{"start":{"line":370,"column":12},"end":{"line":370,"column":12}},{"start":{"line":370,"column":12},"end":{"line":370,"column":12}}]},"17":{"line":424,"type":"if","locations":[{"start":{"line":424,"column":8},"end":{"line":424,"column":8}},{"start":{"line":424,"column":8},"end":{"line":424,"column":8}}]},"18":{"line":438,"type":"if","locations":[{"start":{"line":438,"column":12},"end":{"line":438,"column":12}},{"start":{"line":438,"column":12},"end":{"line":438,"column":12}}]},"19":{"line":493,"type":"if","locations":[{"start":{"line":493,"column":8},"end":{"line":493,"column":8}},{"start":{"line":493,"column":8},"end":{"line":493,"column":8}}]},"20":{"line":499,"type":"if","locations":[{"start":{"line":499,"column":16},"end":{"line":499,"column":16}},{"start":{"line":499,"column":16},"end":{"line":499,"column":16}}]},"21":{"line":538,"type":"if","locations":[{"start":{"line":538,"column":8},"end":{"line":538,"column":8}},{"start":{"line":538,"column":8},"end":{"line":538,"column":8}}]}},"code":["(function () { YUI.add('moodle-atto_multilang2-button', function (Y, NAME) {","","// This file is part of Moodle - http://moodle.org/","//","// Moodle is free software: you can redistribute it and/or modify","// it under the terms of the GNU General Public License as published by","// the Free Software Foundation, either version 3 of the License, or","// (at your option) any later version.","//","// Moodle is distributed in the hope that it will be useful,","// but WITHOUT ANY WARRANTY; without even the implied warranty of","// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the","// GNU General Public License for more details.","//","// You should have received a copy of the GNU General Public License","// along with Moodle. If not, see .","","/**"," * @package atto_multilang2"," * @copyright 2015 onwards Julen Pardo & Mondragon Unibertsitatea"," * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later"," */","","/**"," * @module moodle-atto_multilang2-button"," */","","var CLASSES = {"," TAG: 'filter-multilang-tag'"," },",""," LANG_WILDCARD = '%lang',"," CONTENT_WILDCARD = '%content',"," ATTR_LANGUAGES = 'languages',"," ATTR_CAPABILITY = 'capability',"," ATTR_HIGHLIGHT = 'highlight',"," ATTR_CSS = 'css',"," DEFAULT_LANGUAGE = '{\"en\":\"English (en)\"}',"," DEFAULT_CAPABILITY = true,"," DEFAULT_HIGHLIGHT = true,"," DEFAULT_CSS = 'outline: 1px dotted;' +"," 'padding: 0.1em;' +"," 'margin: 0em 0.1em;' +"," 'background-color: #ffffaa;',"," TEMPLATES = {"," SPANED: ' {mlang ' + LANG_WILDCARD + '}' +"," CONTENT_WILDCARD +"," '{mlang} ',",""," NOT_SPANED: '{mlang ' + LANG_WILDCARD + '}' + CONTENT_WILDCARD + '{mlang}'"," },"," OPENING_SPAN = '';","","/**"," * Atto text editor multilanguage plugin."," *"," * @namespace M.atto_multilang2"," * @class button"," * @extends M.editor_atto.EditorPlugin"," */","","Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {",""," /**"," * If the {mlang} tags have to be highlighted or not. Received as parameter from lib.php."," *"," * @property _highlight"," * @type boolean"," * @private"," */"," _highlight: true,",""," /**"," * Used as \"indirect argument\" to function \"_cleanTagsOnSubmit\", since there is not"," * any (apparent) way to pass arguments to YUI callback functions."," *"," * @property _auxiliarSubmitButton"," * @type Node"," * @private"," */"," _auxiliarSubmitButtonNode: null,",""," initializer: function() {"," var hascapability = this.get(ATTR_CAPABILITY),"," toolbarItems = [];",""," if (hascapability) {"," toolbarItems = this._initializeToolbarItems();"," this._highlight = this.get(ATTR_HIGHLIGHT);",""," this.addToolbarMenu({"," globalItemConfig: {"," callback: this._addTags"," },"," icon: 'icon',"," iconComponent: 'atto_multilang2',"," items: toolbarItems"," });",""," this.get('host').on('atto:selectionchanged', this._checkSelectionChange, this);",""," this._addDelimiterCss();",""," if (this._highlight) {"," this._decorateTagsOnInit();"," this._setSubmitListeners();"," }"," }"," },",""," /**"," * Adds the CSS rules for the delimiters, received as parameter from lib.php."," *"," * @method _addDelimiterCss"," * @private"," */"," _addDelimiterCss: function() {"," var css = '.' + CLASSES.TAG + '{' + this.get(ATTR_CSS) + '}',"," style;",""," style = document.createElement('style');"," style.type = 'text/css';"," style.innerHTML = css;",""," document.head.appendChild(style);"," },",""," /**"," * Initializes the toolbar items, which will be the installed languages,"," * received as parameter."," *"," * @method _initializeToolbarItems"," * @private"," * @return {Array} installed language strings"," */"," _initializeToolbarItems: function() {"," var toolbarItems = [],"," languages,"," langCode;",""," languages = JSON.parse(this.get(ATTR_LANGUAGES));",""," for (langCode in languages) {"," if (languages.hasOwnProperty(langCode)) {"," toolbarItems.push({"," text: languages[langCode],"," callbackArgs: langCode"," });"," }"," }",""," return toolbarItems;"," },",""," /**"," * Retrieves the selected text, wraps it with the multilang tags,"," * and replaces the selected text in the editor with with it."," *"," * If the 'highlight' setting is checked, the {mlang} will be wrapped between"," * the tags with the class for the CSS highlight; if not, they will not"," * be wrapped."," *"," * If there is no content selected, a \" \" will be inserted; otherwhise,"," * it's impossible to place the cursor inside the {mlang} tags."," *"," * @method _addTags"," * @param {EventFacade} e"," * @param {string} langCode the language code"," * @private"," */"," _addTags: function(e, langCode) {"," var selection,"," host = this.get('host'),"," taggedContent,"," content;",""," taggedContent = (this._highlight) ? TEMPLATES.SPANED : TEMPLATES.NOT_SPANED;",""," selection = this._getSelectionHTML();"," content = (host.getSelection().toString().length === 0) ? ' ' : selection;",""," taggedContent = taggedContent.replace(LANG_WILDCARD, langCode);"," taggedContent = taggedContent.replace(CONTENT_WILDCARD, content);",""," host.insertContentAtFocusPoint(taggedContent);",""," this.markUpdated();"," },",""," /**"," * Retrieves selected text with its HTML."," * Took from: http://stackoverflow.com/questions/4176923/html-of-selected-text/4177234#4177234"," *"," * @method _getSelectionHTML"," * @private"," * @return {string} selected text's html; empty if nothing selected"," */"," _getSelectionHTML: function() {"," var html = '',"," selection,"," container,"," index,"," lenght;",""," if (typeof window.getSelection !== 'undefined') {"," selection = window.getSelection();",""," if (selection.rangeCount) {"," container = document.createElement('div');"," for (index = 0, lenght = selection.rangeCount; index < lenght; ++index) {"," container.appendChild(selection.getRangeAt(index).cloneContents());"," }"," html = container.innerHTML;"," }",""," } else if (typeof document.selection !== 'undefined') {"," if (document.selection.type === 'Text') {"," html = document.selection.createRange().htmlText;"," }"," }",""," return html;"," },",""," /**"," * Listens to every change of the text cursor in the text area. If the"," * cursor is placed within a multilang tag, the whole tag is selected."," *"," * @method _checkSelectionChange"," * @private"," */"," _checkSelectionChange: function() {"," var host = this.get('host'),"," node = host.getSelectionParentNode(),"," nodeValue = Y.one(node).get('text'),"," isTextNode,"," isLangTag;",""," isTextNode = Y.one(node).toString().indexOf('#text') > - 1;"," isLangTag = (nodeValue.match(/\\{mlang/g).length === 1);",""," if (isTextNode && isLangTag) {"," host.setSelection(host.getSelectionFromNode(Y.one(node)));"," }"," },",""," /**"," * Retrieves the inputs of type submit, and, for each element, calls the function"," * that sets the submit listener. Is not made in this function because there is"," * not any (apparent) way to access class scope from YUI closure. "," *"," * @method _setSubmitListeners"," * @private"," */"," _setSubmitListeners: function() {"," var submitButtons = Y.all('input[type=submit]');",""," submitButtons.each(this._addListenerToSubmitButtons, this);"," },",""," /**"," * Adds the clean tags submit listener of each input[type=\"submit\"], but only if"," * it's not 'cancel' type, and if its parent form is of 'mform' class, because there"," * may be any other submit type (such us administrator's search button)."," *"," * The button node to add the listener is passed as global property because there is"," * no (apparent) way to pass arguments to YUI callback functions."," *"," * @method _addListenerToSubmitButtons"," * @param {Node} buttonNode"," * @private"," */"," _addListenerToSubmitButtons: function(buttonNode) {"," var buttonObject,"," className,"," parentFormClassName,"," notCancelButton,"," notSearchButton;",""," buttonObject = document.getElementById(buttonNode.get('id'));",""," if (buttonObject !== null) {"," className = buttonObject.className;"," parentFormClassName = buttonObject.form.className;",""," notCancelButton = className.match(/btn-cancel/g) === null;"," notSearchButton = parentFormClassName.match(/mform/g).length > 0;",""," if (notCancelButton && notSearchButton) {"," this._auxiliarSubmitButtonNode = buttonNode;"," buttonNode.on('click', this._cleanTagsOnSubmit, this);"," }"," }"," },",""," /**"," * When submit button clicked, this function is invoked. It has to stop the submission,"," * in order to process the textarea to clean the tags."," *"," * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default,"," * an then simulates the click, to submit the form."," *"," * The clicked submit button ('save and return' or 'save and display'), is accessed globally,"," * in '_auxiliarSubmitButtonNode' property, set by '_addListenerToSubmitButtons' function."," *"," * @method _cleanTagsOnSubmit"," * @param {EventFacade} e"," * @private"," */"," _cleanTagsOnSubmit: function(e) {"," var submitButton;",""," e.preventDefault();",""," submitButton = Y.one(this._auxiliarSubmitButtonNode);",""," this._cleanTagsWithNoYuiId();"," this._cleanTagsWithYuiId();",""," submitButton.detach('click', this._cleanTagsOnSubmit);"," submitButton.simulate('click');"," },",""," /**"," * Cleans the tags around the {mlang} tags when the form is submitted,"," * that do not have \"id\" attribute."," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * There may be more than one atto editor textarea in the page. So, we have to retrieve"," * the textareas by the class name. If there is only one, the object will be only the"," * reference, but, if there are more, we will have an array. So, the easiest way is to"," * check if what we have is an array, and if it not, create it manually, and iterate it"," * later."," *"," * issue #15: the textareas are now retrieved passing to YUI selector the whole element,"," * instead of the id string, due to problems with special characters."," * See discussion: https://moodle.org/mod/forum/discuss.php?d=332217"," *"," * @method _cleanTagsWithNoYuiId"," * @private"," */"," _cleanTagsWithNoYuiId: function() {"," var textareas = Y.all('.editor_atto_content'),"," textarea,"," textareaIndex,"," innerHTML,"," spanedmlangtags,"," spanedmlangtag,"," index,"," cleanmlangtag,"," regularExpression;",""," regularExpression = new RegExp(OPENING_SPAN + '.*?' + '', 'g');",""," if (!textareas instanceof Array) {"," textarea = textareas;"," textareas = [];"," textareas[0] = textarea;"," }",""," for (textareaIndex = 0; textareaIndex < textareas._nodes.length; textareaIndex++) {"," textarea = textareas._nodes[textareaIndex].id;"," textarea = Y.one(document.getElementById(textarea));",""," innerHTML = textarea.get('innerHTML');",""," spanedmlangtags = innerHTML.match(regularExpression);",""," if (spanedmlangtags === null) {"," continue;"," }"," "," for (index = 0; index < spanedmlangtags.length; index++) {"," spanedmlangtag = spanedmlangtags[index];"," cleanmlangtag = spanedmlangtag.replace(OPENING_SPAN, '');",""," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }",""," textarea.set('innerHTML', innerHTML);"," }",""," this.markUpdated();"," },",""," /**"," * Cleans the tags around the {mlang} tags when the form is submitted,"," * that have \"id\" attribute, generated by YUI, when the cursor is placed on the tags."," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * There may be more than one atto editor textarea in the page. So, we have to retrieve"," * the textareas by the class name. If there is only one, the object will be only the"," * reference, but, if there are more, we will have an array. So, the easiest way is to"," * check if what we have is an array, and if it not, create it manually, and iterate it"," * later."," *"," * issue #15: the textareas are now retrieved passing to YUI selector the whole element,"," * instead of the id string, due to problems with special characters."," * See discussion: https://moodle.org/mod/forum/discuss.php?d=332217"," *"," * @method anTagsWithYuiId"," * @private"," */"," _cleanTagsWithYuiId: function() {"," var textareas = Y.all('.editor_atto_content'),"," textarea,"," textareaIndex,"," innerHTML,"," spanedmlangtag,"," index,"," cleanmlangtag,"," regularExpression,"," openingspanwithyui,"," spanedmlangtagsdwithyui,"," mlangtag;",""," openingspanwithyui = OPENING_SPAN.replace('', 'g');",""," if (!textareas instanceof Array) {"," textarea = textareas;"," textareas = [];"," textareas[0] = textarea;"," }"," "," for (textareaIndex = 0; textareaIndex < textareas._nodes.length; textareaIndex++) {"," textarea = textareas._nodes[textareaIndex].id;"," textarea = Y.one(document.getElementById(textarea));",""," innerHTML = textarea.get('innerHTML');",""," spanedmlangtagsdwithyui = innerHTML.match(regularExpression);",""," if (spanedmlangtagsdwithyui === null) {"," continue;"," }"," "," for (index = 0; index < spanedmlangtagsdwithyui.length; index++) {"," spanedmlangtag = spanedmlangtagsdwithyui[index];"," mlangtag = spanedmlangtag.match(/\\{mlang.*?\\}/g)[0];",""," cleanmlangtag = spanedmlangtag.replace(regularExpression, mlangtag);"," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }",""," textarea.set('innerHTML', innerHTML);",""," this.markUpdated();"," }"," },",""," /**"," * Adds the tags to the {mlang} tags when the editor is loaded."," * In this case, we DON'T HAVE TO CALL TO markUpdated(). Why? Honestly,"," * I don't know. But, if we call it after setting the HTML, the {mlang}"," * tags flicker with the decoration, and returns to their original state."," *"," * Instead of taking the HTML directly from the textarea, we have to"," * retrieve it, first, without the tags that can be stored"," * in database, due to a bug in version 2015120501 that stores the"," * {mlang} tags in database, with the tags."," * More info about this bug: https://github.com/julenpardo/moodle-atto_multilang2/issues/8"," *"," * Every different {mlang} tag has to be replaced only once, otherwise,"," * nested s will be created in every repeated replacement. So, we"," * have to have a track of which replacements have been made."," *"," * @method _decorateTagsOnInit"," * @private"," */"," _decorateTagsOnInit: function() {"," var textarea = Y.all('.editor_atto_content'),"," innerHTML,"," regularExpression,"," mlangtags,"," mlangtag,"," index,"," decoratedmlangtag,"," replacementsmade = [],"," notreplacedyet;",""," innerHTML = this._getHTMLwithCleanedTags();",""," regularExpression = new RegExp('{mlang.*?}', 'g');"," mlangtags = innerHTML.match(regularExpression);",""," if (mlangtags !== null) {"," for (index = 0; index < mlangtags.length; index++) {"," mlangtag = mlangtags[index];",""," notreplacedyet = replacementsmade.indexOf(mlangtag) === -1;",""," if (notreplacedyet) {"," replacementsmade.push(mlangtag);",""," decoratedmlangtag = OPENING_SPAN + mlangtag + '';"," regularExpression = new RegExp(mlangtag, 'g');",""," innerHTML = innerHTML.replace(regularExpression, decoratedmlangtag);"," }"," }",""," textarea.set('innerHTML', innerHTML);"," }",""," },",""," /**"," * This function returns the HTML as it is in the textarea, but cleaning every"," * tag around the {mlang} tags. This is necessary for decorating tags on"," * init, because it could happen that in database are stored the {mlang} tags with"," * their tags, due to a bug in version 2015120501."," * More info about this bug: https://github.com/julenpardo/moodle-atto_multilang2/issues/8"," *"," * @method _getHTMLwithCleanedTags"," * @return {string} HTML in textarea, without any around {mlang} tags"," */"," _getHTMLwithCleanedTags: function() {"," var host = this.get('host'),"," innerHTML = host.getCleanHTML(),"," regexString,"," regularExpression,"," spanedmlangtags,"," spanedmlangtag,"," cleanmlangtag,"," index;",""," regexString = OPENING_SPAN + '.*?' + '';"," regularExpression = new RegExp(regexString, 'g');"," spanedmlangtags = innerHTML.match(regularExpression);",""," if (spanedmlangtags !== null) {"," for (index = 0; index < spanedmlangtags.length; index++) {"," spanedmlangtag = spanedmlangtags[index];",""," cleanmlangtag = spanedmlangtag.replace(OPENING_SPAN, '');"," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }"," }",""," return innerHTML;"," }","","}, {"," ATTRS: {"," /**"," * The list of installed languages."," *"," * @attribute languages"," * @type array"," * @default {\"en\":\"English (en)\"}"," */"," languages: DEFAULT_LANGUAGE,",""," /**"," * If the current user has the capability to use the plugin."," *"," * @attribute capability"," * @type boolean"," * @default true"," */"," capability: DEFAULT_CAPABILITY,",""," /**"," * If the {mlang} tags have to be highlighted or not."," *"," * @property highlight"," * @type boolean"," * @default true"," */"," highlight: DEFAULT_HIGHLIGHT,",""," /**"," * The CSS for delimiters."," *"," * @property css"," * @type string"," * @default DEFAULT_CSS"," */"," css: DEFAULT_CSS"," }","});","","","}, '@VERSION@', {\"requires\": [\"moodle-editor_atto-plugin\"]});","","}());"]}; + __coverage__['build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js'] = {"path":"build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0,"100":0,"101":0,"102":0,"103":0,"104":0,"105":0,"106":0,"107":0,"108":0,"109":0,"110":0,"111":0,"112":0,"113":0,"114":0,"115":0,"116":0,"117":0,"118":0,"119":0,"120":0,"121":0,"122":0,"123":0,"124":0,"125":0,"126":0,"127":0,"128":0,"129":0,"130":0,"131":0,"132":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0],"14":[0,0],"15":[0,0],"16":[0,0],"17":[0,0],"18":[0,0],"19":[0,0],"20":[0,0],"21":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0},"fnMap":{"1":{"name":"(anonymous_1)","line":1,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":60}}},"2":{"name":"(anonymous_2)","line":73,"loc":{"start":{"line":73,"column":17},"end":{"line":73,"column":28}}},"3":{"name":"(anonymous_3)","line":107,"loc":{"start":{"line":107,"column":22},"end":{"line":107,"column":33}}},"4":{"name":"(anonymous_4)","line":126,"loc":{"start":{"line":126,"column":29},"end":{"line":126,"column":40}}},"5":{"name":"(anonymous_5)","line":161,"loc":{"start":{"line":161,"column":14},"end":{"line":161,"column":40}}},"6":{"name":"(anonymous_6)","line":188,"loc":{"start":{"line":188,"column":23},"end":{"line":188,"column":34}}},"7":{"name":"(anonymous_7)","line":222,"loc":{"start":{"line":222,"column":27},"end":{"line":222,"column":38}}},"8":{"name":"(anonymous_8)","line":245,"loc":{"start":{"line":245,"column":25},"end":{"line":245,"column":36}}},"9":{"name":"(anonymous_9)","line":260,"loc":{"start":{"line":260,"column":33},"end":{"line":260,"column":54}}},"10":{"name":"(anonymous_10)","line":294,"loc":{"start":{"line":294,"column":24},"end":{"line":294,"column":54}}},"11":{"name":"(anonymous_11)","line":323,"loc":{"start":{"line":323,"column":27},"end":{"line":323,"column":38}}},"12":{"name":"(anonymous_12)","line":388,"loc":{"start":{"line":388,"column":26},"end":{"line":388,"column":37}}},"13":{"name":"(anonymous_13)","line":457,"loc":{"start":{"line":457,"column":25},"end":{"line":457,"column":36}}},"14":{"name":"(anonymous_14)","line":504,"loc":{"start":{"line":504,"column":29},"end":{"line":504,"column":40}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":573,"column":61}},"2":{"start":{"line":28,"column":0},"end":{"line":52,"column":56}},"3":{"start":{"line":62,"column":0},"end":{"line":570,"column":3}},"4":{"start":{"line":74,"column":8},"end":{"line":75,"column":30}},"5":{"start":{"line":77,"column":8},"end":{"line":98,"column":9}},"6":{"start":{"line":78,"column":12},"end":{"line":78,"column":58}},"7":{"start":{"line":79,"column":12},"end":{"line":79,"column":55}},"8":{"start":{"line":81,"column":12},"end":{"line":88,"column":15}},"9":{"start":{"line":90,"column":12},"end":{"line":90,"column":91}},"10":{"start":{"line":92,"column":12},"end":{"line":92,"column":36}},"11":{"start":{"line":94,"column":12},"end":{"line":97,"column":13}},"12":{"start":{"line":95,"column":16},"end":{"line":95,"column":43}},"13":{"start":{"line":96,"column":16},"end":{"line":96,"column":43}},"14":{"start":{"line":108,"column":8},"end":{"line":109,"column":18}},"15":{"start":{"line":111,"column":8},"end":{"line":111,"column":48}},"16":{"start":{"line":112,"column":8},"end":{"line":112,"column":32}},"17":{"start":{"line":113,"column":8},"end":{"line":113,"column":30}},"18":{"start":{"line":115,"column":8},"end":{"line":115,"column":41}},"19":{"start":{"line":127,"column":8},"end":{"line":129,"column":21}},"20":{"start":{"line":131,"column":8},"end":{"line":131,"column":57}},"21":{"start":{"line":133,"column":8},"end":{"line":140,"column":9}},"22":{"start":{"line":134,"column":12},"end":{"line":139,"column":13}},"23":{"start":{"line":135,"column":16},"end":{"line":138,"column":19}},"24":{"start":{"line":142,"column":8},"end":{"line":142,"column":28}},"25":{"start":{"line":162,"column":8},"end":{"line":165,"column":20}},"26":{"start":{"line":167,"column":8},"end":{"line":167,"column":84}},"27":{"start":{"line":169,"column":8},"end":{"line":169,"column":45}},"28":{"start":{"line":170,"column":8},"end":{"line":170,"column":87}},"29":{"start":{"line":172,"column":8},"end":{"line":172,"column":71}},"30":{"start":{"line":173,"column":8},"end":{"line":173,"column":73}},"31":{"start":{"line":175,"column":8},"end":{"line":175,"column":54}},"32":{"start":{"line":177,"column":8},"end":{"line":177,"column":27}},"33":{"start":{"line":189,"column":8},"end":{"line":193,"column":19}},"34":{"start":{"line":195,"column":8},"end":{"line":210,"column":9}},"35":{"start":{"line":196,"column":12},"end":{"line":196,"column":46}},"36":{"start":{"line":198,"column":12},"end":{"line":204,"column":13}},"37":{"start":{"line":199,"column":16},"end":{"line":199,"column":58}},"38":{"start":{"line":200,"column":16},"end":{"line":202,"column":17}},"39":{"start":{"line":201,"column":20},"end":{"line":201,"column":87}},"40":{"start":{"line":203,"column":16},"end":{"line":203,"column":43}},"41":{"start":{"line":206,"column":15},"end":{"line":210,"column":9}},"42":{"start":{"line":207,"column":12},"end":{"line":209,"column":13}},"43":{"start":{"line":208,"column":16},"end":{"line":208,"column":65}},"44":{"start":{"line":212,"column":8},"end":{"line":212,"column":20}},"45":{"start":{"line":223,"column":8},"end":{"line":227,"column":22}},"46":{"start":{"line":229,"column":8},"end":{"line":229,"column":67}},"47":{"start":{"line":230,"column":8},"end":{"line":230,"column":63}},"48":{"start":{"line":232,"column":8},"end":{"line":234,"column":9}},"49":{"start":{"line":233,"column":12},"end":{"line":233,"column":70}},"50":{"start":{"line":246,"column":8},"end":{"line":246,"column":56}},"51":{"start":{"line":248,"column":8},"end":{"line":248,"column":67}},"52":{"start":{"line":261,"column":8},"end":{"line":265,"column":28}},"53":{"start":{"line":267,"column":8},"end":{"line":267,"column":69}},"54":{"start":{"line":269,"column":8},"end":{"line":279,"column":9}},"55":{"start":{"line":270,"column":12},"end":{"line":270,"column":47}},"56":{"start":{"line":271,"column":12},"end":{"line":271,"column":62}},"57":{"start":{"line":273,"column":12},"end":{"line":273,"column":70}},"58":{"start":{"line":274,"column":12},"end":{"line":274,"column":77}},"59":{"start":{"line":276,"column":12},"end":{"line":278,"column":13}},"60":{"start":{"line":277,"column":16},"end":{"line":277,"column":82}},"61":{"start":{"line":295,"column":8},"end":{"line":295,"column":31}},"62":{"start":{"line":297,"column":8},"end":{"line":297,"column":37}},"63":{"start":{"line":298,"column":8},"end":{"line":298,"column":35}},"64":{"start":{"line":300,"column":8},"end":{"line":300,"column":62}},"65":{"start":{"line":301,"column":8},"end":{"line":301,"column":39}},"66":{"start":{"line":324,"column":8},"end":{"line":332,"column":30}},"67":{"start":{"line":334,"column":8},"end":{"line":334,"column":78}},"68":{"start":{"line":336,"column":8},"end":{"line":340,"column":9}},"69":{"start":{"line":337,"column":12},"end":{"line":337,"column":33}},"70":{"start":{"line":338,"column":12},"end":{"line":338,"column":27}},"71":{"start":{"line":339,"column":12},"end":{"line":339,"column":36}},"72":{"start":{"line":342,"column":8},"end":{"line":364,"column":9}},"73":{"start":{"line":343,"column":12},"end":{"line":343,"column":58}},"74":{"start":{"line":344,"column":12},"end":{"line":344,"column":64}},"75":{"start":{"line":346,"column":12},"end":{"line":346,"column":50}},"76":{"start":{"line":348,"column":12},"end":{"line":348,"column":65}},"77":{"start":{"line":350,"column":12},"end":{"line":352,"column":13}},"78":{"start":{"line":351,"column":16},"end":{"line":351,"column":25}},"79":{"start":{"line":354,"column":12},"end":{"line":361,"column":13}},"80":{"start":{"line":355,"column":16},"end":{"line":355,"column":56}},"81":{"start":{"line":356,"column":16},"end":{"line":356,"column":73}},"82":{"start":{"line":358,"column":16},"end":{"line":358,"column":69}},"83":{"start":{"line":360,"column":16},"end":{"line":360,"column":77}},"84":{"start":{"line":363,"column":12},"end":{"line":363,"column":49}},"85":{"start":{"line":366,"column":8},"end":{"line":366,"column":27}},"86":{"start":{"line":389,"column":8},"end":{"line":399,"column":21}},"87":{"start":{"line":401,"column":8},"end":{"line":401,"column":81}},"88":{"start":{"line":402,"column":8},"end":{"line":402,"column":89}},"89":{"start":{"line":404,"column":8},"end":{"line":408,"column":9}},"90":{"start":{"line":405,"column":12},"end":{"line":405,"column":33}},"91":{"start":{"line":406,"column":12},"end":{"line":406,"column":27}},"92":{"start":{"line":407,"column":12},"end":{"line":407,"column":36}},"93":{"start":{"line":410,"column":8},"end":{"line":435,"column":9}},"94":{"start":{"line":411,"column":12},"end":{"line":411,"column":58}},"95":{"start":{"line":412,"column":12},"end":{"line":412,"column":64}},"96":{"start":{"line":414,"column":12},"end":{"line":414,"column":50}},"97":{"start":{"line":416,"column":12},"end":{"line":416,"column":73}},"98":{"start":{"line":418,"column":12},"end":{"line":420,"column":13}},"99":{"start":{"line":419,"column":16},"end":{"line":419,"column":25}},"100":{"start":{"line":422,"column":12},"end":{"line":430,"column":13}},"101":{"start":{"line":423,"column":16},"end":{"line":423,"column":64}},"102":{"start":{"line":424,"column":16},"end":{"line":424,"column":68}},"103":{"start":{"line":426,"column":16},"end":{"line":426,"column":84}},"104":{"start":{"line":427,"column":16},"end":{"line":427,"column":69}},"105":{"start":{"line":429,"column":16},"end":{"line":429,"column":77}},"106":{"start":{"line":432,"column":12},"end":{"line":432,"column":49}},"107":{"start":{"line":434,"column":12},"end":{"line":434,"column":31}},"108":{"start":{"line":458,"column":8},"end":{"line":466,"column":27}},"109":{"start":{"line":468,"column":8},"end":{"line":468,"column":51}},"110":{"start":{"line":470,"column":8},"end":{"line":470,"column":58}},"111":{"start":{"line":471,"column":8},"end":{"line":471,"column":55}},"112":{"start":{"line":473,"column":8},"end":{"line":490,"column":9}},"113":{"start":{"line":474,"column":12},"end":{"line":487,"column":13}},"114":{"start":{"line":475,"column":16},"end":{"line":475,"column":44}},"115":{"start":{"line":477,"column":16},"end":{"line":477,"column":75}},"116":{"start":{"line":479,"column":16},"end":{"line":486,"column":17}},"117":{"start":{"line":480,"column":20},"end":{"line":480,"column":52}},"118":{"start":{"line":482,"column":20},"end":{"line":482,"column":76}},"119":{"start":{"line":483,"column":20},"end":{"line":483,"column":66}},"120":{"start":{"line":485,"column":20},"end":{"line":485,"column":88}},"121":{"start":{"line":489,"column":12},"end":{"line":489,"column":49}},"122":{"start":{"line":505,"column":8},"end":{"line":512,"column":18}},"123":{"start":{"line":514,"column":8},"end":{"line":514,"column":55}},"124":{"start":{"line":515,"column":8},"end":{"line":515,"column":57}},"125":{"start":{"line":516,"column":8},"end":{"line":516,"column":61}},"126":{"start":{"line":518,"column":8},"end":{"line":527,"column":9}},"127":{"start":{"line":519,"column":12},"end":{"line":526,"column":13}},"128":{"start":{"line":520,"column":16},"end":{"line":520,"column":56}},"129":{"start":{"line":522,"column":16},"end":{"line":522,"column":73}},"130":{"start":{"line":523,"column":16},"end":{"line":523,"column":69}},"131":{"start":{"line":525,"column":16},"end":{"line":525,"column":77}},"132":{"start":{"line":529,"column":8},"end":{"line":529,"column":25}}},"branchMap":{"1":{"line":77,"type":"if","locations":[{"start":{"line":77,"column":8},"end":{"line":77,"column":8}},{"start":{"line":77,"column":8},"end":{"line":77,"column":8}}]},"2":{"line":94,"type":"if","locations":[{"start":{"line":94,"column":12},"end":{"line":94,"column":12}},{"start":{"line":94,"column":12},"end":{"line":94,"column":12}}]},"3":{"line":134,"type":"if","locations":[{"start":{"line":134,"column":12},"end":{"line":134,"column":12}},{"start":{"line":134,"column":12},"end":{"line":134,"column":12}}]},"4":{"line":167,"type":"cond-expr","locations":[{"start":{"line":167,"column":44},"end":{"line":167,"column":60}},{"start":{"line":167,"column":63},"end":{"line":167,"column":83}}]},"5":{"line":170,"type":"cond-expr","locations":[{"start":{"line":170,"column":66},"end":{"line":170,"column":74}},{"start":{"line":170,"column":77},"end":{"line":170,"column":86}}]},"6":{"line":195,"type":"if","locations":[{"start":{"line":195,"column":8},"end":{"line":195,"column":8}},{"start":{"line":195,"column":8},"end":{"line":195,"column":8}}]},"7":{"line":198,"type":"if","locations":[{"start":{"line":198,"column":12},"end":{"line":198,"column":12}},{"start":{"line":198,"column":12},"end":{"line":198,"column":12}}]},"8":{"line":206,"type":"if","locations":[{"start":{"line":206,"column":15},"end":{"line":206,"column":15}},{"start":{"line":206,"column":15},"end":{"line":206,"column":15}}]},"9":{"line":207,"type":"if","locations":[{"start":{"line":207,"column":12},"end":{"line":207,"column":12}},{"start":{"line":207,"column":12},"end":{"line":207,"column":12}}]},"10":{"line":232,"type":"if","locations":[{"start":{"line":232,"column":8},"end":{"line":232,"column":8}},{"start":{"line":232,"column":8},"end":{"line":232,"column":8}}]},"11":{"line":232,"type":"binary-expr","locations":[{"start":{"line":232,"column":12},"end":{"line":232,"column":22}},{"start":{"line":232,"column":26},"end":{"line":232,"column":35}}]},"12":{"line":269,"type":"if","locations":[{"start":{"line":269,"column":8},"end":{"line":269,"column":8}},{"start":{"line":269,"column":8},"end":{"line":269,"column":8}}]},"13":{"line":276,"type":"if","locations":[{"start":{"line":276,"column":12},"end":{"line":276,"column":12}},{"start":{"line":276,"column":12},"end":{"line":276,"column":12}}]},"14":{"line":276,"type":"binary-expr","locations":[{"start":{"line":276,"column":16},"end":{"line":276,"column":31}},{"start":{"line":276,"column":35},"end":{"line":276,"column":50}}]},"15":{"line":336,"type":"if","locations":[{"start":{"line":336,"column":8},"end":{"line":336,"column":8}},{"start":{"line":336,"column":8},"end":{"line":336,"column":8}}]},"16":{"line":350,"type":"if","locations":[{"start":{"line":350,"column":12},"end":{"line":350,"column":12}},{"start":{"line":350,"column":12},"end":{"line":350,"column":12}}]},"17":{"line":404,"type":"if","locations":[{"start":{"line":404,"column":8},"end":{"line":404,"column":8}},{"start":{"line":404,"column":8},"end":{"line":404,"column":8}}]},"18":{"line":418,"type":"if","locations":[{"start":{"line":418,"column":12},"end":{"line":418,"column":12}},{"start":{"line":418,"column":12},"end":{"line":418,"column":12}}]},"19":{"line":473,"type":"if","locations":[{"start":{"line":473,"column":8},"end":{"line":473,"column":8}},{"start":{"line":473,"column":8},"end":{"line":473,"column":8}}]},"20":{"line":479,"type":"if","locations":[{"start":{"line":479,"column":16},"end":{"line":479,"column":16}},{"start":{"line":479,"column":16},"end":{"line":479,"column":16}}]},"21":{"line":518,"type":"if","locations":[{"start":{"line":518,"column":8},"end":{"line":518,"column":8}},{"start":{"line":518,"column":8},"end":{"line":518,"column":8}}]}},"code":["(function () { YUI.add('moodle-atto_multilang2-button', function (Y, NAME) {","","// This file is part of Moodle - http://moodle.org/","//","// Moodle is free software: you can redistribute it and/or modify","// it under the terms of the GNU General Public License as published by","// the Free Software Foundation, either version 3 of the License, or","// (at your option) any later version.","//","// Moodle is distributed in the hope that it will be useful,","// but WITHOUT ANY WARRANTY; without even the implied warranty of","// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the","// GNU General Public License for more details.","//","// You should have received a copy of the GNU General Public License","// along with Moodle. If not, see .","","/**"," * @package atto_multilang2"," * @copyright 2015 onwards Julen Pardo & Mondragon Unibertsitatea"," * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later"," */","","/**"," * @module moodle-atto_multilang2-button"," */","","var CLASSES = {"," TAG: 'filter-multilang-tag'"," },",""," LANG_WILDCARD = '%lang',"," CONTENT_WILDCARD = '%content',"," ATTR_LANGUAGES = 'languages',"," ATTR_CAPABILITY = 'capability',"," ATTR_HIGHLIGHT = 'highlight',"," ATTR_CSS = 'css',"," DEFAULT_LANGUAGE = '{\"en\":\"English (en)\"}',"," DEFAULT_CAPABILITY = true,"," DEFAULT_HIGHLIGHT = true,"," DEFAULT_CSS = 'outline: 1px dotted;' +"," 'padding: 0.1em;' +"," 'margin: 0em 0.1em;' +"," 'background-color: #ffffaa;',"," TEMPLATES = {"," SPANED: ' {mlang ' + LANG_WILDCARD + '}' +"," CONTENT_WILDCARD +"," '{mlang} ',",""," NOT_SPANED: '{mlang ' + LANG_WILDCARD + '}' + CONTENT_WILDCARD + '{mlang}'"," },"," OPENING_SPAN = '';","","/**"," * Atto text editor multilanguage plugin."," *"," * @namespace M.atto_multilang2"," * @class button"," * @extends M.editor_atto.EditorPlugin"," */","","Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {",""," /**"," * If the {mlang} tags have to be highlighted or not. Received as parameter from lib.php."," *"," * @property _highlight"," * @type boolean"," * @private"," */"," _highlight: true,",""," initializer: function() {"," var hascapability = this.get(ATTR_CAPABILITY),"," toolbarItems = [];",""," if (hascapability) {"," toolbarItems = this._initializeToolbarItems();"," this._highlight = this.get(ATTR_HIGHLIGHT);",""," this.addToolbarMenu({"," globalItemConfig: {"," callback: this._addTags"," },"," icon: 'icon',"," iconComponent: 'atto_multilang2',"," items: toolbarItems"," });",""," this.get('host').on('atto:selectionchanged', this._checkSelectionChange, this);",""," this._addDelimiterCss();",""," if (this._highlight) {"," this._decorateTagsOnInit();"," this._setSubmitListeners();"," }"," }"," },",""," /**"," * Adds the CSS rules for the delimiters, received as parameter from lib.php."," *"," * @method _addDelimiterCss"," * @private"," */"," _addDelimiterCss: function() {"," var css = '.' + CLASSES.TAG + '{' + this.get(ATTR_CSS) + '}',"," style;",""," style = document.createElement('style');"," style.type = 'text/css';"," style.innerHTML = css;",""," document.head.appendChild(style);"," },",""," /**"," * Initializes the toolbar items, which will be the installed languages,"," * received as parameter."," *"," * @method _initializeToolbarItems"," * @private"," * @return {Array} installed language strings"," */"," _initializeToolbarItems: function() {"," var toolbarItems = [],"," languages,"," langCode;",""," languages = JSON.parse(this.get(ATTR_LANGUAGES));",""," for (langCode in languages) {"," if (languages.hasOwnProperty(langCode)) {"," toolbarItems.push({"," text: languages[langCode],"," callbackArgs: langCode"," });"," }"," }",""," return toolbarItems;"," },",""," /**"," * Retrieves the selected text, wraps it with the multilang tags,"," * and replaces the selected text in the editor with with it."," *"," * If the 'highlight' setting is checked, the {mlang} will be wrapped between"," * the tags with the class for the CSS highlight; if not, they will not"," * be wrapped."," *"," * If there is no content selected, a \" \" will be inserted; otherwhise,"," * it's impossible to place the cursor inside the {mlang} tags."," *"," * @method _addTags"," * @param {EventFacade} event"," * @param {string} langCode the language code"," * @private"," */"," _addTags: function(event, langCode) {"," var selection,"," host = this.get('host'),"," taggedContent,"," content;",""," taggedContent = (this._highlight) ? TEMPLATES.SPANED : TEMPLATES.NOT_SPANED;",""," selection = this._getSelectionHTML();"," content = (host.getSelection().toString().length === 0) ? ' ' : selection;",""," taggedContent = taggedContent.replace(LANG_WILDCARD, langCode);"," taggedContent = taggedContent.replace(CONTENT_WILDCARD, content);",""," host.insertContentAtFocusPoint(taggedContent);",""," this.markUpdated();"," },",""," /**"," * Retrieves selected text with its HTML."," * Took from: http://stackoverflow.com/questions/4176923/html-of-selected-text/4177234#4177234"," *"," * @method _getSelectionHTML"," * @private"," * @return {string} selected text's html; empty if nothing selected"," */"," _getSelectionHTML: function() {"," var html = '',"," selection,"," container,"," index,"," lenght;",""," if (typeof window.getSelection !== 'undefined') {"," selection = window.getSelection();",""," if (selection.rangeCount) {"," container = document.createElement('div');"," for (index = 0, lenght = selection.rangeCount; index < lenght; ++index) {"," container.appendChild(selection.getRangeAt(index).cloneContents());"," }"," html = container.innerHTML;"," }",""," } else if (typeof document.selection !== 'undefined') {"," if (document.selection.type === 'Text') {"," html = document.selection.createRange().htmlText;"," }"," }",""," return html;"," },",""," /**"," * Listens to every change of the text cursor in the text area. If the"," * cursor is placed within a multilang tag, the whole tag is selected."," *"," * @method _checkSelectionChange"," * @private"," */"," _checkSelectionChange: function() {"," var host = this.get('host'),"," node = host.getSelectionParentNode(),"," nodeValue = Y.one(node).get('text'),"," isTextNode,"," isLangTag;",""," isTextNode = Y.one(node).toString().indexOf('#text') > - 1;"," isLangTag = (nodeValue.match(/\\{mlang/g).length === 1);",""," if (isTextNode && isLangTag) {"," host.setSelection(host.getSelectionFromNode(Y.one(node)));"," }"," },",""," /**"," * Retrieves the inputs of type submit, and, for each element, calls the function"," * that sets the submit listener. Is not made in this function because there is"," * not any (apparent) way to access class scope from YUI closure."," *"," * @method _setSubmitListeners"," * @private"," */"," _setSubmitListeners: function() {"," var submitButtons = Y.all('input[type=submit]');",""," submitButtons.each(this._addListenerToSubmitButtons, this);"," },",""," /**"," * Adds the clean tags submit listener of each input[type=\"submit\"], but only if"," * it's not 'cancel' type, and if its parent form is of 'mform' class, because there"," * may be any other submit type (such us administrator's search button)."," *"," * @method _addListenerToSubmitButtons"," * @param {Node} buttonNode"," * @private"," */"," _addListenerToSubmitButtons: function(buttonNode) {"," var buttonObject,"," className,"," parentFormClassName,"," notCancelButton,"," notSearchButton;",""," buttonObject = document.getElementById(buttonNode.get('id'));",""," if (buttonObject !== null) {"," className = buttonObject.className;"," parentFormClassName = buttonObject.form.className;",""," notCancelButton = className.match(/btn-cancel/g) === null;"," notSearchButton = parentFormClassName.match(/mform/g).length > 0;",""," if (notCancelButton && notSearchButton) {"," buttonNode.on('click', this._cleanTagsOnSubmit, this, buttonNode);"," }"," }"," },",""," /**"," * When submit button clicked, this function is invoked. It has to stop the submission,"," * in order to process the textarea to clean the tags."," *"," * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default,"," * an then simulates the click, to submit the form."," *"," * @method _cleanTagsOnSubmit"," * @param {EventFacade} event"," * @param {Node} submitButton"," * @private"," */"," _cleanTagsOnSubmit: function(event, submitButton) {"," event.preventDefault();",""," this._cleanTagsWithNoYuiId();"," this._cleanTagsWithYuiId();",""," submitButton.detach('click', this._cleanTagsOnSubmit);"," submitButton.simulate('click');"," },",""," /**"," * Cleans the tags around the {mlang} tags when the form is submitted,"," * that do not have \"id\" attribute."," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * There may be more than one atto editor textarea in the page. So, we have to retrieve"," * the textareas by the class name. If there is only one, the object will be only the"," * reference, but, if there are more, we will have an array. So, the easiest way is to"," * check if what we have is an array, and if it not, create it manually, and iterate it"," * later."," *"," * issue #15: the textareas are now retrieved passing to YUI selector the whole element,"," * instead of the id string, due to problems with special characters."," * See discussion: https://moodle.org/mod/forum/discuss.php?d=332217"," *"," * @method _cleanTagsWithNoYuiId"," * @private"," */"," _cleanTagsWithNoYuiId: function() {"," var textareas = Y.all('.editor_atto_content'),"," textarea,"," textareaIndex,"," innerHTML,"," spanedmlangtags,"," spanedmlangtag,"," index,"," cleanmlangtag,"," regularExpression;",""," regularExpression = new RegExp(OPENING_SPAN + '.*?' + '', 'g');",""," if (!textareas instanceof Array) {"," textarea = textareas;"," textareas = [];"," textareas[0] = textarea;"," }",""," for (textareaIndex = 0; textareaIndex < textareas._nodes.length; textareaIndex++) {"," textarea = textareas._nodes[textareaIndex].id;"," textarea = Y.one(document.getElementById(textarea));",""," innerHTML = textarea.get('innerHTML');",""," spanedmlangtags = innerHTML.match(regularExpression);",""," if (spanedmlangtags === null) {"," continue;"," }"," "," for (index = 0; index < spanedmlangtags.length; index++) {"," spanedmlangtag = spanedmlangtags[index];"," cleanmlangtag = spanedmlangtag.replace(OPENING_SPAN, '');",""," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }",""," textarea.set('innerHTML', innerHTML);"," }",""," this.markUpdated();"," },",""," /**"," * Cleans the tags around the {mlang} tags when the form is submitted,"," * that have \"id\" attribute, generated by YUI, when the cursor is placed on the tags."," * The cleanup with \"id\" attribute and without it is made separately, to avoid an evil"," * regular expression."," *"," * There may be more than one atto editor textarea in the page. So, we have to retrieve"," * the textareas by the class name. If there is only one, the object will be only the"," * reference, but, if there are more, we will have an array. So, the easiest way is to"," * check if what we have is an array, and if it not, create it manually, and iterate it"," * later."," *"," * issue #15: the textareas are now retrieved passing to YUI selector the whole element,"," * instead of the id string, due to problems with special characters."," * See discussion: https://moodle.org/mod/forum/discuss.php?d=332217"," *"," * @method anTagsWithYuiId"," * @private"," */"," _cleanTagsWithYuiId: function() {"," var textareas = Y.all('.editor_atto_content'),"," textarea,"," textareaIndex,"," innerHTML,"," spanedmlangtag,"," index,"," cleanmlangtag,"," regularExpression,"," openingspanwithyui,"," spanedmlangtagsdwithyui,"," mlangtag;",""," openingspanwithyui = OPENING_SPAN.replace('', 'g');",""," if (!textareas instanceof Array) {"," textarea = textareas;"," textareas = [];"," textareas[0] = textarea;"," }"," "," for (textareaIndex = 0; textareaIndex < textareas._nodes.length; textareaIndex++) {"," textarea = textareas._nodes[textareaIndex].id;"," textarea = Y.one(document.getElementById(textarea));",""," innerHTML = textarea.get('innerHTML');",""," spanedmlangtagsdwithyui = innerHTML.match(regularExpression);",""," if (spanedmlangtagsdwithyui === null) {"," continue;"," }"," "," for (index = 0; index < spanedmlangtagsdwithyui.length; index++) {"," spanedmlangtag = spanedmlangtagsdwithyui[index];"," mlangtag = spanedmlangtag.match(/\\{mlang.*?\\}/g)[0];",""," cleanmlangtag = spanedmlangtag.replace(regularExpression, mlangtag);"," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }",""," textarea.set('innerHTML', innerHTML);",""," this.markUpdated();"," }"," },",""," /**"," * Adds the tags to the {mlang} tags when the editor is loaded."," * In this case, we DON'T HAVE TO CALL TO markUpdated(). Why? Honestly,"," * I don't know. But, if we call it after setting the HTML, the {mlang}"," * tags flicker with the decoration, and returns to their original state."," *"," * Instead of taking the HTML directly from the textarea, we have to"," * retrieve it, first, without the tags that can be stored"," * in database, due to a bug in version 2015120501 that stores the"," * {mlang} tags in database, with the tags."," * More info about this bug: https://github.com/julenpardo/moodle-atto_multilang2/issues/8"," *"," * Every different {mlang} tag has to be replaced only once, otherwise,"," * nested s will be created in every repeated replacement. So, we"," * have to have a track of which replacements have been made."," *"," * @method _decorateTagsOnInit"," * @private"," */"," _decorateTagsOnInit: function() {"," var textarea = Y.all('.editor_atto_content'),"," innerHTML,"," regularExpression,"," mlangtags,"," mlangtag,"," index,"," decoratedmlangtag,"," replacementsmade = [],"," notreplacedyet;",""," innerHTML = this._getHTMLwithCleanedTags();",""," regularExpression = new RegExp('{mlang.*?}', 'g');"," mlangtags = innerHTML.match(regularExpression);",""," if (mlangtags !== null) {"," for (index = 0; index < mlangtags.length; index++) {"," mlangtag = mlangtags[index];",""," notreplacedyet = replacementsmade.indexOf(mlangtag) === -1;",""," if (notreplacedyet) {"," replacementsmade.push(mlangtag);",""," decoratedmlangtag = OPENING_SPAN + mlangtag + '';"," regularExpression = new RegExp(mlangtag, 'g');",""," innerHTML = innerHTML.replace(regularExpression, decoratedmlangtag);"," }"," }",""," textarea.set('innerHTML', innerHTML);"," }",""," },",""," /**"," * This function returns the HTML as it is in the textarea, but cleaning every"," * tag around the {mlang} tags. This is necessary for decorating tags on"," * init, because it could happen that in database are stored the {mlang} tags with"," * their tags, due to a bug in version 2015120501."," * More info about this bug: https://github.com/julenpardo/moodle-atto_multilang2/issues/8"," *"," * @method _getHTMLwithCleanedTags"," * @return {string} HTML in textarea, without any around {mlang} tags"," */"," _getHTMLwithCleanedTags: function() {"," var host = this.get('host'),"," innerHTML = host.getCleanHTML(),"," regexString,"," regularExpression,"," spanedmlangtags,"," spanedmlangtag,"," cleanmlangtag,"," index;",""," regexString = OPENING_SPAN + '.*?' + '';"," regularExpression = new RegExp(regexString, 'g');"," spanedmlangtags = innerHTML.match(regularExpression);",""," if (spanedmlangtags !== null) {"," for (index = 0; index < spanedmlangtags.length; index++) {"," spanedmlangtag = spanedmlangtags[index];",""," cleanmlangtag = spanedmlangtag.replace(OPENING_SPAN, '');"," cleanmlangtag = cleanmlangtag.replace('', '');",""," innerHTML = innerHTML.replace(spanedmlangtag, cleanmlangtag);"," }"," }",""," return innerHTML;"," }","","}, {"," ATTRS: {"," /**"," * The list of installed languages."," *"," * @attribute languages"," * @type array"," * @default {\"en\":\"English (en)\"}"," */"," languages: DEFAULT_LANGUAGE,",""," /**"," * If the current user has the capability to use the plugin."," *"," * @attribute capability"," * @type boolean"," * @default true"," */"," capability: DEFAULT_CAPABILITY,",""," /**"," * If the {mlang} tags have to be highlighted or not."," *"," * @property highlight"," * @type boolean"," * @default true"," */"," highlight: DEFAULT_HIGHLIGHT,",""," /**"," * The CSS for delimiters."," *"," * @property css"," * @type string"," * @default DEFAULT_CSS"," */"," css: DEFAULT_CSS"," }","});","","","}, '@VERSION@', {\"requires\": [\"moodle-editor_atto-plugin\"]});","","}());"]}; } var __cov_xlcucJyua6odXhLRctX6xg = __coverage__['build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js']; -__cov_xlcucJyua6odXhLRctX6xg.s['1']++;YUI.add('moodle-atto_multilang2-button',function(Y,NAME){__cov_xlcucJyua6odXhLRctX6xg.f['1']++;__cov_xlcucJyua6odXhLRctX6xg.s['2']++;var CLASSES={TAG:'filter-multilang-tag'},LANG_WILDCARD='%lang',CONTENT_WILDCARD='%content',ATTR_LANGUAGES='languages',ATTR_CAPABILITY='capability',ATTR_HIGHLIGHT='highlight',ATTR_CSS='css',DEFAULT_LANGUAGE='{"en":"English (en)"}',DEFAULT_CAPABILITY=true,DEFAULT_HIGHLIGHT=true,DEFAULT_CSS='outline: 1px dotted;'+'padding: 0.1em;'+'margin: 0em 0.1em;'+'background-color: #ffffaa;',TEMPLATES={SPANED:' {mlang '+LANG_WILDCARD+'}'+CONTENT_WILDCARD+'{mlang} ',NOT_SPANED:'{mlang '+LANG_WILDCARD+'}'+CONTENT_WILDCARD+'{mlang}'},OPENING_SPAN='';__cov_xlcucJyua6odXhLRctX6xg.s['3']++;Y.namespace('M.atto_multilang2').Button=Y.Base.create('button',Y.M.editor_atto.EditorPlugin,[],{_highlight:true,_auxiliarSubmitButtonNode:null,initializer:function(){__cov_xlcucJyua6odXhLRctX6xg.f['2']++;__cov_xlcucJyua6odXhLRctX6xg.s['4']++;var hascapability=this.get(ATTR_CAPABILITY),toolbarItems=[];__cov_xlcucJyua6odXhLRctX6xg.s['5']++;if(hascapability){__cov_xlcucJyua6odXhLRctX6xg.b['1'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['6']++;toolbarItems=this._initializeToolbarItems();__cov_xlcucJyua6odXhLRctX6xg.s['7']++;this._highlight=this.get(ATTR_HIGHLIGHT);__cov_xlcucJyua6odXhLRctX6xg.s['8']++;this.addToolbarMenu({globalItemConfig:{callback:this._addTags},icon:'icon',iconComponent:'atto_multilang2',items:toolbarItems});__cov_xlcucJyua6odXhLRctX6xg.s['9']++;this.get('host').on('atto:selectionchanged',this._checkSelectionChange,this);__cov_xlcucJyua6odXhLRctX6xg.s['10']++;this._addDelimiterCss();__cov_xlcucJyua6odXhLRctX6xg.s['11']++;if(this._highlight){__cov_xlcucJyua6odXhLRctX6xg.b['2'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['12']++;this._decorateTagsOnInit();__cov_xlcucJyua6odXhLRctX6xg.s['13']++;this._setSubmitListeners();}else{__cov_xlcucJyua6odXhLRctX6xg.b['2'][1]++;}}else{__cov_xlcucJyua6odXhLRctX6xg.b['1'][1]++;}},_addDelimiterCss:function(){__cov_xlcucJyua6odXhLRctX6xg.f['3']++;__cov_xlcucJyua6odXhLRctX6xg.s['14']++;var css='.'+CLASSES.TAG+'{'+this.get(ATTR_CSS)+'}',style;__cov_xlcucJyua6odXhLRctX6xg.s['15']++;style=document.createElement('style');__cov_xlcucJyua6odXhLRctX6xg.s['16']++;style.type='text/css';__cov_xlcucJyua6odXhLRctX6xg.s['17']++;style.innerHTML=css;__cov_xlcucJyua6odXhLRctX6xg.s['18']++;document.head.appendChild(style);},_initializeToolbarItems:function(){__cov_xlcucJyua6odXhLRctX6xg.f['4']++;__cov_xlcucJyua6odXhLRctX6xg.s['19']++;var toolbarItems=[],languages,langCode;__cov_xlcucJyua6odXhLRctX6xg.s['20']++;languages=JSON.parse(this.get(ATTR_LANGUAGES));__cov_xlcucJyua6odXhLRctX6xg.s['21']++;for(langCode in languages){__cov_xlcucJyua6odXhLRctX6xg.s['22']++;if(languages.hasOwnProperty(langCode)){__cov_xlcucJyua6odXhLRctX6xg.b['3'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['23']++;toolbarItems.push({text:languages[langCode],callbackArgs:langCode});}else{__cov_xlcucJyua6odXhLRctX6xg.b['3'][1]++;}}__cov_xlcucJyua6odXhLRctX6xg.s['24']++;return toolbarItems;},_addTags:function(e,langCode){__cov_xlcucJyua6odXhLRctX6xg.f['5']++;__cov_xlcucJyua6odXhLRctX6xg.s['25']++;var selection,host=this.get('host'),taggedContent,content;__cov_xlcucJyua6odXhLRctX6xg.s['26']++;taggedContent=this._highlight?(__cov_xlcucJyua6odXhLRctX6xg.b['4'][0]++,TEMPLATES.SPANED):(__cov_xlcucJyua6odXhLRctX6xg.b['4'][1]++,TEMPLATES.NOT_SPANED);__cov_xlcucJyua6odXhLRctX6xg.s['27']++;selection=this._getSelectionHTML();__cov_xlcucJyua6odXhLRctX6xg.s['28']++;content=host.getSelection().toString().length===0?(__cov_xlcucJyua6odXhLRctX6xg.b['5'][0]++,' '):(__cov_xlcucJyua6odXhLRctX6xg.b['5'][1]++,selection);__cov_xlcucJyua6odXhLRctX6xg.s['29']++;taggedContent=taggedContent.replace(LANG_WILDCARD,langCode);__cov_xlcucJyua6odXhLRctX6xg.s['30']++;taggedContent=taggedContent.replace(CONTENT_WILDCARD,content);__cov_xlcucJyua6odXhLRctX6xg.s['31']++;host.insertContentAtFocusPoint(taggedContent);__cov_xlcucJyua6odXhLRctX6xg.s['32']++;this.markUpdated();},_getSelectionHTML:function(){__cov_xlcucJyua6odXhLRctX6xg.f['6']++;__cov_xlcucJyua6odXhLRctX6xg.s['33']++;var html='',selection,container,index,lenght;__cov_xlcucJyua6odXhLRctX6xg.s['34']++;if(typeof window.getSelection!=='undefined'){__cov_xlcucJyua6odXhLRctX6xg.b['6'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['35']++;selection=window.getSelection();__cov_xlcucJyua6odXhLRctX6xg.s['36']++;if(selection.rangeCount){__cov_xlcucJyua6odXhLRctX6xg.b['7'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['37']++;container=document.createElement('div');__cov_xlcucJyua6odXhLRctX6xg.s['38']++;for(index=0,lenght=selection.rangeCount;index-1;__cov_xlcucJyua6odXhLRctX6xg.s['47']++;isLangTag=nodeValue.match(/\{mlang/g).length===1;__cov_xlcucJyua6odXhLRctX6xg.s['48']++;if((__cov_xlcucJyua6odXhLRctX6xg.b['11'][0]++,isTextNode)&&(__cov_xlcucJyua6odXhLRctX6xg.b['11'][1]++,isLangTag)){__cov_xlcucJyua6odXhLRctX6xg.b['10'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['49']++;host.setSelection(host.getSelectionFromNode(Y.one(node)));}else{__cov_xlcucJyua6odXhLRctX6xg.b['10'][1]++;}},_setSubmitListeners:function(){__cov_xlcucJyua6odXhLRctX6xg.f['8']++;__cov_xlcucJyua6odXhLRctX6xg.s['50']++;var submitButtons=Y.all('input[type=submit]');__cov_xlcucJyua6odXhLRctX6xg.s['51']++;submitButtons.each(this._addListenerToSubmitButtons,this);},_addListenerToSubmitButtons:function(buttonNode){__cov_xlcucJyua6odXhLRctX6xg.f['9']++;__cov_xlcucJyua6odXhLRctX6xg.s['52']++;var buttonObject,className,parentFormClassName,notCancelButton,notSearchButton;__cov_xlcucJyua6odXhLRctX6xg.s['53']++;buttonObject=document.getElementById(buttonNode.get('id'));__cov_xlcucJyua6odXhLRctX6xg.s['54']++;if(buttonObject!==null){__cov_xlcucJyua6odXhLRctX6xg.b['12'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['55']++;className=buttonObject.className;__cov_xlcucJyua6odXhLRctX6xg.s['56']++;parentFormClassName=buttonObject.form.className;__cov_xlcucJyua6odXhLRctX6xg.s['57']++;notCancelButton=className.match(/btn-cancel/g)===null;__cov_xlcucJyua6odXhLRctX6xg.s['58']++;notSearchButton=parentFormClassName.match(/mform/g).length>0;__cov_xlcucJyua6odXhLRctX6xg.s['59']++;if((__cov_xlcucJyua6odXhLRctX6xg.b['14'][0]++,notCancelButton)&&(__cov_xlcucJyua6odXhLRctX6xg.b['14'][1]++,notSearchButton)){__cov_xlcucJyua6odXhLRctX6xg.b['13'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['60']++;this._auxiliarSubmitButtonNode=buttonNode;__cov_xlcucJyua6odXhLRctX6xg.s['61']++;buttonNode.on('click',this._cleanTagsOnSubmit,this);}else{__cov_xlcucJyua6odXhLRctX6xg.b['13'][1]++;}}else{__cov_xlcucJyua6odXhLRctX6xg.b['12'][1]++;}},_cleanTagsOnSubmit:function(e){__cov_xlcucJyua6odXhLRctX6xg.f['10']++;__cov_xlcucJyua6odXhLRctX6xg.s['62']++;var submitButton;__cov_xlcucJyua6odXhLRctX6xg.s['63']++;e.preventDefault();__cov_xlcucJyua6odXhLRctX6xg.s['64']++;submitButton=Y.one(this._auxiliarSubmitButtonNode);__cov_xlcucJyua6odXhLRctX6xg.s['65']++;this._cleanTagsWithNoYuiId();__cov_xlcucJyua6odXhLRctX6xg.s['66']++;this._cleanTagsWithYuiId();__cov_xlcucJyua6odXhLRctX6xg.s['67']++;submitButton.detach('click',this._cleanTagsOnSubmit);__cov_xlcucJyua6odXhLRctX6xg.s['68']++;submitButton.simulate('click');},_cleanTagsWithNoYuiId:function(){__cov_xlcucJyua6odXhLRctX6xg.f['11']++;__cov_xlcucJyua6odXhLRctX6xg.s['69']++;var textareas=Y.all('.editor_atto_content'),textarea,textareaIndex,innerHTML,spanedmlangtags,spanedmlangtag,index,cleanmlangtag,regularExpression;__cov_xlcucJyua6odXhLRctX6xg.s['70']++;regularExpression=new RegExp(OPENING_SPAN+'.*?'+'','g');__cov_xlcucJyua6odXhLRctX6xg.s['71']++;if(!textareas instanceof Array){__cov_xlcucJyua6odXhLRctX6xg.b['15'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['72']++;textarea=textareas;__cov_xlcucJyua6odXhLRctX6xg.s['73']++;textareas=[];__cov_xlcucJyua6odXhLRctX6xg.s['74']++;textareas[0]=textarea;}else{__cov_xlcucJyua6odXhLRctX6xg.b['15'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['75']++;for(textareaIndex=0;textareaIndex','');__cov_xlcucJyua6odXhLRctX6xg.s['86']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}__cov_xlcucJyua6odXhLRctX6xg.s['87']++;textarea.set('innerHTML',innerHTML);}__cov_xlcucJyua6odXhLRctX6xg.s['88']++;this.markUpdated();},_cleanTagsWithYuiId:function(){__cov_xlcucJyua6odXhLRctX6xg.f['12']++;__cov_xlcucJyua6odXhLRctX6xg.s['89']++;var textareas=Y.all('.editor_atto_content'),textarea,textareaIndex,innerHTML,spanedmlangtag,index,cleanmlangtag,regularExpression,openingspanwithyui,spanedmlangtagsdwithyui,mlangtag;__cov_xlcucJyua6odXhLRctX6xg.s['90']++;openingspanwithyui=OPENING_SPAN.replace('','g');__cov_xlcucJyua6odXhLRctX6xg.s['92']++;if(!textareas instanceof Array){__cov_xlcucJyua6odXhLRctX6xg.b['17'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['93']++;textarea=textareas;__cov_xlcucJyua6odXhLRctX6xg.s['94']++;textareas=[];__cov_xlcucJyua6odXhLRctX6xg.s['95']++;textareas[0]=textarea;}else{__cov_xlcucJyua6odXhLRctX6xg.b['17'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['96']++;for(textareaIndex=0;textareaIndex','');__cov_xlcucJyua6odXhLRctX6xg.s['108']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}__cov_xlcucJyua6odXhLRctX6xg.s['109']++;textarea.set('innerHTML',innerHTML);__cov_xlcucJyua6odXhLRctX6xg.s['110']++;this.markUpdated();}},_decorateTagsOnInit:function(){__cov_xlcucJyua6odXhLRctX6xg.f['13']++;__cov_xlcucJyua6odXhLRctX6xg.s['111']++;var textarea=Y.all('.editor_atto_content'),innerHTML,regularExpression,mlangtags,mlangtag,index,decoratedmlangtag,replacementsmade=[],notreplacedyet;__cov_xlcucJyua6odXhLRctX6xg.s['112']++;innerHTML=this._getHTMLwithCleanedTags();__cov_xlcucJyua6odXhLRctX6xg.s['113']++;regularExpression=new RegExp('{mlang.*?}','g');__cov_xlcucJyua6odXhLRctX6xg.s['114']++;mlangtags=innerHTML.match(regularExpression);__cov_xlcucJyua6odXhLRctX6xg.s['115']++;if(mlangtags!==null){__cov_xlcucJyua6odXhLRctX6xg.b['19'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['116']++;for(index=0;index';__cov_xlcucJyua6odXhLRctX6xg.s['122']++;regularExpression=new RegExp(mlangtag,'g');__cov_xlcucJyua6odXhLRctX6xg.s['123']++;innerHTML=innerHTML.replace(regularExpression,decoratedmlangtag);}else{__cov_xlcucJyua6odXhLRctX6xg.b['20'][1]++;}}__cov_xlcucJyua6odXhLRctX6xg.s['124']++;textarea.set('innerHTML',innerHTML);}else{__cov_xlcucJyua6odXhLRctX6xg.b['19'][1]++;}},_getHTMLwithCleanedTags:function(){__cov_xlcucJyua6odXhLRctX6xg.f['14']++;__cov_xlcucJyua6odXhLRctX6xg.s['125']++;var host=this.get('host'),innerHTML=host.getCleanHTML(),regexString,regularExpression,spanedmlangtags,spanedmlangtag,cleanmlangtag,index;__cov_xlcucJyua6odXhLRctX6xg.s['126']++;regexString=OPENING_SPAN+'.*?'+'';__cov_xlcucJyua6odXhLRctX6xg.s['127']++;regularExpression=new RegExp(regexString,'g');__cov_xlcucJyua6odXhLRctX6xg.s['128']++;spanedmlangtags=innerHTML.match(regularExpression);__cov_xlcucJyua6odXhLRctX6xg.s['129']++;if(spanedmlangtags!==null){__cov_xlcucJyua6odXhLRctX6xg.b['21'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['130']++;for(index=0;index','');__cov_xlcucJyua6odXhLRctX6xg.s['134']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}}else{__cov_xlcucJyua6odXhLRctX6xg.b['21'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['135']++;return innerHTML;}},{ATTRS:{languages:DEFAULT_LANGUAGE,capability:DEFAULT_CAPABILITY,highlight:DEFAULT_HIGHLIGHT,css:DEFAULT_CSS}});},'@VERSION@',{'requires':['moodle-editor_atto-plugin']}); +__cov_xlcucJyua6odXhLRctX6xg.s['1']++;YUI.add('moodle-atto_multilang2-button',function(Y,NAME){__cov_xlcucJyua6odXhLRctX6xg.f['1']++;__cov_xlcucJyua6odXhLRctX6xg.s['2']++;var CLASSES={TAG:'filter-multilang-tag'},LANG_WILDCARD='%lang',CONTENT_WILDCARD='%content',ATTR_LANGUAGES='languages',ATTR_CAPABILITY='capability',ATTR_HIGHLIGHT='highlight',ATTR_CSS='css',DEFAULT_LANGUAGE='{"en":"English (en)"}',DEFAULT_CAPABILITY=true,DEFAULT_HIGHLIGHT=true,DEFAULT_CSS='outline: 1px dotted;'+'padding: 0.1em;'+'margin: 0em 0.1em;'+'background-color: #ffffaa;',TEMPLATES={SPANED:' {mlang '+LANG_WILDCARD+'}'+CONTENT_WILDCARD+'{mlang} ',NOT_SPANED:'{mlang '+LANG_WILDCARD+'}'+CONTENT_WILDCARD+'{mlang}'},OPENING_SPAN='';__cov_xlcucJyua6odXhLRctX6xg.s['3']++;Y.namespace('M.atto_multilang2').Button=Y.Base.create('button',Y.M.editor_atto.EditorPlugin,[],{_highlight:true,initializer:function(){__cov_xlcucJyua6odXhLRctX6xg.f['2']++;__cov_xlcucJyua6odXhLRctX6xg.s['4']++;var hascapability=this.get(ATTR_CAPABILITY),toolbarItems=[];__cov_xlcucJyua6odXhLRctX6xg.s['5']++;if(hascapability){__cov_xlcucJyua6odXhLRctX6xg.b['1'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['6']++;toolbarItems=this._initializeToolbarItems();__cov_xlcucJyua6odXhLRctX6xg.s['7']++;this._highlight=this.get(ATTR_HIGHLIGHT);__cov_xlcucJyua6odXhLRctX6xg.s['8']++;this.addToolbarMenu({globalItemConfig:{callback:this._addTags},icon:'icon',iconComponent:'atto_multilang2',items:toolbarItems});__cov_xlcucJyua6odXhLRctX6xg.s['9']++;this.get('host').on('atto:selectionchanged',this._checkSelectionChange,this);__cov_xlcucJyua6odXhLRctX6xg.s['10']++;this._addDelimiterCss();__cov_xlcucJyua6odXhLRctX6xg.s['11']++;if(this._highlight){__cov_xlcucJyua6odXhLRctX6xg.b['2'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['12']++;this._decorateTagsOnInit();__cov_xlcucJyua6odXhLRctX6xg.s['13']++;this._setSubmitListeners();}else{__cov_xlcucJyua6odXhLRctX6xg.b['2'][1]++;}}else{__cov_xlcucJyua6odXhLRctX6xg.b['1'][1]++;}},_addDelimiterCss:function(){__cov_xlcucJyua6odXhLRctX6xg.f['3']++;__cov_xlcucJyua6odXhLRctX6xg.s['14']++;var css='.'+CLASSES.TAG+'{'+this.get(ATTR_CSS)+'}',style;__cov_xlcucJyua6odXhLRctX6xg.s['15']++;style=document.createElement('style');__cov_xlcucJyua6odXhLRctX6xg.s['16']++;style.type='text/css';__cov_xlcucJyua6odXhLRctX6xg.s['17']++;style.innerHTML=css;__cov_xlcucJyua6odXhLRctX6xg.s['18']++;document.head.appendChild(style);},_initializeToolbarItems:function(){__cov_xlcucJyua6odXhLRctX6xg.f['4']++;__cov_xlcucJyua6odXhLRctX6xg.s['19']++;var toolbarItems=[],languages,langCode;__cov_xlcucJyua6odXhLRctX6xg.s['20']++;languages=JSON.parse(this.get(ATTR_LANGUAGES));__cov_xlcucJyua6odXhLRctX6xg.s['21']++;for(langCode in languages){__cov_xlcucJyua6odXhLRctX6xg.s['22']++;if(languages.hasOwnProperty(langCode)){__cov_xlcucJyua6odXhLRctX6xg.b['3'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['23']++;toolbarItems.push({text:languages[langCode],callbackArgs:langCode});}else{__cov_xlcucJyua6odXhLRctX6xg.b['3'][1]++;}}__cov_xlcucJyua6odXhLRctX6xg.s['24']++;return toolbarItems;},_addTags:function(event,langCode){__cov_xlcucJyua6odXhLRctX6xg.f['5']++;__cov_xlcucJyua6odXhLRctX6xg.s['25']++;var selection,host=this.get('host'),taggedContent,content;__cov_xlcucJyua6odXhLRctX6xg.s['26']++;taggedContent=this._highlight?(__cov_xlcucJyua6odXhLRctX6xg.b['4'][0]++,TEMPLATES.SPANED):(__cov_xlcucJyua6odXhLRctX6xg.b['4'][1]++,TEMPLATES.NOT_SPANED);__cov_xlcucJyua6odXhLRctX6xg.s['27']++;selection=this._getSelectionHTML();__cov_xlcucJyua6odXhLRctX6xg.s['28']++;content=host.getSelection().toString().length===0?(__cov_xlcucJyua6odXhLRctX6xg.b['5'][0]++,' '):(__cov_xlcucJyua6odXhLRctX6xg.b['5'][1]++,selection);__cov_xlcucJyua6odXhLRctX6xg.s['29']++;taggedContent=taggedContent.replace(LANG_WILDCARD,langCode);__cov_xlcucJyua6odXhLRctX6xg.s['30']++;taggedContent=taggedContent.replace(CONTENT_WILDCARD,content);__cov_xlcucJyua6odXhLRctX6xg.s['31']++;host.insertContentAtFocusPoint(taggedContent);__cov_xlcucJyua6odXhLRctX6xg.s['32']++;this.markUpdated();},_getSelectionHTML:function(){__cov_xlcucJyua6odXhLRctX6xg.f['6']++;__cov_xlcucJyua6odXhLRctX6xg.s['33']++;var html='',selection,container,index,lenght;__cov_xlcucJyua6odXhLRctX6xg.s['34']++;if(typeof window.getSelection!=='undefined'){__cov_xlcucJyua6odXhLRctX6xg.b['6'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['35']++;selection=window.getSelection();__cov_xlcucJyua6odXhLRctX6xg.s['36']++;if(selection.rangeCount){__cov_xlcucJyua6odXhLRctX6xg.b['7'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['37']++;container=document.createElement('div');__cov_xlcucJyua6odXhLRctX6xg.s['38']++;for(index=0,lenght=selection.rangeCount;index-1;__cov_xlcucJyua6odXhLRctX6xg.s['47']++;isLangTag=nodeValue.match(/\{mlang/g).length===1;__cov_xlcucJyua6odXhLRctX6xg.s['48']++;if((__cov_xlcucJyua6odXhLRctX6xg.b['11'][0]++,isTextNode)&&(__cov_xlcucJyua6odXhLRctX6xg.b['11'][1]++,isLangTag)){__cov_xlcucJyua6odXhLRctX6xg.b['10'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['49']++;host.setSelection(host.getSelectionFromNode(Y.one(node)));}else{__cov_xlcucJyua6odXhLRctX6xg.b['10'][1]++;}},_setSubmitListeners:function(){__cov_xlcucJyua6odXhLRctX6xg.f['8']++;__cov_xlcucJyua6odXhLRctX6xg.s['50']++;var submitButtons=Y.all('input[type=submit]');__cov_xlcucJyua6odXhLRctX6xg.s['51']++;submitButtons.each(this._addListenerToSubmitButtons,this);},_addListenerToSubmitButtons:function(buttonNode){__cov_xlcucJyua6odXhLRctX6xg.f['9']++;__cov_xlcucJyua6odXhLRctX6xg.s['52']++;var buttonObject,className,parentFormClassName,notCancelButton,notSearchButton;__cov_xlcucJyua6odXhLRctX6xg.s['53']++;buttonObject=document.getElementById(buttonNode.get('id'));__cov_xlcucJyua6odXhLRctX6xg.s['54']++;if(buttonObject!==null){__cov_xlcucJyua6odXhLRctX6xg.b['12'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['55']++;className=buttonObject.className;__cov_xlcucJyua6odXhLRctX6xg.s['56']++;parentFormClassName=buttonObject.form.className;__cov_xlcucJyua6odXhLRctX6xg.s['57']++;notCancelButton=className.match(/btn-cancel/g)===null;__cov_xlcucJyua6odXhLRctX6xg.s['58']++;notSearchButton=parentFormClassName.match(/mform/g).length>0;__cov_xlcucJyua6odXhLRctX6xg.s['59']++;if((__cov_xlcucJyua6odXhLRctX6xg.b['14'][0]++,notCancelButton)&&(__cov_xlcucJyua6odXhLRctX6xg.b['14'][1]++,notSearchButton)){__cov_xlcucJyua6odXhLRctX6xg.b['13'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['60']++;buttonNode.on('click',this._cleanTagsOnSubmit,this,buttonNode);}else{__cov_xlcucJyua6odXhLRctX6xg.b['13'][1]++;}}else{__cov_xlcucJyua6odXhLRctX6xg.b['12'][1]++;}},_cleanTagsOnSubmit:function(event,submitButton){__cov_xlcucJyua6odXhLRctX6xg.f['10']++;__cov_xlcucJyua6odXhLRctX6xg.s['61']++;event.preventDefault();__cov_xlcucJyua6odXhLRctX6xg.s['62']++;this._cleanTagsWithNoYuiId();__cov_xlcucJyua6odXhLRctX6xg.s['63']++;this._cleanTagsWithYuiId();__cov_xlcucJyua6odXhLRctX6xg.s['64']++;submitButton.detach('click',this._cleanTagsOnSubmit);__cov_xlcucJyua6odXhLRctX6xg.s['65']++;submitButton.simulate('click');},_cleanTagsWithNoYuiId:function(){__cov_xlcucJyua6odXhLRctX6xg.f['11']++;__cov_xlcucJyua6odXhLRctX6xg.s['66']++;var textareas=Y.all('.editor_atto_content'),textarea,textareaIndex,innerHTML,spanedmlangtags,spanedmlangtag,index,cleanmlangtag,regularExpression;__cov_xlcucJyua6odXhLRctX6xg.s['67']++;regularExpression=new RegExp(OPENING_SPAN+'.*?'+'','g');__cov_xlcucJyua6odXhLRctX6xg.s['68']++;if(!textareas instanceof Array){__cov_xlcucJyua6odXhLRctX6xg.b['15'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['69']++;textarea=textareas;__cov_xlcucJyua6odXhLRctX6xg.s['70']++;textareas=[];__cov_xlcucJyua6odXhLRctX6xg.s['71']++;textareas[0]=textarea;}else{__cov_xlcucJyua6odXhLRctX6xg.b['15'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['72']++;for(textareaIndex=0;textareaIndex','');__cov_xlcucJyua6odXhLRctX6xg.s['83']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}__cov_xlcucJyua6odXhLRctX6xg.s['84']++;textarea.set('innerHTML',innerHTML);}__cov_xlcucJyua6odXhLRctX6xg.s['85']++;this.markUpdated();},_cleanTagsWithYuiId:function(){__cov_xlcucJyua6odXhLRctX6xg.f['12']++;__cov_xlcucJyua6odXhLRctX6xg.s['86']++;var textareas=Y.all('.editor_atto_content'),textarea,textareaIndex,innerHTML,spanedmlangtag,index,cleanmlangtag,regularExpression,openingspanwithyui,spanedmlangtagsdwithyui,mlangtag;__cov_xlcucJyua6odXhLRctX6xg.s['87']++;openingspanwithyui=OPENING_SPAN.replace('','g');__cov_xlcucJyua6odXhLRctX6xg.s['89']++;if(!textareas instanceof Array){__cov_xlcucJyua6odXhLRctX6xg.b['17'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['90']++;textarea=textareas;__cov_xlcucJyua6odXhLRctX6xg.s['91']++;textareas=[];__cov_xlcucJyua6odXhLRctX6xg.s['92']++;textareas[0]=textarea;}else{__cov_xlcucJyua6odXhLRctX6xg.b['17'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['93']++;for(textareaIndex=0;textareaIndex','');__cov_xlcucJyua6odXhLRctX6xg.s['105']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}__cov_xlcucJyua6odXhLRctX6xg.s['106']++;textarea.set('innerHTML',innerHTML);__cov_xlcucJyua6odXhLRctX6xg.s['107']++;this.markUpdated();}},_decorateTagsOnInit:function(){__cov_xlcucJyua6odXhLRctX6xg.f['13']++;__cov_xlcucJyua6odXhLRctX6xg.s['108']++;var textarea=Y.all('.editor_atto_content'),innerHTML,regularExpression,mlangtags,mlangtag,index,decoratedmlangtag,replacementsmade=[],notreplacedyet;__cov_xlcucJyua6odXhLRctX6xg.s['109']++;innerHTML=this._getHTMLwithCleanedTags();__cov_xlcucJyua6odXhLRctX6xg.s['110']++;regularExpression=new RegExp('{mlang.*?}','g');__cov_xlcucJyua6odXhLRctX6xg.s['111']++;mlangtags=innerHTML.match(regularExpression);__cov_xlcucJyua6odXhLRctX6xg.s['112']++;if(mlangtags!==null){__cov_xlcucJyua6odXhLRctX6xg.b['19'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['113']++;for(index=0;index';__cov_xlcucJyua6odXhLRctX6xg.s['119']++;regularExpression=new RegExp(mlangtag,'g');__cov_xlcucJyua6odXhLRctX6xg.s['120']++;innerHTML=innerHTML.replace(regularExpression,decoratedmlangtag);}else{__cov_xlcucJyua6odXhLRctX6xg.b['20'][1]++;}}__cov_xlcucJyua6odXhLRctX6xg.s['121']++;textarea.set('innerHTML',innerHTML);}else{__cov_xlcucJyua6odXhLRctX6xg.b['19'][1]++;}},_getHTMLwithCleanedTags:function(){__cov_xlcucJyua6odXhLRctX6xg.f['14']++;__cov_xlcucJyua6odXhLRctX6xg.s['122']++;var host=this.get('host'),innerHTML=host.getCleanHTML(),regexString,regularExpression,spanedmlangtags,spanedmlangtag,cleanmlangtag,index;__cov_xlcucJyua6odXhLRctX6xg.s['123']++;regexString=OPENING_SPAN+'.*?'+'';__cov_xlcucJyua6odXhLRctX6xg.s['124']++;regularExpression=new RegExp(regexString,'g');__cov_xlcucJyua6odXhLRctX6xg.s['125']++;spanedmlangtags=innerHTML.match(regularExpression);__cov_xlcucJyua6odXhLRctX6xg.s['126']++;if(spanedmlangtags!==null){__cov_xlcucJyua6odXhLRctX6xg.b['21'][0]++;__cov_xlcucJyua6odXhLRctX6xg.s['127']++;for(index=0;index','');__cov_xlcucJyua6odXhLRctX6xg.s['131']++;innerHTML=innerHTML.replace(spanedmlangtag,cleanmlangtag);}}else{__cov_xlcucJyua6odXhLRctX6xg.b['21'][1]++;}__cov_xlcucJyua6odXhLRctX6xg.s['132']++;return innerHTML;}},{ATTRS:{languages:DEFAULT_LANGUAGE,capability:DEFAULT_CAPABILITY,highlight:DEFAULT_HIGHLIGHT,css:DEFAULT_CSS}});},'@VERSION@',{'requires':['moodle-editor_atto-plugin']}); diff --git a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-debug.js b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-debug.js index 9deb971..194364a 100644 --- a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-debug.js +++ b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-debug.js @@ -70,16 +70,6 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att */ _highlight: true, - /** - * Used as "indirect argument" to function "_cleanTagsOnSubmit", since there is not - * any (apparent) way to pass arguments to YUI callback functions. - * - * @property _auxiliarSubmitButton - * @type Node - * @private - */ - _auxiliarSubmitButtonNode: null, - initializer: function() { var hascapability = this.get(ATTR_CAPABILITY), toolbarItems = []; @@ -164,11 +154,11 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att * it's impossible to place the cursor inside the {mlang} tags. * * @method _addTags - * @param {EventFacade} e + * @param {EventFacade} event * @param {string} langCode the language code * @private */ - _addTags: function(e, langCode) { + _addTags: function(event, langCode) { var selection, host = this.get('host'), taggedContent, @@ -247,7 +237,7 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att /** * Retrieves the inputs of type submit, and, for each element, calls the function * that sets the submit listener. Is not made in this function because there is - * not any (apparent) way to access class scope from YUI closure. + * not any (apparent) way to access class scope from YUI closure. * * @method _setSubmitListeners * @private @@ -263,9 +253,6 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att * it's not 'cancel' type, and if its parent form is of 'mform' class, because there * may be any other submit type (such us administrator's search button). * - * The button node to add the listener is passed as global property because there is - * no (apparent) way to pass arguments to YUI callback functions. - * * @method _addListenerToSubmitButtons * @param {Node} buttonNode * @private @@ -287,8 +274,7 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att notSearchButton = parentFormClassName.match(/mform/g).length > 0; if (notCancelButton && notSearchButton) { - this._auxiliarSubmitButtonNode = buttonNode; - buttonNode.on('click', this._cleanTagsOnSubmit, this); + buttonNode.on('click', this._cleanTagsOnSubmit, this, buttonNode); } } }, @@ -300,19 +286,13 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default, * an then simulates the click, to submit the form. * - * The clicked submit button ('save and return' or 'save and display'), is accessed globally, - * in '_auxiliarSubmitButtonNode' property, set by '_addListenerToSubmitButtons' function. - * * @method _cleanTagsOnSubmit - * @param {EventFacade} e + * @param {EventFacade} event + * @param {Node} submitButton * @private */ - _cleanTagsOnSubmit: function(e) { - var submitButton; - - e.preventDefault(); - - submitButton = Y.one(this._auxiliarSubmitButtonNode); + _cleanTagsOnSubmit: function(event, submitButton) { + event.preventDefault(); this._cleanTagsWithNoYuiId(); this._cleanTagsWithYuiId(); diff --git a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-min.js b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-min.js index 21e4a6c..f0d313e 100644 --- a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-min.js +++ b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button-min.js @@ -1 +1 @@ -YUI.add("moodle-atto_multilang2-button",function(e,t){var n={TAG:"filter-multilang-tag"},r="%lang",i="%content",s="languages",o="capability",u="highlight",a="css",f='{"en":"English (en)"}',l=!0,c=!0,h="outline: 1px dotted;padding: 0.1em;margin: 0em 0.1em;background-color: #ffffaa;",p={SPANED:' {mlang '+r+"}"+i+'{mlang} ',NOT_SPANED:"{mlang "+r+"}"+i+"{mlang}"},d='';e.namespace("M.atto_multilang2").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_highlight:!0,_auxiliarSubmitButtonNode:null,initializer:function(){var e=this.get(o),t=[];e&&(t=this._initializeToolbarItems(),this._highlight=this.get(u),this.addToolbarMenu({globalItemConfig:{callback:this._addTags},icon:"icon",iconComponent:"atto_multilang2",items:t}),this.get("host").on("atto:selectionchanged",this._checkSelectionChange,this),this._addDelimiterCss(),this._highlight&&(this._decorateTagsOnInit(),this._setSubmitListeners()))},_addDelimiterCss:function(){var e="."+n.TAG+"{"+this.get(a)+"}",t;t=document.createElement("style"),t.type="text/css",t.innerHTML=e,document.head.appendChild(t)},_initializeToolbarItems:function(){var e=[],t,n;t=JSON.parse(this.get(s));for(n in t)t.hasOwnProperty(n)&&e.push({text:t[n],callbackArgs:n});return e},_addTags:function(e,t){var n,s=this.get("host"),o,u;o=this._highlight?p.SPANED:p.NOT_SPANED,n=this._getSelectionHTML(),u=s.getSelection().toString().length===0?" ":n,o=o.replace(r,t),o=o.replace(i,u),s.insertContentAtFocusPoint(o),this.markUpdated()},_getSelectionHTML:function(){var e="",t,n,r,i;if(typeof window.getSelection!="undefined"){t=window.getSelection();if(t.rangeCount){n=document.createElement("div");for(r=0,i=t.rangeCount;r-1,s=r.match(/\{mlang/g).length===1,i&&s&&t.setSelection(t.getSelectionFromNode(e.one(n)))},_setSubmitListeners:function(){var t=e.all("input[type=submit]");t.each(this._addListenerToSubmitButtons,this)},_addListenerToSubmitButtons:function(e){var t,n,r,i,s;t=document.getElementById(e.get("id")),t!==null&&(n=t.className,r=t.form.className,i=n.match(/btn-cancel/g)===null,s=r.match(/mform/g).length>0,i&&s&&(this._auxiliarSubmitButtonNode=e,e.on("click",this._cleanTagsOnSubmit,this)))},_cleanTagsOnSubmit:function(t){var n;t.preventDefault(),n=e.one(this._auxiliarSubmitButtonNode),this._cleanTagsWithNoYuiId(),this._cleanTagsWithYuiId(),n.detach("click",this._cleanTagsOnSubmit),n.simulate("click")},_cleanTagsWithNoYuiId:function(){var t=e.all(".editor_atto_content"),n,r,i,s,o,u,a,f;f=new RegExp(d+".*?"+"","g"),!t instanceof Array&&(n=t,t=[],t[0]=n);for(r=0;r",""),i=i.replace(o,a);n.set("innerHTML",i)}this.markUpdated()},_cleanTagsWithYuiId:function(){var t=e.all(".editor_atto_content"),n,r,i,s,o,u,a,f,l,c;f=d.replace("","g"),!t instanceof Array&&(n=t,t=[],t[0]=n);for(r=0;r",""),i=i.replace(s,u);n.set("innerHTML",i),this.markUpdated()}},_decorateTagsOnInit:function(){var t=e.all(".editor_atto_content"),n,r,i,s,o,u,a=[],f;n=this._getHTMLwithCleanedTags(),r=new RegExp("{mlang.*?}","g"),i=n.match(r);if(i!==null){for(o=0;o",r=new RegExp(s,"g"),n=n.replace(r,u));t.set("innerHTML",n)}},_getHTMLwithCleanedTags:function(){var e=this.get("host"),t=e.getCleanHTML(),n,r,i,s,o,u;n=d+".*?"+"",r=new RegExp(n,"g"),i=t.match(r);if(i!==null)for(u=0;u",""),t=t.replace(s,o);return t}},{ATTRS:{languages:f,capability:l,highlight:c,css:h}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); +YUI.add("moodle-atto_multilang2-button",function(e,t){var n={TAG:"filter-multilang-tag"},r="%lang",i="%content",s="languages",o="capability",u="highlight",a="css",f='{"en":"English (en)"}',l=!0,c=!0,h="outline: 1px dotted;padding: 0.1em;margin: 0em 0.1em;background-color: #ffffaa;",p={SPANED:' {mlang '+r+"}"+i+'{mlang} ',NOT_SPANED:"{mlang "+r+"}"+i+"{mlang}"},d='';e.namespace("M.atto_multilang2").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_highlight:!0,initializer:function(){var e=this.get(o),t=[];e&&(t=this._initializeToolbarItems(),this._highlight=this.get(u),this.addToolbarMenu({globalItemConfig:{callback:this._addTags},icon:"icon",iconComponent:"atto_multilang2",items:t}),this.get("host").on("atto:selectionchanged",this._checkSelectionChange,this),this._addDelimiterCss(),this._highlight&&(this._decorateTagsOnInit(),this._setSubmitListeners()))},_addDelimiterCss:function(){var e="."+n.TAG+"{"+this.get(a)+"}",t;t=document.createElement("style"),t.type="text/css",t.innerHTML=e,document.head.appendChild(t)},_initializeToolbarItems:function(){var e=[],t,n;t=JSON.parse(this.get(s));for(n in t)t.hasOwnProperty(n)&&e.push({text:t[n],callbackArgs:n});return e},_addTags:function(e,t){var n,s=this.get("host"),o,u;o=this._highlight?p.SPANED:p.NOT_SPANED,n=this._getSelectionHTML(),u=s.getSelection().toString().length===0?" ":n,o=o.replace(r,t),o=o.replace(i,u),s.insertContentAtFocusPoint(o),this.markUpdated()},_getSelectionHTML:function(){var e="",t,n,r,i;if(typeof window.getSelection!="undefined"){t=window.getSelection();if(t.rangeCount){n=document.createElement("div");for(r=0,i=t.rangeCount;r-1,s=r.match(/\{mlang/g).length===1,i&&s&&t.setSelection(t.getSelectionFromNode(e.one(n)))},_setSubmitListeners:function(){var t=e.all("input[type=submit]");t.each(this._addListenerToSubmitButtons,this)},_addListenerToSubmitButtons:function(e){var t,n,r,i,s;t=document.getElementById(e.get("id")),t!==null&&(n=t.className,r=t.form.className,i=n.match(/btn-cancel/g)===null,s=r.match(/mform/g).length>0,i&&s&&e.on("click",this._cleanTagsOnSubmit,this,e))},_cleanTagsOnSubmit:function(e,t){e.preventDefault(),this._cleanTagsWithNoYuiId(),this._cleanTagsWithYuiId(),t.detach("click",this._cleanTagsOnSubmit),t.simulate("click")},_cleanTagsWithNoYuiId:function(){var t=e.all(".editor_atto_content"),n,r,i,s,o,u,a,f;f=new RegExp(d+".*?"+"","g"),!t instanceof Array&&(n=t,t=[],t[0]=n);for(r=0;r",""),i=i.replace(o,a);n.set("innerHTML",i)}this.markUpdated()},_cleanTagsWithYuiId:function(){var t=e.all(".editor_atto_content"),n,r,i,s,o,u,a,f,l,c;f=d.replace("","g"),!t instanceof Array&&(n=t,t=[],t[0]=n);for(r=0;r",""),i=i.replace(s,u);n.set("innerHTML",i),this.markUpdated()}},_decorateTagsOnInit:function(){var t=e.all(".editor_atto_content"),n,r,i,s,o,u,a=[],f;n=this._getHTMLwithCleanedTags(),r=new RegExp("{mlang.*?}","g"),i=n.match(r);if(i!==null){for(o=0;o",r=new RegExp(s,"g"),n=n.replace(r,u));t.set("innerHTML",n)}},_getHTMLwithCleanedTags:function(){var e=this.get("host"),t=e.getCleanHTML(),n,r,i,s,o,u;n=d+".*?"+"",r=new RegExp(n,"g"),i=t.match(r);if(i!==null)for(u=0;u",""),t=t.replace(s,o);return t}},{ATTRS:{languages:f,capability:l,highlight:c,css:h}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); diff --git a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js index 9deb971..194364a 100644 --- a/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js +++ b/yui/build/moodle-atto_multilang2-button/moodle-atto_multilang2-button.js @@ -70,16 +70,6 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att */ _highlight: true, - /** - * Used as "indirect argument" to function "_cleanTagsOnSubmit", since there is not - * any (apparent) way to pass arguments to YUI callback functions. - * - * @property _auxiliarSubmitButton - * @type Node - * @private - */ - _auxiliarSubmitButtonNode: null, - initializer: function() { var hascapability = this.get(ATTR_CAPABILITY), toolbarItems = []; @@ -164,11 +154,11 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att * it's impossible to place the cursor inside the {mlang} tags. * * @method _addTags - * @param {EventFacade} e + * @param {EventFacade} event * @param {string} langCode the language code * @private */ - _addTags: function(e, langCode) { + _addTags: function(event, langCode) { var selection, host = this.get('host'), taggedContent, @@ -247,7 +237,7 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att /** * Retrieves the inputs of type submit, and, for each element, calls the function * that sets the submit listener. Is not made in this function because there is - * not any (apparent) way to access class scope from YUI closure. + * not any (apparent) way to access class scope from YUI closure. * * @method _setSubmitListeners * @private @@ -263,9 +253,6 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att * it's not 'cancel' type, and if its parent form is of 'mform' class, because there * may be any other submit type (such us administrator's search button). * - * The button node to add the listener is passed as global property because there is - * no (apparent) way to pass arguments to YUI callback functions. - * * @method _addListenerToSubmitButtons * @param {Node} buttonNode * @private @@ -287,8 +274,7 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att notSearchButton = parentFormClassName.match(/mform/g).length > 0; if (notCancelButton && notSearchButton) { - this._auxiliarSubmitButtonNode = buttonNode; - buttonNode.on('click', this._cleanTagsOnSubmit, this); + buttonNode.on('click', this._cleanTagsOnSubmit, this, buttonNode); } } }, @@ -300,19 +286,13 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default, * an then simulates the click, to submit the form. * - * The clicked submit button ('save and return' or 'save and display'), is accessed globally, - * in '_auxiliarSubmitButtonNode' property, set by '_addListenerToSubmitButtons' function. - * * @method _cleanTagsOnSubmit - * @param {EventFacade} e + * @param {EventFacade} event + * @param {Node} submitButton * @private */ - _cleanTagsOnSubmit: function(e) { - var submitButton; - - e.preventDefault(); - - submitButton = Y.one(this._auxiliarSubmitButtonNode); + _cleanTagsOnSubmit: function(event, submitButton) { + event.preventDefault(); this._cleanTagsWithNoYuiId(); this._cleanTagsWithYuiId(); diff --git a/yui/src/button/js/button.js b/yui/src/button/js/button.js index 592339a..dca595a 100644 --- a/yui/src/button/js/button.js +++ b/yui/src/button/js/button.js @@ -68,16 +68,6 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att */ _highlight: true, - /** - * Used as "indirect argument" to function "_cleanTagsOnSubmit", since there is not - * any (apparent) way to pass arguments to YUI callback functions. - * - * @property _auxiliarSubmitButton - * @type Node - * @private - */ - _auxiliarSubmitButtonNode: null, - initializer: function() { var hascapability = this.get(ATTR_CAPABILITY), toolbarItems = []; @@ -162,11 +152,11 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att * it's impossible to place the cursor inside the {mlang} tags. * * @method _addTags - * @param {EventFacade} e + * @param {EventFacade} event * @param {string} langCode the language code * @private */ - _addTags: function(e, langCode) { + _addTags: function(event, langCode) { var selection, host = this.get('host'), taggedContent, @@ -245,7 +235,7 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att /** * Retrieves the inputs of type submit, and, for each element, calls the function * that sets the submit listener. Is not made in this function because there is - * not any (apparent) way to access class scope from YUI closure. + * not any (apparent) way to access class scope from YUI closure. * * @method _setSubmitListeners * @private @@ -261,9 +251,6 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att * it's not 'cancel' type, and if its parent form is of 'mform' class, because there * may be any other submit type (such us administrator's search button). * - * The button node to add the listener is passed as global property because there is - * no (apparent) way to pass arguments to YUI callback functions. - * * @method _addListenerToSubmitButtons * @param {Node} buttonNode * @private @@ -285,8 +272,7 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att notSearchButton = parentFormClassName.match(/mform/g).length > 0; if (notCancelButton && notSearchButton) { - this._auxiliarSubmitButtonNode = buttonNode; - buttonNode.on('click', this._cleanTagsOnSubmit, this); + buttonNode.on('click', this._cleanTagsOnSubmit, this, buttonNode); } } }, @@ -298,19 +284,13 @@ Y.namespace('M.atto_multilang2').Button = Y.Base.create('button', Y.M.editor_att * Once the textarea is cleaned, detaches this submit listener, i.e., it sets as default, * an then simulates the click, to submit the form. * - * The clicked submit button ('save and return' or 'save and display'), is accessed globally, - * in '_auxiliarSubmitButtonNode' property, set by '_addListenerToSubmitButtons' function. - * * @method _cleanTagsOnSubmit - * @param {EventFacade} e + * @param {EventFacade} event + * @param {Node} submitButton * @private */ - _cleanTagsOnSubmit: function(e) { - var submitButton; - - e.preventDefault(); - - submitButton = Y.one(this._auxiliarSubmitButtonNode); + _cleanTagsOnSubmit: function(event, submitButton) { + event.preventDefault(); this._cleanTagsWithNoYuiId(); this._cleanTagsWithYuiId(); From 7a90a4c2075e4274f48e3b370acb639156f16988 Mon Sep 17 00:00:00 2001 From: Julen Pardo Date: Thu, 26 May 2016 15:15:01 +0200 Subject: [PATCH 7/7] master: update README and version.php for v1.6 release --- README.md | 8 ++++---- version.php | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 22b4ad5..19c9fd4 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ Atto multilanguage plugin ========================= -![Release](https://img.shields.io/badge/release-v1.5-brightgreen.svg) ![Supported](https://img.shields.io/badge/supported-Moodle%202.9,%20Moodle%203.0-green.svg) +![Release](https://img.shields.io/badge/release-v1.6-blue.svg) ![Supported](https://img.shields.io/badge/supported-2.9%2C%203.0%2C%203.1-green.svg) This plugin will make the creation of multilingual contents on Moodle much more easier with Atto editor. The plugin is developed to work with [IƱaki Arenaza's multilang2 filter](https://github.com/iarenaza/moodle-filter_multilang2), and the idea is based on [his plugin for TinyMCE editor](https://github.com/iarenaza/moodle-tinymce_moodlelang2). ## Current version -The latest release is the v1.5 (build 2016042800) for Moodle 2.9 and 3.0. Checkout [v2.9.1.5](https://github.com/julenpardo/moodle-atto_multilang2/releases/tag/v2.9.1.5) and [v3.0.1.5](https://github.com/julenpardo/moodle-atto_multilang2/releases/tag/v3.0.1.5) releases, respectively. +The latest release is the v1.6 (build 2016042800) for Moodle 2.9, 3.0 and 3.1. Checkout [v2.9.1.6](https://github.com/julenpardo/moodle-atto_multilang2/releases/tag/v2.9.1.6), [v3.0.1.6](https://github.com/julenpardo/moodle-atto_multilang2/releases/tag/v3.0.1.6), and [v3.1.1.6](https://github.com/julenpardo/moodle-atto_multilang2/releases/tag/v3.1.1.6) releases, respectively. -## Changes from v1.4 - - Fix issue "Quiz cannot be evaluated" (see [issue 15](https://github.com/julenpardo/moodle-atto_multilang2/issues/15)). +## Changes from v1.5 + - Fix issue "Filepicker not loading when grading assignment" (see [issue 17](https://github.com/julenpardo/moodle-atto_multilang2/issues/17)). ## Requirements As mentioned before, [filter_multilang2](https://github.com/iarenaza/moodle-filter_multilang2) is required. diff --git a/version.php b/version.php index 2a76fed..411370e 100644 --- a/version.php +++ b/version.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Atto Multilingual content plugin version details. * @@ -20,10 +21,11 @@ * @copyright 2015 onwards Julen Pardo & Mondragon Unibertsitatea * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016042800; // The current plugin version (Date: YYYYMMDDXX). -$plugin->release = 'master - Release v1.5 (Build 2016042800) for Moodle v2.9 and v3.0'; +$plugin->version = 2016052600; // The current plugin version (Date: YYYYMMDDXX). +$plugin->release = 'master - Release v1.6 (Build 2016052600) for Moodle 2.9, 3.0 and 3.1'; $plugin->requires = 2015051100; // Required Moodle version. $plugin->component = 'atto_multilang2'; // Full name of the plugin (used for diagnostics). $plugin->maturity = MATURITY_STABLE;