Skip to content

Commit

Permalink
Fixes issue with missing nav item icon; adds checkbox persistance usi…
Browse files Browse the repository at this point in the history
…ng localStorage. Bump to 1.0.2
  • Loading branch information
mmikkel committed May 16, 2018
1 parent 8cbf771 commit 1d3a48d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/CpClearCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
];
});
Expand Down
20 changes: 18 additions & 2 deletions src/resources/cpclearcache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
}
});
Expand All @@ -47,6 +61,8 @@
}

this.$trigger.on('click', $.proxy(this.onClick, this));

$('body').on('change', '#mmikkel-cpclearcache input[type="checkbox"]', $.proxy(this.onChange, this));

}

Expand Down

0 comments on commit 1d3a48d

Please sign in to comment.