From 2475f952dfe0cec2a87e1ee97e74ed354758fe20 Mon Sep 17 00:00:00 2001 From: Matthias Mees Date: Tue, 29 Apr 2014 13:22:55 +0200 Subject: [PATCH] Standardize select image from media db/show preview process. This used to be two seperate processes for the category icon and images selected in plugin/theme config. It has now been simplified to use just one process, which also uses the same markup and JS. This adds to the consistency of the UI/UX, but it also saves some CSS and a lot of JS, most of the latter of the expensive kind that modifies the DOM. --- templates/2k11/admin/category.inc.tpl | 10 ++-- templates/2k11/admin/plugin_config_item.tpl | 11 +++-- .../2k11/admin/serendipity_editor.js.tpl | 46 ++++--------------- templates/2k11/admin/style.css | 14 ++---- 4 files changed, 26 insertions(+), 55 deletions(-) diff --git a/templates/2k11/admin/category.inc.tpl b/templates/2k11/admin/category.inc.tpl index f1f849bc..4b5422b7 100644 --- a/templates/2k11/admin/category.inc.tpl +++ b/templates/2k11/admin/category.inc.tpl @@ -131,13 +131,15 @@
- - + + + +
-
+
{$CONST.PREVIEW}
- +
diff --git a/templates/2k11/admin/plugin_config_item.tpl b/templates/2k11/admin/plugin_config_item.tpl index 0e07c516..fe0a71b1 100644 --- a/templates/2k11/admin/plugin_config_item.tpl +++ b/templates/2k11/admin/plugin_config_item.tpl @@ -56,12 +56,17 @@ {elseif $ctype == 'media'}
- - {* This should maybe be input[type=file] *} - {if $cdesc != ''}{$cdesc}{/if} + +
+
{$CONST.PREVIEW}
+ +
{elseif $ctype == 'sequence'}
diff --git a/templates/2k11/admin/serendipity_editor.js.tpl b/templates/2k11/admin/serendipity_editor.js.tpl index ddda60c3..be9d772b 100644 --- a/templates/2k11/admin/serendipity_editor.js.tpl +++ b/templates/2k11/admin/serendipity_editor.js.tpl @@ -150,14 +150,11 @@ } /* end Better-Editor functions */ - // Switches preview of image selected from media db by changing the - // container's background image - serendipity.change_preview = function(id) { - var text_box = document.getElementById('serendipity[template][' + id + ']'); - var image_box = document.getElementById(id + '_preview'); - var filename = text_box.value; - - image_box.style.backgroundImage = 'url(' + filename + ')'; + // Switches preview of image selected from media db + serendipity.change_preview = function(input, output) { + var filename = document.getElementById(input).value; + var $target = $('#' + output + '_preview > img'); + $target.attr('src', filename); } // Opens media db image selection in new window @@ -1080,28 +1077,10 @@ $(function() { $('.show_config_option_now').click(); } - // Config option add media - if($('.media_choose').length > 0) { - var $el = $('.media_choose'); - var $item = $el.find('> input'); - var configItem = $item.attr('data-configitem'); - var mWidth = $item.attr('data-pmwidth'); - var mHeight = $item.attr('data-pmheight'); - if($item.val() != '') { - var bgImg = 'url(' + $item.val() + ')'; - } else { - var bgImg = 'none'; - } - $('
').appendTo($el) - .css({ - backgroundImage: bgImg, - // minWidth: mWidth, - minHeight: mHeight - }); - } - $('.change_preview').change(function() { - serendipity.change_preview($(this).attr('data-configitem')); + console.log('ID: ' + $(this).attr('id')); + console.log('CI: ' + $(this).attr('data-configitem')); + serendipity.change_preview($(this).attr('id'), $(this).attr('data-configitem')); }); $('.choose_media').click(function() { @@ -1134,15 +1113,6 @@ $(function() { {/if} }); - // Category icon preview - $('#insert_image').click(function(e) { - serendipity.choose_media('category_icon'); - }); - - $('#category_icon').change(function() { - $('#imagepreview').attr('src', $('#category_icon').val()); - }); - // Selection for multidelete $('.multidelete').click(function() { var $el = $(this); diff --git a/templates/2k11/admin/style.css b/templates/2k11/admin/style.css index 45840100..2b7f4559 100644 --- a/templates/2k11/admin/style.css +++ b/templates/2k11/admin/style.css @@ -964,6 +964,7 @@ input[type=checkbox], .importer_data dd, .form_buttons > input, +.js .media_choose label, .quick_list ol > li { margin-bottom: .75em; } @@ -976,7 +977,7 @@ input[type=checkbox], .serendipity_commentDirection, .entry_info, .pagination, -.media_choose .preview, +.media_choose figure, .media_file_metadata dt, #serendipity_comments_list details, .configure_plugin .cke { @@ -1244,13 +1245,6 @@ summary { max-width: 75%; } -.media_choose .preview { - background-repeat: no-repeat; - height: auto; - margin: .75em 0; - max-width: 100%; -} - .editor_toolbar button, .comment_data dt, #serendipityScaleForm .form_field label { @@ -2140,8 +2134,8 @@ label .perm_name, .no-js .toggle_comment_full, .no-js #add_upload, .no-js .choose_media, -.no-js #insert_image, -.no-js #category_preview #preview, +.no-js .media_choose figure, +.no-js #category_preview figure, .no-js .media_show_info, .no-js .media_rename, .no-js .template_show_info,