Skip to content

Commit

Permalink
Fix check jQuery before use in rundiz-template-admin.js.
Browse files Browse the repository at this point in the history
  • Loading branch information
ve3 committed Apr 23, 2023
1 parent e36dfcc commit b2aa983
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 4 deletions.
53 changes: 52 additions & 1 deletion assets/js-src/rdta/rundiz-template-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
class RundizTemplateAdmin {


/**
* Check if jQuery is loaded or not.
*
* @returns {Boolean} Return `true` if it is loaded, `false` for otherwise.
*/
#isjQueryLoaded() {
if (typeof(window.jQuery) === 'function' && window.jQuery) {
return true;
}
return false;
}// isjQueryLoaded


/**
* Listen to button dropdown or button group with dropdown.
*
Expand Down Expand Up @@ -235,6 +248,11 @@ class RundizTemplateAdmin {
* @returns {Boolean}
*/
dataTableToggleRow() {
if (!this.#isjQueryLoaded()) {
// if jQuery is not loaded.
console.warn('jQuery is not loaded.');
return ;
}
let $ = jQuery.noConflict();

document.addEventListener('click', function(event) {
Expand Down Expand Up @@ -262,7 +280,13 @@ class RundizTemplateAdmin {
* @return {undefined}
*/
hotfixLongSidebarSubmenus() {
if (!this.#isjQueryLoaded()) {
// if jQuery is not loaded.
console.warn('jQuery is not loaded.');
return ;
}
let $ = jQuery.noConflict();

let $navbar = $('.rd-navbar');
if (!$navbar || $('.rd-sidebar-item-list').length <= 0) {
// if not found sidebar.
Expand Down Expand Up @@ -348,6 +372,11 @@ class RundizTemplateAdmin {
* @returns {Boolean}
*/
sidebarExpandToggler() {
if (!this.#isjQueryLoaded()) {
// if jQuery is not loaded.
console.warn('jQuery is not loaded.');
return ;
}
let $ = jQuery.noConflict();

let togglerButton = document.querySelector('.rd-sidebar-expand-collapse-controls a');
Expand Down Expand Up @@ -385,7 +414,13 @@ class RundizTemplateAdmin {
* @returns {undefined}
*/
sidebarStickyMenu() {
if (!this.#isjQueryLoaded()) {
// if jQuery is not loaded.
console.warn('jQuery is not loaded.');
return ;
}
let $ = jQuery.noConflict();

if ($('.rd-sidebar').length <= 0) {
// if not found sidebar.
return ;
Expand Down Expand Up @@ -440,8 +475,18 @@ class RundizTemplateAdmin {
* @returns {undefined}
*/
smartMenusNavbar() {
if (!this.#isjQueryLoaded()) {
// if jQuery is not loaded.
console.warn('jQuery is not loaded.');
return ;
}
let $ = jQuery.noConflict();

if ($('.sm-rdta.navbar').length <= 0) {
// if not found navbar.
return ;
}

// tweak to show only one menu at a time. ( https://www.smartmenus.org/forums/topic/accordion-failed/#post-2660 )
// this problem occur on small screen navbar menu. so, this can fix it.
$('.sm-rdta.navbar').bind('click.smapi', function (e, item) {
Expand Down Expand Up @@ -503,9 +548,15 @@ class RundizTemplateAdmin {
* @returns {undefined}
*/
smartMenusSidebar() {
if (!this.#isjQueryLoaded()) {
// if jQuery is not loaded.
console.warn('jQuery is not loaded.');
return ;
}
let $ = jQuery.noConflict();

if ($('.sm-vertical').length <= 0) {
// if not found smart menu selector.
// if not found sidebar.
return ;
}

Expand Down
53 changes: 52 additions & 1 deletion assets/js/rdta/rundiz-template-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ License: MIT
class RundizTemplateAdmin {


/**
* Check if jQuery is loaded or not.
*
* @returns {Boolean} Return `true` if it is loaded, `false` for otherwise.
*/
#isjQueryLoaded() {
if (typeof(window.jQuery) === 'function' && window.jQuery) {
return true;
}
return false;
}// isjQueryLoaded


/**
* Listen to button dropdown or button group with dropdown.
*
Expand Down Expand Up @@ -239,6 +252,11 @@ class RundizTemplateAdmin {
* @returns {Boolean}
*/
dataTableToggleRow() {
if (!this.#isjQueryLoaded()) {
// if jQuery is not loaded.
console.warn('jQuery is not loaded.');
return ;
}
let $ = jQuery.noConflict();

document.addEventListener('click', function(event) {
Expand Down Expand Up @@ -266,7 +284,13 @@ class RundizTemplateAdmin {
* @return {undefined}
*/
hotfixLongSidebarSubmenus() {
if (!this.#isjQueryLoaded()) {
// if jQuery is not loaded.
console.warn('jQuery is not loaded.');
return ;
}
let $ = jQuery.noConflict();

let $navbar = $('.rd-navbar');
if (!$navbar || $('.rd-sidebar-item-list').length <= 0) {
// if not found sidebar.
Expand Down Expand Up @@ -352,6 +376,11 @@ class RundizTemplateAdmin {
* @returns {Boolean}
*/
sidebarExpandToggler() {
if (!this.#isjQueryLoaded()) {
// if jQuery is not loaded.
console.warn('jQuery is not loaded.');
return ;
}
let $ = jQuery.noConflict();

let togglerButton = document.querySelector('.rd-sidebar-expand-collapse-controls a');
Expand Down Expand Up @@ -389,7 +418,13 @@ class RundizTemplateAdmin {
* @returns {undefined}
*/
sidebarStickyMenu() {
if (!this.#isjQueryLoaded()) {
// if jQuery is not loaded.
console.warn('jQuery is not loaded.');
return ;
}
let $ = jQuery.noConflict();

if ($('.rd-sidebar').length <= 0) {
// if not found sidebar.
return ;
Expand Down Expand Up @@ -444,8 +479,18 @@ class RundizTemplateAdmin {
* @returns {undefined}
*/
smartMenusNavbar() {
if (!this.#isjQueryLoaded()) {
// if jQuery is not loaded.
console.warn('jQuery is not loaded.');
return ;
}
let $ = jQuery.noConflict();

if ($('.sm-rdta.navbar').length <= 0) {
// if not found navbar.
return ;
}

// tweak to show only one menu at a time. ( https://www.smartmenus.org/forums/topic/accordion-failed/#post-2660 )
// this problem occur on small screen navbar menu. so, this can fix it.
$('.sm-rdta.navbar').bind('click.smapi', function (e, item) {
Expand Down Expand Up @@ -507,9 +552,15 @@ class RundizTemplateAdmin {
* @returns {undefined}
*/
smartMenusSidebar() {
if (!this.#isjQueryLoaded()) {
// if jQuery is not loaded.
console.warn('jQuery is not loaded.');
return ;
}
let $ = jQuery.noConflict();

if ($('.sm-vertical').length <= 0) {
// if not found smart menu selector.
// if not found sidebar.
return ;
}

Expand Down
Loading

0 comments on commit b2aa983

Please sign in to comment.