Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 336 Vote(s) - 3.62 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a way to override any of /js/*.js files?

#1
I know there are the ways to override module's js/css/tpl and other files, but I cant find a way to override, for example, the `/js/validate.js` file.
I've tried to place my own file to `/themes/my-theme/js` folder, but I cant see a result (validate.js is still loaded from `/js/` folder).

Is there a way to do this?
Reply

#2
<!-- language-all: lang-php -->

There is no built-in functionality to do this.

But you can override the method `addMedia` of `FrontController`.

Create this file `/override/classes/controller/FrontController.php`:

<?php
class FrontController extends FrontControllerCore
{
/**
* Adds a media file(s) (CSS, JS) to page header
*
* @param string|array $media_uri Path to file, or an array of paths like: array(array(uri => media_type), ...)
* @param string|null $css_media_type CSS media type
* @param int|null $offset
* @param bool $remove If True, removes media files
* @param bool $check_path If true, checks if files exists
* @return true|void
*/
public function addMedia($media_uri, $css_media_type = null, $offset = null, $remove = false, $check_path = true)
{
if (!is_array($media_uri)) {
if ($css_media_type) {
$media_uri = array($media_uri => $css_media_type);
} else {
$media_uri = array($media_uri);
}
}

$list_uri = array();
foreach ($media_uri as $file => $media) {
if (!Validate::isAbsoluteUrl($media)) {
$different = 0;
$different_css = 0;
$type = 'css';
if (!$css_media_type) {
$type = 'js';
$file = $media;
}
if (strpos($file, __PS_BASE_URI__.'modules/') === 0) {
$override_path = str_replace(__PS_BASE_URI__.'modules/', _PS_ROOT_DIR_.'/themes/'._THEME_NAME_.'/'.$type.'/modules/', $file, $different);
if (strrpos($override_path, $type.'/'.basename($file)) !== false) {
$override_path_css = str_replace($type.'/'.basename($file), basename($file), $override_path, $different_css);
}

if ($different && @filemtime($override_path)) {
$file = str_replace(__PS_BASE_URI__.'modules/', __PS_BASE_URI__.'themes/'._THEME_NAME_.'/'.$type.'/modules/', $file, $different);
} elseif ($different_css && @filemtime($override_path_css)) {
$file = $override_path_css;
}
if ($css_media_type) {
$list_uri[$file] = $media;
} else {
$list_uri[] = $file;
}
// Here we add our test to override default js files
} elseif (strpos($file, _PS_JS_DIR_) === 0) {
$override_path = str_replace(_PS_JS_DIR_, _PS_ROOT_DIR_.'/themes/'._THEME_NAME_.'/js/default/', $file, $different);
if (strrpos($override_path, $type.'/'.basename($file)) !== false) {
$override_path_css = str_replace($type.'/'.basename($file), basename($file), $override_path, $different_css);
}

if ($different && @filemtime($override_path)) {
$file = str_replace(_PS_JS_DIR_, __PS_BASE_URI__.'themes/'._THEME_NAME_.'/js/default/', $file, $different);
} elseif ($different_css && @filemtime($override_path_css)) {
$file = $override_path_css;
}
if ($css_media_type) {
$list_uri[$file] = $media;
} else {
$list_uri[] = $file;
}
} else {
$list_uri[$file] = $media;
}
} else {
$list_uri[$file] = $media;
}
}

if ($remove) {
if ($css_media_type) {
return parent::removeCSS($list_uri, $css_media_type);
}
return parent::removeJS($list_uri);
}

if ($css_media_type) {
return parent::addCSS($list_uri, $css_media_type, $offset, $check_path);
}

return parent::addJS($list_uri, $check_path);
}
}

With this override, you can now create a file `/themes/my_theme/js/default/validate.js` to override the default `/js/validate.js` file.

PS: as with any override, you will have to delete the file `/cache/class_index.php`.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through