/** * return jquery plugin path. * * @param mixed $name * @return string|boolean */ public static function getJqueryPluginPath($name, $folder = null) { $plugin_path = array('js' => array(), 'css' => array()); if ($folder === null) { $folder = _PS_JS_DIR_ . 'jquery/plugins/'; } //set default folder $file = 'jquery.' . $name . '.js'; $url_data = parse_url($folder); $file_uri = _PS_ROOT_DIR_ . Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']); $file_uri_host_mode = _PS_CORE_DIR_ . Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']); if (@file_exists($file_uri . $file) || defined('_PS_HOST_MODE_') && @file_exists($file_uri_host_mode . $file)) { $plugin_path['js'] = Media::getJSPath($folder . $file); } elseif (@file_exists($file_uri . $name . '/' . $file) || defined('_PS_HOST_MODE_') && @file_exists($file_uri_host_mode . $name . '/' . $file)) { $plugin_path['js'] = Media::getJSPath($folder . $name . '/' . $file); } else { return false; } $plugin_path['css'] = Media::getJqueryPluginCSSPath($name, $folder); return $plugin_path; }
public function removeJS($js_uri) { if (is_array($js_uri)) { foreach ($js_uri as $js_file) { $js_path = Media::getJSPath($js_file); if ($js_path && in_array($js_path, $this->js_files)) { unset($this->js_files[array_search($js_path, $this->js_files)]); } } } else { $js_path = Media::getJSPath($js_uri); if ($js_path) { unset($this->js_files[array_search($js_path, $this->js_files)]); } } }
/** * Add a new javascript file in page header. * * @param mixed $js_uri * @return void */ public function addJS($js_uri) { if (is_array($js_uri)) { foreach ($js_uri as $js_file) { $js_path = Media::getJSPath($js_file); if ($js_path && !in_array($js_path, $this->js_files)) { $this->js_files[] = $js_path; } } } else { $js_path = Media::getJSPath($js_uri); if ($js_path) { $this->js_files[] = $js_path; } } }