{"version":3,"file":"learningbookmarks.min.js","sources":["https:\/\/learn.greencultured.co\/local\/learningtools\/ltool\/bookmarks\/amd\/src\/learningbookmarks.js"],"sourcesContent":["\/\/ This file is part of Moodle - http:\/\/moodle.org\/\n\/\/\n\/\/ Moodle is free software: you can redistribute it and\/or modify\n\/\/ it under the terms of the GNU General Public License as published by\n\/\/ the Free Software Foundation, either version 3 of the License, or\n\/\/ (at your option) any later version.\n\/\/\n\/\/ Moodle is distributed in the hope that it will be useful,\n\/\/ but WITHOUT ANY WARRANTY; without even the implied warranty of\n\/\/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\/\/ GNU General Public License for more details.\n\/\/\n\/\/ You should have received a copy of the GNU General Public License\n\/\/ along with Moodle. If not, see .\n\n\/**\n * Bookmarks ltool define js.\n * @module ltool_bookmarks\n * @category Classes - autoloading\n * @copyright 2021, bdecent gmbh bdecent.de\n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\ndefine(['core\/str', 'core\/ajax', 'core\/notification'],\n function(String, Ajax, notification) {\n\n \/* global ltools, pagebookmarks *\/\n\n \/**\n * Controls bookmarks tool action.\n * @param {int} contextid\n * @param {object} params\n *\/\n function learningToolBookmarksAction(contextid, params) {\n\n var bookmarkmarked = document.getElementById('bookmarks-marked');\n if (bookmarkmarked) {\n if (pagebookmarks) {\n bookmarkmarked.classList.add('marked');\n } else {\n bookmarkmarked.classList.remove('marked');\n }\n }\n\n var bookmarksform = document.getElementById('ltbookmarks-action');\n if (bookmarksform) {\n bookmarksform.addEventListener(\"click\", function(e) {\n e.preventDefault();\n submitFormdata(contextid, params);\n });\n \/\/ Hover color.\n var bookmarkshovercolor = bookmarksform.getAttribute(\"data-hovercolor\");\n var bookmarksfontcolor = bookmarksform.getAttribute(\"data-fontcolor\");\n if (bookmarkshovercolor && bookmarksfontcolor) {\n bookmarksform.addEventListener(\"mouseover\", function() {\n document.querySelector('#ltbookmarksinfo p').style.background = bookmarkshovercolor;\n document.querySelector('#ltbookmarksinfo p').style.color = bookmarksfontcolor;\n });\n }\n\n }\n var bookmarkssorttype = document.getElementById(\"bookmarkssorttype\");\n\n if (bookmarkssorttype) {\n bookmarkssorttype.addEventListener(\"click\", function() {\n var sorttype = this.getAttribute(\"data-type\");\n bookmarksSortActionPage(sorttype);\n });\n }\n }\n\n \/**\n * Sort the bookmarks list.\n * @param {string} sorttype type of sort\n * @return {void}\n *\/\n function bookmarksSortActionPage(sorttype) {\n\n var pageurl = window.location.href;\n var para = '';\n pageurl = removeURLParameter(pageurl, 'sorttype');\n\n if (sorttype == 'asc') {\n sorttype = 'desc';\n } else if (sorttype == 'desc') {\n sorttype = 'asc';\n }\n\n if (pageurl.indexOf('?') > -1) {\n para = '&';\n } else {\n para = '?';\n }\n\n pageurl = pageurl + para + 'sorttype=' + sorttype;\n window.open(pageurl, '_self');\n }\n\n\n \/**\n * Clean the url parameters.\n * @param {string} url page url.\n * @param {string} parameter url parameter.\n * @return {url} sort url\n *\/\n function removeURLParameter(url, parameter) {\n \/\/ Prefer to use l.search if you have a location\/link object.\n var urlparts = url.split('?');\n if (urlparts.length >= 2) {\n\n var prefix = encodeURIComponent(parameter) + '=';\n var pars = urlparts[1].split(\/[&;]\/g);\n\n \/\/ Reverse iteration as may be destructive.\n for (var i = pars.length; i-- > 0;) {\n \/\/ Idiom for string.startsWith.\n if (pars[i].lastIndexOf(prefix, 0) !== -1) {\n pars.splice(i, 1);\n }\n }\n url = urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : \"\");\n return url;\n } else {\n return url;\n }\n }\n\n \/**\n * Bookmarks submit the form data.\n * @param {int} contextid context id.\n * @param {object} formData form instance data.\n * @return {void} ajax response\n *\/\n function submitFormdata(contextid, formData) {\n\n if (formData.pagetitle == \"\") {\n formData.pagetitle = document.querySelector('title').innerHTML;\n }\n var Formdata = JSON.stringify(formData);\n Ajax.call([{\n methodname: 'ltool_bookmarks_save_userbookmarks',\n args: {contextid: contextid, formdata: Formdata},\n done: function(response) {\n\n notification.addNotification({\n message: response.bookmarksmsg,\n type: response.notificationtype\n });\n\n let bookmarkmarked = document.getElementById('bookmarks-marked');\n if (response.bookmarksstatus) {\n bookmarkmarked.classList.add('marked');\n } else {\n bookmarkmarked.classList.remove('marked');\n }\n\n if (ltools.disappertimenotify != 0) {\n setTimeout(function() {\n document.querySelector(\"span.notifications\").innerHTML = \"\";\n }, ltools.disappertimenotify);\n }\n\n },\n }]);\n }\n\n return {\n init: function(contextid, params) {\n learningToolBookmarksAction(contextid, params);\n }\n };\n});\n"],"names":["define","String","Ajax","notification","learningToolBookmarksAction","contextid","params","bookmarkmarked","document","getElementById","pagebookmarks","classList","add","remove","bookmarksform","addEventListener","e","preventDefault","formData","pagetitle","querySelector","innerHTML","Formdata","JSON","stringify","call","methodname","args","formdata","done","response","addNotification","message","bookmarksmsg","type","notificationtype","bookmarksstatus","ltools","disappertimenotify","setTimeout","submitFormdata","bookmarkshovercolor","getAttribute","bookmarksfontcolor","style","background","color","bookmarkssorttype","sorttype","pageurl","window","location","href","para","url","parameter","urlparts","split","length","prefix","encodeURIComponent","pars","i","lastIndexOf","splice","join","removeURLParameter","indexOf","open","bookmarksSortActionPage","this","init"],"mappings":";;;;;;;AAuBAA,2CAAO,CAAC,WAAY,YAAa,sBAC7B,SAASC,OAAQC,KAAMC,uBASdC,4BAA4BC,UAAWC,YAExCC,eAAiBC,SAASC,eAAe,oBACzCF,iBACIG,cACAH,eAAeI,UAAUC,IAAI,UAE7BL,eAAeI,UAAUE,OAAO,eAIpCC,cAAgBN,SAASC,eAAe,yBACxCK,cAAe,CACfA,cAAcC,iBAAiB,SAAS,SAASC,GAC7CA,EAAEC,0BAsFUZ,UAAWa,UAEL,IAAtBA,SAASC,YACTD,SAASC,UAAYX,SAASY,cAAc,SAASC,eAErDC,SAAWC,KAAKC,UAAUN,UAC9BhB,KAAKuB,KAAK,CAAC,CACPC,WAAY,qCACZC,KAAM,CAACtB,UAAWA,UAAWu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