Bux fix for onload and teardown of pages on refresh and ajax requests.
Signed-Off-By: Piyush Vijay <piyushvijay.1997@gmail.com>
This commit is contained in:
parent
5402f43840
commit
177e101379
@ -744,6 +744,13 @@ export let AJAX = {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a generic event handler to clicks
|
||||
* on pages and submissions of forms
|
||||
*/
|
||||
$(document).on('click', 'a', AJAX.requestHandler);
|
||||
$(document).on('submit', 'form', AJAX.requestHandler);
|
||||
|
||||
/**
|
||||
* @todo this is to be removed when complete code is modularised
|
||||
* Exporsing module to window for use with non modular code
|
||||
|
||||
@ -3,17 +3,6 @@ import './variables/import_variables';
|
||||
import { jQuery as $ } from './utils/JqueryExtended';
|
||||
import files from './consts/files';
|
||||
|
||||
/**
|
||||
* This block of code is for importing javascript files needed
|
||||
* for the first time loading of the page.
|
||||
*/
|
||||
let firstPage = window.location.pathname.replace('/', '').replace('.php', '');
|
||||
if (typeof files[firstPage] !== 'undefined') {
|
||||
for (let i in files[firstPage]) {
|
||||
AJAX.scriptHandler.add(files[firstPage][i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Page load event handler
|
||||
*/
|
||||
@ -79,8 +68,19 @@ $(function () {
|
||||
});
|
||||
|
||||
/**
|
||||
* Attach a generic event handler to clicks
|
||||
* on pages and submissions of forms
|
||||
* This block of code is for importing javascript files needed
|
||||
* for the first time loading of the page.
|
||||
*/
|
||||
$(document).on('click', 'a', AJAX.requestHandler);
|
||||
$(document).on('submit', 'form', AJAX.requestHandler);
|
||||
let firstPage = window.location.pathname.replace('/', '').replace('.php', '');
|
||||
let indexStart = window.location.search.indexOf('target') + 7;
|
||||
let indexEnd = window.location.search.indexOf('.php');
|
||||
let indexPage = window.location.search.slice(indexStart, indexEnd);
|
||||
if (typeof files[firstPage] !== 'undefined' && firstPage.toLocaleLowerCase() !== 'index') {
|
||||
for (let i in files[firstPage]) {
|
||||
AJAX.scriptHandler.add(files[firstPage][i], 1);
|
||||
}
|
||||
} else if (typeof files[indexPage] !== 'undefined' && firstPage.toLocaleLowerCase() === 'index') {
|
||||
for (let i in files[indexPage]) {
|
||||
AJAX.scriptHandler.add(files[indexPage][i], 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,18 +195,20 @@ class Scripts
|
||||
|
||||
$code = 'AJAX.scriptHandler';
|
||||
foreach ($this->_files as $file) {
|
||||
$code .= sprintf(
|
||||
'.add("%s",%d)',
|
||||
Sanitize::escapeJsString($file['filename']),
|
||||
$file['has_onload'] ? 1 : 0
|
||||
);
|
||||
if (strpos($file['filename'], ".js") !== false) {
|
||||
$code .= sprintf(
|
||||
'.add("%s",%d)',
|
||||
Sanitize::escapeJsString($file['filename']),
|
||||
$file['has_onload'] ? 1 : 0
|
||||
);
|
||||
}
|
||||
}
|
||||
$code .= ';';
|
||||
$this->addCode($code);
|
||||
|
||||
$code = '$(function() {';
|
||||
foreach ($this->_files as $file) {
|
||||
if ($file['has_onload']) {
|
||||
if ($file['has_onload'] && strpos($file['filename'], ".js") !== false) {
|
||||
$code .= 'AJAX.fireOnload("';
|
||||
$code .= Sanitize::escapeJsString($file['filename']);
|
||||
$code .= '");';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user