|
1
|
|
-!function(){lpGlobalSettings.courses_url;const e=document.location.href;let t,r,o=JSON.parse(window.localStorage.getItem("lp_filter_courses"))||{},s=!1,n=1,c=null,l=null;lpGlobalSettings.is_course_archive&&(window.location.search.length||-1!==e.search("page")||(o={}));const a=(e,t)=>{const r=new URL(e);return Object.keys(t).forEach((e=>{r.searchParams.set(e,t[e])})),r};window.lpArchiveRequestCourse=(e,o)=>{const c=lpGlobalSettings.lp_rest_url;if(!c)return;if(!t)return;const u=l&&l.querySelector("div.lp-archive-courses .lp-content-area"),p=u&&u.querySelector("ul.learn-press-courses");if(!p)return;if(s)return;s=!0,r?p.append(t):r=t.outerHTML;const h=a(c+"lp/v1/courses/archive-course",{...lpGlobalSettings.lpArchiveSkeleton,...e}),d=lpGlobalSettings.lp_rest_url+"lp/v1/courses/archive-course"+h.search;fetch(d,{method:"GET"}).then((e=>e.json())).then((e=>{void 0!==e.data.content&&p&&(p.innerHTML=e.data.content||"");const t=e.data.pagination,r=document.querySelector(".learn-press-pagination");if(r&&r.remove(),void 0!==t){const e=(new DOMParser).parseFromString(t,"text/html").querySelector(".learn-press-pagination");e&&(p.after(e),i())}wp.hooks.doAction("lp-js-get-courses",e),"function"==typeof o&&o(e)})).catch((e=>{p.innerHTML+=`<div class="lp-ajax-message error" style="display:block">${e.message||"Error: Query lp/v1/courses/archive-course"}</div>`,console.log(e)})).finally((()=>{if(s=!1,jQuery("form.search-courses button").removeClass("loading"),n)n=0;else{const e={behavior:"smooth"};l.scrollIntoView(e)}window.localStorage.setItem("lp_filter_courses",JSON.stringify(e));const t=a(document.location,e);window.history.pushState("","",t)}))};const i=()=>{const e=document.querySelectorAll(".lp-archive-courses .learn-press-pagination .page-numbers");e.length>0&&e.forEach((r=>r.addEventListener("click",(o=>{if(o.preventDefault(),o.stopPropagation(),!l)return;t&&(t.style.display="block"),l.scrollIntoView({behavior:"smooth"});let s={};if(s=JSON.parse(window.localStorage.getItem("lp_filter_courses"))||{},o.currentTarget.getAttribute("href")){const t=[...e].filter((e=>e.classList.contains("current"))),n=o.currentTarget.textContent||r.classList.contains("next")&&parseInt(t[0].textContent)+1||r.classList.contains("prev")&&parseInt(t[0].textContent)-1;s.paged=n,lpArchiveRequestCourse({...s})}}))))};function u(){t=document.querySelector(".lp-archive-course-skeleton"),c=document.querySelector(".no-first-load-ajax"),t&&(c?(i(),(()=>{const e=document.querySelectorAll("form.search-courses"),r=JSON.parse(window.localStorage.getItem("lp_filter_courses"))||{};e.forEach((e=>{const o=e.querySelector('input[name="c_search"]'),s=e.querySelector('[type="submit"]');let n;o.addEventListener("keyup",(e=>{t&&(t.style.display="block"),e.preventDefault();const o=e.target.value.trim();(!o||o&&o.length>2)&&(void 0!==n&&clearTimeout(n),n=setTimeout((function(){s.classList.add("loading"),r.c_search=o,r.paged=1,lpArchiveRequestCourse({...r})}),800))})),e.addEventListener("submit",(t=>{t.preventDefault();const r=e.querySelector('input[name="c_search"]');r&&r.dispatchEvent(new Event("keyup"))}))}))})()):lpArchiveRequestCourse(o)),(()=>{const e=document.querySelectorAll('.lp-archive-courses input[name="lp-switch-layout-btn"]');e.length>0&&e.forEach((e=>e.addEventListener("change",(e=>{e.preventDefault();const t=e.target.value;if(t){const e=document.querySelector(".lp-archive-courses .learn-press-courses[data-layout]");e&&(e.dataset.layout=t),LP.Cookies.set("courses-layout",t)}}))))})(),(()=>{const e=LP.Cookies.get("courses-layout"),t=document.querySelectorAll('.lp-courses-bar .switch-layout [name="lp-switch-layout-btn"]');t.length>0&&[...t].map((t=>t.value===e&&(t.checked=!0)))})()}const p=setInterval((function(){void 0!==lpGlobalSettings.lpArchiveSkeleton&&(t=document.querySelector(".lp-archive-course-skeleton"),l=document.querySelector(".lp-archive-courses"),l&&t&&(u(),clearInterval(p)))}),1)}(); |
|
1
|
+(()=>{"use strict";const e={};let t;"undefined"!=typeof lpDataAdmin&&(t=lpDataAdmin.lp_rest_url,e.admin={apiSearchCourses:t+"lp/v1/admin/tools/search-course",apiSearchUsers:t+"lp/v1/admin/tools/search-user",apiAssignUserCourse:t+"lp/v1/admin/tools/assign-user-course",apiUnAssignUserCourse:t+"lp/v1/admin/tools/unassign-user-course"}),"undefined"!=typeof lpData&&(t=lpData.lp_rest_url,e.frontend={apiWidgets:t+"lp/v1/widgets/api",apiCourses:t+"lp/v1/courses/archive-course",apiAJAX:t+"lp/v1/load_content_via_ajax/",apiProfileCoverImage:t+"lp/v1/profile/cover-image"}),t&&(e.apiCourses=t+"lp/v1/courses/",e.apiEditCoursesArchiveBlock=t+"lp/v1/courses/edit-archive-block",e.apiCoursesSuggest=t+"lp/v1/courses/courses-suggest");const s=e,r=(e,t)=>{const s=new URL(e);return Object.keys(t).forEach(e=>{s.searchParams.set(e,t[e])}),s};window.lpToggleEnableInit=0,window.lpFullScreenViewInit=0;const o={get:(e,t,s)=>{let r;if(s)r=wpCookies.get(e);else{let t=wpCookies.get("LP");t&&(t=JSON.parse(t),r=e?t[e]:t)}return r||r===t||(r=t),r},set(e,t,s,r,o,n){if(arguments.length>2)wpCookies.set(e,t,s,r,o,n);else if(2==arguments.length){let s=wpCookies.get("LP");s=s?JSON.parse(s):{},s[e]=t,wpCookies.set("LP",JSON.stringify(s),"","/")}else wpCookies.set("LP",JSON.stringify(e),"","/")},remove(e){const t=o.get(),s=new RegExp(e,"g"),r={},n=e.match(/\*/);for(const o in t)n?o.match(s)||(r[o]=t[o]):e!=o&&(r[o]=t[o]);o.set(r)}},n=o;"undefined"!=typeof lpData&&"undefined"!=typeof lpSettingCourses||console.log("lpData || lpSettingCourses is undefined"),window.lpArchiveRequestCourse=e=>{window.lpCourseList.updateEventTypeBeforeFetch("filter"),window.lpCourseList.triggerFetchAPI(e)},document.addEventListener("change",function(e){const t=e.target;window.lpCourseList.checkIsNewListCourses()||(window.lpCourseList.onChangeSortBy(e,t),window.lpCourseList.onChangeTypeLayout(e,t))}),document.addEventListener("click",function(e){const t=e.target;window.lpCourseList.checkIsNewListCourses()||(window.lpCourseList.clickLoadMore(e,t),window.lpCourseList.clickNumberPage(e,t))}),document.addEventListener("scroll",function(e){const t=e.target;window.lpCourseList.checkIsNewListCourses()||window.lpCourseList.scrollInfinite(e,t)}),document.addEventListener("keyup",function(e){const t=e.target;window.lpCourseList.checkIsNewListCourses()||window.lpCourseList.searchCourse(e,t)}),document.addEventListener("submit",function(e){const t=e.target;window.lpCourseList.checkIsNewListCourses()||window.lpCourseList.searchCourse(e,t)}),window.lpCourseList=(()=>{const e="lp-archive-courses",t="learn-press-courses",o="lp-archive-course-skeleton",i="courses-page-result",a=parseInt(lpSettingCourses.lpArchiveLoadAjax||0),c=1===parseInt(lpSettingCourses.lpArchiveNoLoadAjaxFirst),l=lpData.urlParams||[],u=(()=>{let e=window.location.href;return e.includes("?")&&(e=e.split("?")[0]),e})();let d={};const p=lpSettingCourses.lpArchivePaginationType||"number";let f,g,w=!1;const L=(e,t={})=>{const o=r(s.frontend.apiCourses,e);let n={};0!==parseInt(lpData.user_id)&&(n={headers:{"X-WP-Nonce":lpData.nonce}}),((e,t={},s={})=>{"function"==typeof s.before&&s.before(),fetch(e,{method:"GET",...t}).then(e=>e.json()).then(e=>{"function"==typeof s.success&&s.success(e)}).catch(e=>{"function"==typeof s.error&&s.error(e)}).finally(()=>{"function"==typeof s.completed&&s.completed()})})(o,n,t)};return{init:()=>{const e={},t=window.location.search,s=new URLSearchParams(t);for(const[t,r]of s.entries())e[t]=r;d={...l,...e},d.paged=parseInt(d.paged||1),isNaN(d.paged)&&(d.paged=1),c&&"number"!==p&&(d.paged=1),window.localStorage.setItem("lp_filter_courses",JSON.stringify(d))},updateEventTypeBeforeFetch:e=>{f=e},onChangeSortBy:(e,t)=>{if(!t.classList.contains("courses-order-by"))return;e.preventDefault();const s=JSON.parse(window.localStorage.getItem("lp_filter_courses"))||{};s.order_by=t.value||"","undefined"!=typeof lpSettingCourses&&lpData.is_course_archive&&lpSettingCourses.lpArchiveLoadAjax?window.lpCourseList.triggerFetchAPI(s):window.location.href=r(u,s)},onChangeTypeLayout:(s,r)=>{if("lp-switch-layout-btn"!==r.getAttribute("name"))return;const o=r.closest(`.${e}`);if(!o)return;const i=o.querySelector(`.${t}`);if(!i)return;s.preventDefault();const a=r.value;a&&(i.dataset.layout=a,n.set("courses-layout",a))},clickNumberPage:(t,s)=>{if(!a||parseInt(lpSettingCourses.noLoadCoursesJs))return;if(s.classList.contains("page-numbers")){if(!s.closest(`.${e}`))return;t.preventDefault();const r=d.paged;return s.classList.contains("prev")?d.paged=r-1:s.classList.contains("next")?d.paged=r+1:d.paged=parseInt(s.textContent),f="number",void window.lpCourseList.triggerFetchAPI(d)}const r=s.closest(".page-numbers");r&&(t.preventDefault(),r.click())},clickLoadMore:(s,r)=>{if(!r.classList.contains("courses-btn-load-more"))return;const o=r.closest(`.${e}`);o&&o.querySelector(`.${t}`)&&(s.preventDefault(),++d.paged,f="load-more",window.lpCourseList.triggerFetchAPI(d))},scrollInfinite:(t,s)=>{const r=document.querySelector(`.${e}`);if(!r)return;const o=r.querySelector(".courses-load-infinite");o&&new IntersectionObserver(function(e){for(const t of e)if(t.isIntersecting){if(w)return;++d.paged,f="infinite",window.lpCourseList.triggerFetchAPI(d)}}).observe(o)},triggerFetchAPI:s=>{const r=document.querySelector(`.${e}`);if(!r)return;const o=r.querySelector(`.${t}`);if(!o)return;let n;switch(d=s,f){case"load-more":n=window.lpCourseList.callBackPaginationTypeLoadMore(r,o);break;case"infinite":n=window.lpCourseList.callBackPaginationTypeInfinite(r,o);break;case"custom":n=s.customCallBack||!1;break;default:n=window.lpCourseList.callBackFilter(s,r,o)}n&&L(s,n)},callBackFilter:(t,s,n)=>{if(!n)return;const a=n.querySelector(`.${o}`);return{before:()=>{window.history.pushState("","",r(u,t)),window.localStorage.setItem("lp_filter_courses",JSON.stringify(t)),a&&(a.style.display="block")},success:e=>{n.querySelectorAll(`:not(.${o})`).forEach(e=>{e.closest(`.${o}`)||e.remove()}),n.insertAdjacentHTML("afterbegin",e.data.content||"");const t=document.querySelector(".learn-press-pagination");t&&t.remove();const s=e.data.pagination||"";n.insertAdjacentHTML("afterend",s);const r=document.querySelector(`.${i}`);r&&(r.innerHTML=e.data.from_to||"")},error:e=>{n.innerHTML+=`<div class="lp-ajax-message error" style="display:block">${e.message||"Error"}</div>`},completed:()=>{a&&(a.style.display="none"),n.closest(`.${e}`).scrollIntoView({behavior:"smooth"})}}},callBackPaginationTypeLoadMore:(e,t)=>{if(!t||!e)return!1;const s=e.querySelector(".courses-btn-load-more");let r;return s&&(r=s.querySelector(".lp-loading-circle")),{before:()=>{s&&(r.classList.remove("hide"),s.setAttribute("disabled","disabled"))},success:e=>{t.insertAdjacentHTML("beforeend",e.data.content||""),t.insertAdjacentHTML("afterend",e.data.pagination||"");const s=document.querySelector(`.${i}`);s&&(s.innerHTML=e.data.from_to||"")},error:e=>{t.innerHTML+=`<div class="lp-ajax-message error" style="display:block">${e.message||"Error"}</div>`},completed:()=>{s&&(r.classList.add("hide"),s.remove())}}},callBackPaginationTypeInfinite:(e,t)=>{if(!t||!t)return;const s=e.querySelector(".courses-load-infinite");if(!s)return;const r=s.querySelector(".lp-loading-circle");return w=!0,s.classList.remove("courses-load-infinite"),{before:()=>{r.classList.remove("hide")},success:e=>{t.insertAdjacentHTML("beforeend",e.data.content||""),e.data.pagination&&t.insertAdjacentHTML("afterend",e.data.pagination||"");const s=document.querySelector(`.${i}`);s&&(s.innerHTML=e.data.from_to||"")},error:e=>{t.innerHTML+=`<div class="lp-ajax-message error" style="display:block">${e.message||"Error"}</div>`},completed:()=>{s.remove(),w=!1}}},searchCourse:(s,r)=>{if("c_search"===r.name){s.preventDefault();const e=r.closest("form.search-courses");if(!e)return;return void e.querySelector('button[type="submit"]').click()}if(!r.classList.contains("search-courses"))return;const o=r;s.preventDefault();const n=o.closest(`.${e}`);if(!n)return;if(!n.querySelector(`.${t}`))return;const i=o.querySelector("input[name=c_search]").value;(!i||i&&i.length>2)&&(void 0!==g&&clearTimeout(g),g=setTimeout(function(){f="filter",d.c_search=i,d.paged=1,window.lpCourseList.triggerFetchAPI(d)},800))},ajaxEnableLoadPage:()=>{let s=0;if(!c){let r;const n={success:n=>{r=setInterval(function(){const a=document.querySelector(`.${o}`),c=document.querySelector(`.${e}`);let l;if(c&&(l=c.querySelector(`.${t}`)),++s,s>5e3&&clearInterval(r),l&&a){clearInterval(r),l.insertAdjacentHTML("afterbegin",n.data.content||""),a.style.display="none";const e=n.data.pagination||"";l.insertAdjacentHTML("afterend",e);const t=document.querySelector(`.${i}`);t&&(t.innerHTML=n.data.from_to||"")}},1)}};"number"!==p&&(d.paged=1),L(d,n)}},getFilterParams:()=>d,checkIsNewListCourses:()=>!!document.querySelector(".lp-list-courses-default")}})(),document.addEventListener("DOMContentLoaded",function(){window.lpCourseList.checkIsNewListCourses()||(window.lpCourseList.init(),window.lpCourseList.ajaxEnableLoadPage())})})(); |