From c626e0f8eddd4c9db8284a5260b5bc7e1571bca0 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Mon, 7 May 2018 02:11:16 -0600 Subject: [PATCH] Add image picker for complex components (close #17) --- lang/en_us.php | 1 + pages/editor.php | 53 ++++++++++++++--------- public/themes/identity/inc/header.inc.php | 8 +++- static/css/filepicker.css | 5 +++ static/js/editorparent.js | 30 ++++++++++++- 5 files changed, 74 insertions(+), 23 deletions(-) diff --git a/lang/en_us.php b/lang/en_us.php index 26fd57e..d7481ef 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -54,6 +54,7 @@ define("STRINGS", [ "save needed" => "Press Save to see recent changes.", "saved" => "Saved", "icon" => "Icon", + "image" => "Image", "link" => "Link", "text" => "Text", "select page or enter url" => "Select a page or enter URL", diff --git a/pages/editor.php b/pages/editor.php index 16149ea..94faed4 100644 --- a/pages/editor.php +++ b/pages/editor.php @@ -191,6 +191,17 @@ if (!is_empty($VARS['siteid'])) {
+
+ +
+
+ +
+
+
+ +
+
- -
- + +
+ -
- + ?> + +
+ +
-
- +
diff --git a/public/themes/identity/inc/header.inc.php b/public/themes/identity/inc/header.inc.php index 77cc405..2372695 100644 --- a/public/themes/identity/inc/header.inc.php +++ b/public/themes/identity/inc/header.inc.php @@ -23,7 +23,13 @@
- + + + +

diff --git a/static/css/filepicker.css b/static/css/filepicker.css index a6a0d49..8b6c91c 100644 --- a/static/css/filepicker.css +++ b/static/css/filepicker.css @@ -7,4 +7,9 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. .filepicker-item { cursor: pointer; color: #2196F3; +} + +#selectedimage { + max-height: 200px; + max-width: 200px; } \ No newline at end of file diff --git a/static/js/editorparent.js b/static/js/editorparent.js index d542f3e..cff93d3 100644 --- a/static/js/editorparent.js +++ b/static/js/editorparent.js @@ -37,6 +37,7 @@ function editComplex(json) { var content = data.content; } $("#iconEdit").removeClass("d-none"); + $("#imageEdit").removeClass("d-none"); $("#linkEdit").removeClass("d-none"); $("#textEdit").removeClass("d-none"); $("#linkPage").val(""); @@ -60,6 +61,32 @@ function editComplex(json) { setSelectedIcon(); } } + if (typeof content.image === 'undefined') { + $("#imageEdit").addClass("d-none"); + } else { + $("#imageEdit").data("image", content.image); + if (content.image != "") { + $("#imageEdit #selectedimage").attr("src", "public/file.php?file=" + content.image); + } + function loadComplexImageBrowser(path) { + $.get("lib/filepicker.php", { + path: path, + type: "image" + }, function (data) { + $("#imagepicker").html(data); + $("#imagepicker .filepicker-item").click(function () { + if ($(this).data("type") == "dir") { + loadComplexImageBrowser($(this).data("path")); + } else { + var path = $(this).data("path"); + $("#imageEdit").data("image", path); + $("#imageEdit #selectedimage").attr("src", "public/file.php?file=" + path); + } + }) + }); + } + loadComplexImageBrowser(); + } if (typeof content.link === 'undefined') { $("#linkEdit").addClass("d-none"); } else { @@ -93,7 +120,7 @@ function loadFilePickerFolder(path, type) { type: ty }, function (data) { $("#fileBrowseModalBody").html(data); - $(".filepicker-item").click(function () { + $("#fileBrowseModalBody .filepicker-item").click(function () { if ($(this).data("type") == "dir") { loadFilePickerFolder($(this).data("path"), type); } else { @@ -121,6 +148,7 @@ $("#editModalSave").on("click", function () { data["component"] = $("#editModal").data("component"); var content = {}; content["icon"] = $('input[name="selectedicon"]:checked').val(); + content["image"] = $("#imageEdit").data("image"); if ($("#linkBox").val() != "") { content["link"] = $("#linkBox").val(); } else {