forked from composer/satis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update npm dependencies and style/syntax
- Loading branch information
Showing
8 changed files
with
131 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'; | ||
import { formatDistanceToNow } from 'date-fns' | ||
import { enUS } from 'date-fns/locale' | ||
|
||
class DateDistance { | ||
static calculate(elements) { | ||
if (typeof elements === 'string') { | ||
elements = document.querySelectorAll(elements); | ||
} | ||
for (let i = 0; i < elements.length; i++) { | ||
let element = elements[i]; | ||
let datetime = element.attributes.datetime.value; | ||
let date = new Date(datetime); | ||
let distance = distanceInWordsToNow(date, { | ||
addSuffix: true | ||
}); | ||
|
||
element.textContent = distance; | ||
} | ||
static calculate(elements) { | ||
if (typeof elements === 'string') { | ||
elements = document.querySelectorAll(elements) | ||
} | ||
|
||
for (let i = 0; i < elements.length; i++) { | ||
let element = elements[i] | ||
let datetime = element.attributes.datetime.value | ||
let date = new Date(datetime) | ||
let distance = formatDistanceToNow(date, { | ||
addSuffix: true, | ||
locale: enUS | ||
}) | ||
|
||
element.textContent = distance | ||
} | ||
} | ||
} | ||
|
||
export default DateDistance; | ||
export default DateDistance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,65 @@ | ||
import $ from 'jquery'; | ||
import $ from 'jquery' | ||
|
||
class PackageFilter { | ||
constructor(input, list, listItem) { | ||
this.input = $(input); | ||
this.list = $(list); | ||
this.listItemSelector = listItem; | ||
this.packages = this.list.find(listItem); | ||
this.inputTimeout = null; | ||
constructor(input, list, listItem) { | ||
this.input = $(input) | ||
this.list = $(list) | ||
this.listItemSelector = listItem | ||
this.packages = this.list.find(listItem) | ||
this.inputTimeout = null | ||
this.readHash = this.readHash.bind(this) | ||
this.updateHash = this.updateHash.bind(this) | ||
this.filterPackages = this.filterPackages.bind(this) | ||
|
||
this.readHash = this.readHash.bind(this); | ||
this.updateHash = this.updateHash.bind(this); | ||
this.filterPackages = this.filterPackages.bind(this); | ||
this.init() | ||
} | ||
|
||
this.init(); | ||
} | ||
|
||
readHash() { | ||
let hash = window.decodeURIComponent(window.location.hash.substr(1)); | ||
|
||
if (hash.length > 0) { | ||
this.input.val(hash); | ||
this.filterPackages(); | ||
} | ||
}; | ||
readHash() { | ||
let hash = window.decodeURIComponent(window.location.hash.substr(1)) | ||
|
||
updateHash() { | ||
window.location.hash = window.encodeURIComponent(this.input.val()); | ||
}; | ||
if (hash.length > 0) { | ||
this.input.val(hash) | ||
this.filterPackages() | ||
} | ||
} | ||
|
||
filterPackages() { | ||
var needle = this.input.val().toLowerCase(), | ||
closestSelector = this.listItemSelector; | ||
updateHash() { | ||
window.location.hash = window.encodeURIComponent(this.input.val()) | ||
} | ||
|
||
this.list.hide(); | ||
filterPackages() { | ||
let needle = this.input.val().toLowerCase() | ||
let closestSelector = this.listItemSelector | ||
|
||
this.packages.each(function () { | ||
$(this).closest(closestSelector).toggle( | ||
$(this).text().toLowerCase().indexOf(needle) !== -1 | ||
); | ||
}); | ||
this.list.hide() | ||
|
||
this.list.show(); | ||
}; | ||
this.packages.each(function () { | ||
$(this).closest(closestSelector).toggle( | ||
$(this).text().toLowerCase().indexOf(needle) !== -1 | ||
) | ||
}) | ||
|
||
init() { | ||
var instance = this; | ||
this.list.show() | ||
} | ||
|
||
instance.input.keyup(function () { | ||
instance.updateHash(); | ||
window.clearTimeout(instance.inputTimeout); | ||
instance.inputTimeout = window.setTimeout(instance.filterPackages, 350); | ||
}); | ||
init() { | ||
var instance = this | ||
|
||
$(window).keyup(function (event) { | ||
if (event.keyCode === 27) { // "ESC" keyCode | ||
instance.input.val(''); | ||
instance.filterPackages(); | ||
} | ||
}); | ||
instance.input.keyup(function () { | ||
instance.updateHash() | ||
window.clearTimeout(instance.inputTimeout) | ||
instance.inputTimeout = window.setTimeout(instance.filterPackages, 350) | ||
}) | ||
|
||
instance.readHash(); | ||
$(window).keyup(function (event) { | ||
if (event.keyCode === 27) { // "ESC" keyCode | ||
instance.input.val('') | ||
instance.filterPackages() | ||
} | ||
}) | ||
|
||
instance.readHash() | ||
} | ||
} | ||
|
||
export default PackageFilter; | ||
export default PackageFilter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import $ from 'jquery'; | ||
// import 'bootstrap'; | ||
// import 'popper.js'; | ||
import 'bootstrap/js/dist/collapse'; | ||
import DateDistance from './App/DateDistance'; | ||
import PackageFilter from './App/PackageFilter'; | ||
import $ from 'jquery' | ||
import 'bootstrap/js/dist/collapse' | ||
import DateDistance from './App/DateDistance' | ||
import PackageFilter from './App/PackageFilter' | ||
|
||
function updateTimeElements () { | ||
DateDistance.calculate('time') | ||
DateDistance.calculate('time') | ||
}; | ||
|
||
$(document).ready(function() { | ||
new PackageFilter('input#search', '#package-list', '.card'); | ||
|
||
updateTimeElements(); | ||
window.setInterval(updateTimeElements, 5000); | ||
$(function() { | ||
new PackageFilter('input#search', '#package-list', '.card') | ||
updateTimeElements() | ||
window.setInterval(updateTimeElements, 5000) | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"entrypoints": { | ||
"app": { | ||
"js": [ | ||
"/build/app.js" | ||
] | ||
}, | ||
"style": { | ||
"css": [ | ||
"/build/style.css" | ||
] | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,15 @@ | ||
var Encore = require('@symfony/webpack-encore'); | ||
const Encore = require('@symfony/webpack-encore') | ||
|
||
Encore | ||
// directory where compiled assets will be stored | ||
.setOutputPath('views/build/') | ||
// public path used by the web server to access the output path | ||
.setPublicPath('/build') | ||
// only needed for CDN's or sub-directory deploy | ||
// .setManifestKeyPrefix('assets/') | ||
|
||
/* | ||
* ENTRY CONFIG | ||
* | ||
* Add 1 entry for each "page" of your app | ||
* (including one that's included on every page - e.g. "app") | ||
* | ||
* Each entry will result in one JavaScript file (e.g. app.js) | ||
* and one CSS file (e.g. app.css) if you JavaScript imports CSS. | ||
*/ | ||
.addEntry('app', './views/assets/js/app.js') | ||
//.addEntry('page1', './assets/js/page1.js') | ||
//.addEntry('page2', './assets/js/page2.js') | ||
.addStyleEntry('style', './views/assets/css/style.scss') | ||
|
||
/* | ||
* FEATURE CONFIG | ||
* | ||
* Enable & configure other features below. For a full | ||
* list of features, see: | ||
* https://symfony.com/doc/current/frontend.html#adding-more-features | ||
*/ | ||
.cleanupOutputBeforeBuild() | ||
// .enableBuildNotifications() | ||
.enableSourceMaps(!Encore.isProduction()) | ||
// enables hashed filenames (e.g. app.abc123.css) | ||
// .enableVersioning(Encore.isProduction()) | ||
|
||
// enables Sass/SCSS support | ||
.enableSassLoader() | ||
|
||
// uncomment if you use TypeScript | ||
//.enableTypeScriptLoader() | ||
|
||
// uncomment if you're having problems with a jQuery plugin | ||
//.autoProvidejQuery() | ||
; | ||
|
||
module.exports = Encore.getWebpackConfig(); | ||
.addEntry('app', './views/assets/js/app.js') | ||
.addStyleEntry('style', './views/assets/css/style.scss') | ||
.cleanupOutputBeforeBuild() | ||
.disableSingleRuntimeChunk() | ||
.enableSassLoader() | ||
.enableSourceMaps(!Encore.isProduction()) | ||
.setOutputPath('views/build/') | ||
.setPublicPath('/build') | ||
|
||
const config = Encore.getWebpackConfig() | ||
|
||
module.exports = config |