Skip to content
Snippets Groups Projects
Commit 9d8180d8 authored by Maximilian Giller's avatar Maximilian Giller
Browse files

Summarised localize calls into one object

parent e455f1eb
No related branches found
No related tags found
No related merge requests found
...@@ -9,8 +9,8 @@ export const COLOR_PALETTE = [ ...@@ -9,8 +9,8 @@ export const COLOR_PALETTE = [
]; ];
// Just renaming a variable which is given by the PHP script. This avoids errors in all other files. // Just renaming a variable which is given by the PHP script. This avoids errors in all other files.
export const PLUGIN_PATH = plugin.path; export const PLUGIN_PATH = ks_global.plugin_path;
export var SPACE = space.id; export var SPACE = ks_global.space_id;
export function setSpace(space) { export function setSpace(space) {
SPACE = space; SPACE = space;
......
...@@ -17,7 +17,7 @@ export function loadGraphJson(spaceId) { ...@@ -17,7 +17,7 @@ export function loadGraphJson(spaceId) {
return jQuery return jQuery
.ajax({ .ajax({
type: "POST", type: "POST",
url: ajax_object.ajax_url, url: ks_global.ajax_url,
data: payload, data: payload,
}) })
.then((data) => JSON.parse(data)); .then((data) => JSON.parse(data));
...@@ -40,7 +40,7 @@ export function saveGraphJson(spaceId, json) { ...@@ -40,7 +40,7 @@ export function saveGraphJson(spaceId, json) {
return jQuery.ajax({ return jQuery.ajax({
type: "POST", type: "POST",
url: ajax_object.ajax_url, url: ks_global.ajax_url,
data: payload, data: payload,
}); });
} }
...@@ -57,7 +57,7 @@ export function listAllSpaces() { ...@@ -57,7 +57,7 @@ export function listAllSpaces() {
return jQuery.ajax({ return jQuery.ajax({
type: "POST", type: "POST",
url: ajax_object.ajax_url, url: ks_global.ajax_url,
data: payload, data: payload,
}).then((data) => JSON.parse(data)["spaces"]); }).then((data) => JSON.parse(data)["spaces"]);
} }
...@@ -11,38 +11,42 @@ $GLOBALS['build'] = 'debug'; ...@@ -11,38 +11,42 @@ $GLOBALS['build'] = 'debug';
function ks_add_graph($atts = []): string function ks_add_graph($atts = []): string
{ {
$space_id = kg_get_space_id_from_atts($atts);
$div = '<div id="3d-graph"></div>'; // The id "3d-graph" indicates, that the javascript associated with this should automatically be executed $div = '<div id="3d-graph"></div>'; // The id "3d-graph" indicates, that the javascript associated with this should automatically be executed
$plugin_dir = plugin_dir_url(__FILE__);
$script_path = 'build' . DIRECTORY_SEPARATOR . $GLOBALS['build'] . DIRECTORY_SEPARATOR . 'graph.js'; $script_path = 'build' . DIRECTORY_SEPARATOR . $GLOBALS['build'] . DIRECTORY_SEPARATOR . 'graph.js';
// $script = "<script src='$script_path'></script>"; // $script = "<script src='$script_path'></script>";
//wp_enqueue_script('kg-script', $script_path); //wp_enqueue_script('kg-script', $script_path);
wp_enqueue_script("ks-display-js", plugins_url($script_path, __FILE__), array('jquery'), false); wp_enqueue_script("ks-display-js", plugins_url($script_path, __FILE__), array('jquery'), false);
wp_localize_script( ks_localize();
'ks-display-js',
'ajax_object',
array('ajax_url' => admin_url('admin-ajax.php'))
);
wp_localize_script("ks-display-js", "space", array('id' => $space_id));
wp_localize_script("ks-display-js", "plugin", array('path' => $plugin_dir));
return $div . $variables; return $div;
// return $div . $variables . $script; // return $div . $variables . $script;
} }
function ks_echo_graph ($atts = []): void { function ks_echo_graph($atts = []): void
{
echo ks_add_graph($atts); echo ks_add_graph($atts);
} }
function ks_add_editor($atts = []) function ks_localize()
{ {
ks_add_editor_dependencies();
$space_id = kg_get_space_id_from_atts($atts); $space_id = kg_get_space_id_from_atts($atts);
$plugin_dir = plugin_dir_url(__FILE__); $plugin_dir = plugin_dir_url(__FILE__);
wp_localize_script("ks-editor-js", "space", array('id' => $space_id)); wp_localize_script(
wp_localize_script("ks-editor-js", "plugin", array('path' => $plugin_dir)); 'ks-editor-js',
'ks_global',
array(
'ajax_url' => admin_url('admin-ajax.php'),
'space_id' => $space_id,
'plugin_path' => $plugin_dir
)
);
}
function ks_add_editor($atts = [])
{
ks_add_editor_dependencies();
ks_localize();
require_once(__DIR__ . '/editor/editor.php'); require_once(__DIR__ . '/editor/editor.php');
} }
...@@ -55,11 +59,6 @@ function ks_add_editor_dependencies() ...@@ -55,11 +59,6 @@ function ks_add_editor_dependencies()
wp_enqueue_script("ks-editor-js", plugins_url($script_path, __FILE__), array('jquery'), false); wp_enqueue_script("ks-editor-js", plugins_url($script_path, __FILE__), array('jquery'), false);
//wp_register_script("ks-editor-js", plugins_url($script_path, __FILE__), array('jquery'), false); //wp_register_script("ks-editor-js", plugins_url($script_path, __FILE__), array('jquery'), false);
wp_localize_script(
'ks-editor-js',
'ajax_object',
array('ajax_url' => admin_url('admin-ajax.php'))
);
//wp_enqueue_script("ks-editor-js"); //wp_enqueue_script("ks-editor-js");
$style_file_version = date("ymd-Gis", filemtime(plugin_dir_path(__FILE__) . "editor/css/editor.css")); $style_file_version = date("ymd-Gis", filemtime(plugin_dir_path(__FILE__) . "editor/css/editor.css"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment