1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-05-17 15:50:34 +02:00

add search inside saved items pane. fixes #26

This commit is contained in:
Kushagra Gour 2017-04-30 20:29:44 +05:30
parent 659588d580
commit b6e463ba4c
4 changed files with 83 additions and 26 deletions

View File

@ -507,17 +507,18 @@
<div id="js-saved-items-pane" class="saved-items-pane"> <div id="js-saved-items-pane" class="saved-items-pane">
<button class="btn saved-items-pane__close-btn" id="js-saved-items-pane-close-btn">X</button> <button class="btn saved-items-pane__close-btn" id="js-saved-items-pane-close-btn">X</button>
<div class="flex flex-v-center" style="justify-content: space-between;"> <div class="flex flex-v-center" style="justify-content: space-between;">
<h3>My Library <span id="savedItemCountEl"></span></h3>
<h3>My Library <span id="savedItemCountEl"></span></h3> <div class="main-header__btn-wrap">
<div class="main-header__btn-wrap"> <a d-click="exportItems" href="" class="btn btn-icon">Export
<a d-click="exportItems" href="" class="btn btn-icon">Export </a>
</a> <a d-click="onImportBtnClicked" href="" class="btn btn-icon">Import
<a d-click="onImportBtnClicked" href="" class="btn btn-icon">Import </a>
</a> </div>
</div>
</div> </div>
<input type="" id="searchInput" class="search-input" d-input="onSearchInputChange" placeholder="Search your creations here...">
<div id="js-saved-items-wrap" class="saved-items-pane__container"> <div id="js-saved-items-wrap" class="saved-items-pane__container">
</div> </div>
</div> </div>

View File

@ -5,7 +5,7 @@ addLibraryModal, addLibraryModal, notificationsBtn, notificationsModal, notifica
notificationsModal, notificationsBtn, codepenBtn, saveHtmlBtn, saveBtn, settingsBtn, notificationsModal, notificationsBtn, codepenBtn, saveHtmlBtn, saveBtn, settingsBtn,
onboardModal, settingsModal, notificationsBtn, onboardShowInTabOptionBtn, editorThemeLinkTag, onboardModal, settingsModal, notificationsBtn, onboardShowInTabOptionBtn, editorThemeLinkTag,
onboardDontShowInTabOptionBtn, TextareaAutoComplete, savedItemCountEl, indentationSizeValueEl, onboardDontShowInTabOptionBtn, TextareaAutoComplete, savedItemCountEl, indentationSizeValueEl,
runBtn runBtn, searchInput
*/ */
/* eslint-disable no-extra-semi */ /* eslint-disable no-extra-semi */
;(function (alertsService) { ;(function (alertsService) {
@ -70,6 +70,7 @@ runBtn
, prefs = {} , prefs = {}
, codeInPreview = { html: null, css: null, js: null } , codeInPreview = { html: null, css: null, js: null }
, isSavedItemsPaneOpen = false , isSavedItemsPaneOpen = false
, editorWithFocus
// DOM nodes // DOM nodes
, frame = $('#demo-frame') , frame = $('#demo-frame')
@ -336,6 +337,13 @@ runBtn
savedItemsPane.classList.toggle('is-open'); savedItemsPane.classList.toggle('is-open');
} }
isSavedItemsPaneOpen = savedItemsPane.classList.contains('is-open'); isSavedItemsPaneOpen = savedItemsPane.classList.contains('is-open');
if (isSavedItemsPaneOpen) {
searchInput.focus();
} else {
searchInput.value = '';
// Give last focused editor, focus again
editorWithFocus.focus();
}
document.body.classList[isSavedItemsPaneOpen ? 'add' : 'remove']('overlay-visible'); document.body.classList[isSavedItemsPaneOpen ? 'add' : 'remove']('overlay-visible');
} }
@ -353,7 +361,7 @@ runBtn
d.resolve([]); d.resolve([]);
} }
savedItems = savedItems || []; savedItems = savedItems || {};
trackEvent('fn', 'fetchItems', itemIds.length); trackEvent('fn', 'fetchItems', itemIds.length);
for (let i = 0; i < itemIds.length; i++) { for (let i = 0; i < itemIds.length; i++) {
@ -892,6 +900,9 @@ runBtn
} }
} }
}); });
cm.on('focus', (editor) => {
editorWithFocus = editor;
});
cm.on('change', function onChange(editor, change) { cm.on('change', function onChange(editor, change) {
clearTimeout(updateTimer); clearTimeout(updateTimer);
@ -1258,20 +1269,33 @@ runBtn
trackEvent('ui', 'saveBtnClick', currentItem.id ? 'saved' : 'new'); trackEvent('ui', 'saveBtnClick', currentItem.id ? 'saved' : 'new');
saveItem(); saveItem();
}; };
scope.onSearchInputChange = function (e) {
const text = e.target.value;
let el;
for (let [itemId, item] of Object.entries(savedItems)) {
el = $(`#js-saved-items-pane [data-item-id=${itemId}]`);
if (item.title.toLowerCase().indexOf(text) === -1) {
el.classList.add('hide');
} else {
el.classList.remove('hide');
}
}
};
function compileNodes() { function compileNodes() {
var nodes = [].slice.call($all('[d-click]'));
nodes.forEach(function (el) { function attachListenerForEvent(eventName) {
el.addEventListener('click', function (e) { var nodes;
scope[el.getAttribute('d-click')].call(window, e) nodes = $all(`[d-${eventName}]`);
nodes.forEach(function (el) {
el.addEventListener(eventName, function (e) {
scope[el.getAttribute(`d-${eventName}`)].call(window, e)
});
}); });
}); }
nodes = [].slice.call($all('[d-change]')); attachListenerForEvent('click');
nodes.forEach(function (el) { attachListenerForEvent('change');
el.addEventListener('change', function (e) { attachListenerForEvent('input');
scope[el.getAttribute('d-change')].call(window, e)
});
})
} }
function init () { function init () {
@ -1434,9 +1458,9 @@ runBtn
selectedItemElement = $('.js-saved-item-tile.selected'); selectedItemElement = $('.js-saved-item-tile.selected');
if (selectedItemElement) { if (selectedItemElement) {
selectedItemElement.classList.remove('selected'); selectedItemElement.classList.remove('selected');
selectedItemElement.nextElementSibling.classList.add('selected'); selectedItemElement.nextUntil('.js-saved-item-tile:not(.hide)').classList.add('selected');
} else { } else {
$('.js-saved-item-tile:first-child').classList.add('selected'); $('.js-saved-item-tile:not(.hide)').classList.add('selected');
} }
$('.js-saved-item-tile.selected').scrollIntoView(false); $('.js-saved-item-tile.selected').scrollIntoView(false);
} else if (event.keyCode === 38 && isSavedItemsPaneOpen) { } else if (event.keyCode === 38 && isSavedItemsPaneOpen) {
@ -1445,7 +1469,7 @@ runBtn
selectedItemElement.classList.remove('selected'); selectedItemElement.classList.remove('selected');
selectedItemElement.previousElementSibling.classList.add('selected'); selectedItemElement.previousElementSibling.classList.add('selected');
} else { } else {
$('.js-saved-item-tile:first-child').classList.add('selected'); $('.js-saved-item-tile:not(.hide)').classList.add('selected');
} }
$('.js-saved-item-tile.selected').scrollIntoView(false); $('.js-saved-item-tile.selected').scrollIntoView(false);
} else if (event.keyCode === 13 && isSavedItemsPaneOpen) { } else if (event.keyCode === 13 && isSavedItemsPaneOpen) {

View File

@ -373,7 +373,16 @@ li.CodeMirror-hint-active {
background: none; background: none;
border: 0; border: 0;
color: rgba(255,255,255,0.6); color: rgba(255,255,255,0.6);
width: calc(100vw - 400px); width: calc(100vw - 420px);
}
.search-input {
background: rgba(255, 255, 255, 0.1);
padding: 10px 20px;
border: 0;
width: 100%;
font-size: 16px;
color: white;
border-radius: 4px;
} }
.modal { .modal {
position: fixed; position: fixed;

View File

@ -2,9 +2,32 @@
window.DEBUG = document.cookie.indexOf('wmdebug') > -1; window.DEBUG = document.cookie.indexOf('wmdebug') > -1;
window.$ = document.querySelector.bind(document); window.$ = document.querySelector.bind(document);
window.$all = document.querySelectorAll.bind(document); window.$all = (selector) => [...document.querySelectorAll(selector)] ;
var alphaNum = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; var alphaNum = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
/**
* The following 2 functions are supposed to find the next/previous sibling until the
* passed `selector` is matched. But for now it actually finds the next/previous
* element of `this` element in the list of `selector` matched element inside `this`'s
* parent.
* @param Selector that should match for next siblings
* @return element Next element that mathes `selector`
*/
Node.prototype.nextUntil = function (selector) {
var siblings = [...this.parentNode.querySelectorAll(selector)];
var index = siblings.indexOf(this);
return siblings[index + 1];
};
/*
* @param Selector that should match for next siblings
* @return element Next element that mathes `selector`
*/
Node.prototype.previousUntil = function (selector) {
var siblings = [...this.parentNode.querySelectorAll(selector)];
var index = siblings.indexOf(this);
return siblings[index - 1];
};
// https://github.com/substack/semver-compare/blob/master/index.js // https://github.com/substack/semver-compare/blob/master/index.js
function semverCompare(a, b) { function semverCompare(a, b) {
var pa = a.split('.'); var pa = a.split('.');