Your IP : 192.168.165.1


Current Path : C:/Users/Mahmood/Desktop/moodle/lib/amd/build/
Upload File :
Current File : C:/Users/Mahmood/Desktop/moodle/lib/amd/build/paged_content_pages.min.js.map

{"version":3,"sources":["../src/paged_content_pages.js"],"names":["define","$","Templates","Notification","PubSub","PagedContentEvents","SELECTORS","ROOT","PAGE_REGION","ACTIVE_PAGE_REGION","TEMPLATES","PAGING_CONTENT_ITEM","LOADING","findPage","root","pageNumber","find","startLoading","deferred","Deferred","attr","render","visible","then","html","loadingSpinner","timerId","setTimeout","css","appendTo","always","clearTimeout","remove","removeAttr","fail","exception","renderPagePromise","pagePromise","pageJS","page","content","appendNodeContents","resolve","reject","promise","showPages","pagesData","id","renderPagesContentCallback","existingPages","newPageData","newPagesPromise","forEach","pageData","existingPage","length","push","promises","allItemsLoaded","lastPageNumber","publish","ALL_ITEMS_LOADED","renderPagePromises","map","index","when","apply","newPages","Array","prototype","slice","call","arguments","loadingPromise","pagesToShow","concat","addClass","removeClass","PAGES_SHOWN","init","subscribe","SHOW_PAGES","SET_ITEMS_PER_PAGE_LIMIT","empty","rootSelector"],"mappings":"AAsBAA,OAAM,4BACF,CACI,QADJ,CAEI,gBAFJ,CAGI,mBAHJ,CAII,aAJJ,CAKI,2BALJ,CADE,CAQF,SACIC,CADJ,CAEIC,CAFJ,CAGIC,CAHJ,CAIIC,CAJJ,CAKIC,CALJ,CAME,IAEEC,CAAAA,CAAS,CAAG,CACZC,IAAI,CAAE,kCADM,CAEZC,WAAW,CAAE,sCAFD,CAGZC,kBAAkB,CAAE,6CAHR,CAFd,CAQEC,CAAS,CAAG,CACZC,mBAAmB,CAAE,yBADT,CAEZC,OAAO,CAAE,sBAFG,CARd,CAsBEC,CAAQ,CAAG,SAASC,CAAT,CAAeC,CAAf,CAA2B,CACtC,MAAOD,CAAAA,CAAI,CAACE,IAAL,CAAU,gBAAiBD,CAAjB,CAA8B,KAAxC,CACV,CAxBC,CAoCEE,CAAY,CAAG,SAASH,CAAT,CAA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,CAEH,CAnBD,EAoBCZ,IApBD,CAoBM/B,CAAY,CAACgC,SApBnB,EAqBCL,MArBD,CAqBQ,UAAW,CACf2C,CAAc,CAAC/B,OAAf,EACH,CAvBD,CAwBH,CA/NC,CA+QF,MAAO,CACHqC,IAAI,CAfG,QAAPA,CAAAA,IAAO,CAASjE,CAAT,CAAeiC,CAAf,CAAmBC,CAAnB,CAA+C,CACtDlC,CAAI,CAAGb,CAAC,CAACa,CAAD,CAAR,CAEAV,CAAM,CAAC4E,SAAP,CAAiBjC,CAAE,CAAG1C,CAAkB,CAAC4E,UAAzC,CAAqD,SAASnC,CAAT,CAAoB,CACrED,CAAS,CAAC/B,CAAD,CAAOgC,CAAP,CAAkBC,CAAlB,CAAsBC,CAAtB,CACZ,CAFD,EAIA5C,CAAM,CAAC4E,SAAP,CAAiBjC,CAAE,CAAG1C,CAAkB,CAAC6E,wBAAzC,CAAmE,UAAW,CAG1EpE,CAAI,CAACqE,KAAL,EACH,CAJD,CAKH,CAEM,CAEHC,YAAY,CAAE9E,CAAS,CAACC,IAFrB,CAIV,CAjSK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Javascript for showing/hiding pages of content.\n *\n * @module     core/paged_content_pages\n * @copyright  2018 Ryan Wyllie <ryan@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n    [\n        'jquery',\n        'core/templates',\n        'core/notification',\n        'core/pubsub',\n        'core/paged_content_events'\n    ],\n    function(\n        $,\n        Templates,\n        Notification,\n        PubSub,\n        PagedContentEvents\n    ) {\n\n    var SELECTORS = {\n        ROOT: '[data-region=\"page-container\"]',\n        PAGE_REGION: '[data-region=\"paged-content-page\"]',\n        ACTIVE_PAGE_REGION: '[data-region=\"paged-content-page\"].active'\n    };\n\n    var TEMPLATES = {\n        PAGING_CONTENT_ITEM: 'core/paged_content_page',\n        LOADING: 'core/overlay_loading'\n    };\n\n    var PRELOADING_GRACE_PERIOD = 300;\n\n    /**\n     * Find a page by the number.\n     *\n     * @param {object} root The root element.\n     * @param {Number} pageNumber The number of the page to be found.\n     * @returns {jQuery} The page.\n     */\n    var findPage = function(root, pageNumber) {\n        return root.find('[data-page=\"' + pageNumber + '\"]');\n    };\n\n    /**\n     * Show the loading spinner until the returned deferred is resolved by the\n     * calling code.\n     *\n     * The loading spinner is only rendered after a short grace period to avoid\n     * having it flash up briefly in the interface.\n     *\n     * @param {object} root The root element.\n     * @returns {promise} The page.\n     */\n    var startLoading = function(root) {\n        var deferred = $.Deferred();\n        root.attr('aria-busy', true);\n\n        Templates.render(TEMPLATES.LOADING, {visible: true})\n            .then(function(html) {\n                var loadingSpinner = $(html);\n                // Put this in a timer to give the calling code 300 milliseconds\n                // to render the content before we show the loading spinner. This\n                // helps prevent a loading icon flicker on close to instant\n                // rendering.\n                var timerId = setTimeout(function() {\n                    root.css('position', 'relative');\n                    loadingSpinner.appendTo(root);\n                }, PRELOADING_GRACE_PERIOD);\n\n                deferred.always(function() {\n                    clearTimeout(timerId);\n                    // Remove the loading spinner when our deferred is resolved\n                    // by the calling code.\n                    loadingSpinner.remove();\n                    root.css('position', '');\n                    root.removeAttr('aria-busy');\n                    return;\n                });\n\n                return;\n            })\n            .fail(Notification.exception);\n\n        return deferred;\n    };\n\n    /**\n     * Render the result of the page promise in a paged content page.\n     *\n     * This function returns a promise that is resolved with the new paged content\n     * page.\n     *\n     * @param {object} root The root element.\n     * @param {promise} pagePromise The promise resolved with HTML and JS to render in the page.\n     * @param {Number} pageNumber The page number.\n     * @returns {promise} The page.\n     */\n    var renderPagePromise = function(root, pagePromise, pageNumber) {\n        var deferred = $.Deferred();\n        pagePromise.then(function(html, pageJS) {\n            pageJS = pageJS || '';\n            // When we get the contents to be rendered we can pass it in as the\n            // content for a new page.\n            Templates.render(TEMPLATES.PAGING_CONTENT_ITEM, {\n                page: pageNumber,\n                content: html\n            })\n            .then(function(html) {\n                // Make sure the JS we got from the page promise is being added\n                // to the page when we render the page.\n                Templates.appendNodeContents(root, html, pageJS);\n                var page = findPage(root, pageNumber);\n                deferred.resolve(page);\n                return;\n            })\n            .fail(function(exception) {\n                deferred.reject(exception);\n            })\n            .fail(Notification.exception);\n\n            return;\n        })\n        .fail(function(exception) {\n            deferred.reject(exception);\n            return;\n        })\n        .fail(Notification.exception);\n\n        return deferred.promise();\n    };\n\n    /**\n     * Make one or more pages visible based on the SHOW_PAGES event. The show\n     * pages event provides data containing which pages should be shown as well\n     * as the limit and offset values for loading the items for each of those pages.\n     *\n     * The renderPagesContentCallback is provided this list of data to know which\n     * pages to load. E.g. the data to load 2 pages might look like:\n     * [\n     *      {\n     *          pageNumber: 1,\n     *          limit: 5,\n     *          offset: 0\n     *      },\n     *      {\n     *          pageNumber: 2,\n     *          limit: 5,\n     *          offset: 5\n     *      }\n     * ]\n     *\n     * The renderPagesContentCallback should return an array of promises, one for\n     * each page in the pages data, that is resolved with the HTML and JS for that page.\n     *\n     * If the renderPagesContentCallback is not provided then it is assumed that\n     * all pages have been rendered prior to initialising this module.\n     *\n     * This function triggers the PAGES_SHOWN event after the pages have been rendered.\n     *\n     * @param {object} root The root element.\n     * @param {Number} pagesData The data for which pages need to be visible.\n     * @param {string} id A unique id for this instance.\n     * @param {function} renderPagesContentCallback Render pages content.\n     */\n    var showPages = function(root, pagesData, id, renderPagesContentCallback) {\n        var existingPages = [];\n        var newPageData = [];\n        var newPagesPromise = $.Deferred();\n        var shownewpage = true;\n        // Check which of the pages being requests have previously been rendered\n        // so that we only ask for new pages to be rendered by the callback.\n        pagesData.forEach(function(pageData) {\n            var pageNumber = pageData.pageNumber;\n            var existingPage = findPage(root, pageNumber);\n            if (existingPage.length) {\n                existingPages.push(existingPage);\n            } else {\n                newPageData.push(pageData);\n            }\n        });\n\n        if (newPageData.length && typeof renderPagesContentCallback === 'function') {\n            // If we have pages we haven't previously seen then ask the client code\n            // to render them for us by calling the callback.\n            var promises = renderPagesContentCallback(newPageData, {\n                allItemsLoaded: function(lastPageNumber) {\n                    PubSub.publish(id + PagedContentEvents.ALL_ITEMS_LOADED, lastPageNumber);\n                }\n            });\n            // After the client has finished rendering each of the pages being asked\n            // for then begin our rendering process to put that content into paged\n            // content pages.\n            var renderPagePromises = promises.map(function(promise, index) {\n                // Create our promise for when our rendering will be completed.\n                return renderPagePromise(root, promise, newPageData[index].pageNumber);\n            });\n            // After each of our rendering promises have been completed then we can\n            // give all of the new pages to the next bit of code for handling.\n            $.when.apply($, renderPagePromises)\n                .then(function() {\n                    var newPages = Array.prototype.slice.call(arguments);\n                    // Resolve the promise with the list of newly rendered pages.\n                    newPagesPromise.resolve(newPages);\n                    return;\n                })\n                .fail(function(exception) {\n                    newPagesPromise.reject(exception);\n                    return;\n                })\n                .fail(Notification.exception);\n        } else {\n            // If there aren't any pages to load then immediately resolve the promise.\n            newPagesPromise.resolve([]);\n        }\n\n        var loadingPromise = startLoading(root);\n        newPagesPromise.then(function(newPages) {\n            // Once all of the new pages have been created then add them to any\n            // existing pages we have.\n            var pagesToShow = existingPages.concat(newPages);\n            // Hide all existing pages.\n            root.find(SELECTORS.PAGE_REGION).addClass('hidden');\n            // Show each of the pages that were requested.;\n            pagesToShow.forEach(function(page) {\n                if (shownewpage) {\n                    page.removeClass('hidden');\n                }\n            });\n\n            return;\n        })\n        .then(function() {\n            // Let everything else know we've displayed the pages.\n            PubSub.publish(id + PagedContentEvents.PAGES_SHOWN, pagesData);\n            return;\n        })\n        .fail(Notification.exception)\n        .always(function() {\n            loadingPromise.resolve();\n        });\n    };\n\n    /**\n     * Initialise the module to listen for SHOW_PAGES events and render the\n     * appropriate pages using the provided renderPagesContentCallback function.\n     *\n     * The renderPagesContentCallback is provided a list of data to know which\n     * pages to load.\n     * E.g. the data to load 2 pages might look like:\n     * [\n     *      {\n     *          pageNumber: 1,\n     *          limit: 5,\n     *          offset: 0\n     *      },\n     *      {\n     *          pageNumber: 2,\n     *          limit: 5,\n     *          offset: 5\n     *      }\n     * ]\n     *\n     * The renderPagesContentCallback should return an array of promises, one for\n     * each page in the pages data, that is resolved with the HTML and JS for that page.\n     *\n     * If the renderPagesContentCallback is not provided then it is assumed that\n     * all pages have been rendered prior to initialising this module.\n     *\n     * The event element is the element to listen for the paged content events on.\n     *\n     * @param {object} root The root element.\n     * @param {string} id A unique id for this instance.\n     * @param {function} renderPagesContentCallback Render pages content.\n     */\n    var init = function(root, id, renderPagesContentCallback) {\n        root = $(root);\n\n        PubSub.subscribe(id + PagedContentEvents.SHOW_PAGES, function(pagesData) {\n            showPages(root, pagesData, id, renderPagesContentCallback);\n        });\n\n        PubSub.subscribe(id + PagedContentEvents.SET_ITEMS_PER_PAGE_LIMIT, function() {\n            // If the items per page limit was changed then we need to clear our content\n            // the load new values based on the new limit.\n            root.empty();\n        });\n    };\n\n    return {\n        init: init,\n        rootSelector: SELECTORS.ROOT,\n    };\n});\n"],"file":"paged_content_pages.min.js"}