From 1d3a48d2eaf3226d669b25c3c98b7d674ce5dec9 Mon Sep 17 00:00:00 2001 From: Mats Mikkel Rummelhoff Date: Wed, 16 May 2018 10:39:55 +0200 Subject: [PATCH] Fixes issue with missing nav item icon; adds checkbox persistance using localStorage. Bump to 1.0.2 --- CHANGELOG.md | 7 +++++++ composer.json | 2 +- src/CpClearCache.php | 2 +- src/resources/cpclearcache.js | 20 ++++++++++++++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d3f1de..9241ab4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 1.0.2 - 2018-05-16 +### Added +– CP Clear Cache now remembers your checked boxes + +### Fixed +- Fixes the missing nav item icon on Craft 3.0.7 and above + ## 1.0.1 - 2018-03-28 ### Fixed - Fixes issue #1, where CP Clear Cache would conflict w/ other plugins (e.g. SEOmatic) diff --git a/composer.json b/composer.json index 85dc8ad..f33452b 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "mmikkel/cp-clearcache", "description": "Fewer clicks to get clearin'", "type": "craft-plugin", - "version": "1.0.1", + "version": "1.0.2", "keywords": [ "craft", "cms", diff --git a/src/CpClearCache.php b/src/CpClearCache.php index 84fa759..f710f65 100644 --- a/src/CpClearCache.php +++ b/src/CpClearCache.php @@ -120,7 +120,7 @@ function () use ($data) { Event::on(Cp::class, Cp::EVENT_REGISTER_CP_NAV_ITEMS, function (RegisterCpNavItemsEvent $event) { $event->navItems['mmikkel/cpclearcache'] = [ 'label' => \Craft::t('app', 'Clear Caches'), - 'icon' => 'trash', + 'fontIcon' => 'trash', 'url' => 'mmikkel/cpclearcache' ]; }); diff --git a/src/resources/cpclearcache.js b/src/resources/cpclearcache.js index 72f3dfe..d49ede9 100644 --- a/src/resources/cpclearcache.js +++ b/src/resources/cpclearcache.js @@ -8,23 +8,37 @@ hud: null, $trigger: null, + localStorageKey: 'cpclearcache_selected', + + onChange: function (e) { + Craft.setLocalStorage(this.localStorageKey, $.map($('input[type="checkbox"]:checked'), function (input) { + return input.value; + })); + }, onClick: function (e) { e.preventDefault(); - var $form = $(this.data.html); + $form = $(this.data.html); $form.attr('id', 'mmikkel-cpclearcache'); if (!this.hud) { + var _self = this; + this.hud = new Garnish.HUD(this.$trigger, $form, { orientations: ['top', 'bottom', 'right', 'left'], hudClass: 'hud toolhud', onShow: function () { Garnish.requestAnimationFrame(function () { new Craft.ClearCachesUtility('mmikkel-cpclearcache'); - new Garnish.CheckboxSelect($('#mmikkel-cpclearcache .checkbox-select')); + var $checkboxes = $('#mmikkel-cpclearcache .checkbox-select'); + new Garnish.CheckboxSelect($checkboxes); + var checkedBoxes = Craft.getLocalStorage(_self.localStorageKey); + $checkboxes.find('input[type="checkbox"]').each(function () { + $(this).prop('checked', checkedBoxes === undefined || checkedBoxes.indexOf(this.value) > -1).trigger('change'); + }); }); } }); @@ -47,6 +61,8 @@ } this.$trigger.on('click', $.proxy(this.onClick, this)); + + $('body').on('change', '#mmikkel-cpclearcache input[type="checkbox"]', $.proxy(this.onChange, this)); }