bye jquery.timeago, hello es6
This commit is contained in:
@ -41,132 +41,7 @@
|
||||
</section>
|
||||
|
||||
<script type="text/javascript" src="/js/jquery-3.1.0.min.js"></script>
|
||||
<script type="text/javascript" src="/js/jquery.timeago.js"></script>
|
||||
<script type="text/javascript" src="/js/jquery-ui.min.js"></script>
|
||||
<script type="text/javascript" src="/js/main.js"></script>
|
||||
<script>
|
||||
$(document).ready(() => {
|
||||
let s = $.timeago.settings;
|
||||
let str = s.strings;
|
||||
s.refreshMillis = 1000;
|
||||
s.allowFuture = true;
|
||||
s.localeTitle = true;
|
||||
str.seconds = "%d seconds";
|
||||
str.minute = "1 minute";
|
||||
str.hour = "1 hour";
|
||||
str.hours = "%d hours";
|
||||
str.day = "1 day";
|
||||
str.month = "1 month";
|
||||
str.year = "1 year";
|
||||
str.suffixFromNow = null;
|
||||
$("time.timeago").timeago();
|
||||
|
||||
$.widget("custom.combobox", {
|
||||
_create: function() {
|
||||
this.wrapper = $("<span>")
|
||||
.addClass("custom-combobox")
|
||||
.insertAfter(this.element);
|
||||
this.element.hide();
|
||||
this._createAutocomplete();
|
||||
this._createShowAllButton();
|
||||
},
|
||||
_createAutocomplete: function() {
|
||||
var selected = this.element.children(":selected"),
|
||||
value = selected.val() ? selected.text() : "";
|
||||
this.input = $("<input>")
|
||||
.appendTo(this.wrapper)
|
||||
.val(value)
|
||||
.attr("title", "")
|
||||
.addClass("custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left")
|
||||
.autocomplete({
|
||||
delay: 0,
|
||||
minLength: 0,
|
||||
source: $.proxy(this, "_source")
|
||||
})
|
||||
.tooltip({
|
||||
classes: {
|
||||
"ui-tooltip": "ui-state-highlight"
|
||||
}
|
||||
});
|
||||
this._on(this.input, {
|
||||
autocompleteselect: function(event, ui) {
|
||||
ui.item.option.selected = true;
|
||||
this._trigger("select", event, {
|
||||
item: ui.item.option
|
||||
});
|
||||
},
|
||||
autocompletechange: "_removeIfInvalid"
|
||||
});
|
||||
},
|
||||
_createShowAllButton: function() {
|
||||
var input = this.input,
|
||||
wasOpen = false;
|
||||
$("<a>")
|
||||
.attr("tabIndex", -1)
|
||||
.attr("title", "Show All Items")
|
||||
.tooltip()
|
||||
.appendTo(this.wrapper)
|
||||
.button({
|
||||
icons: {
|
||||
primary: "ui-icon-triangle-1-s"
|
||||
},
|
||||
text: false
|
||||
})
|
||||
.removeClass("ui-corner-all")
|
||||
.addClass("custom-combobox-toggle ui-corner-right")
|
||||
.on("mousedown", function() {
|
||||
wasOpen = input.autocomplete("widget").is(":visible");
|
||||
})
|
||||
.on("click", function() {
|
||||
input.trigger("focus");
|
||||
if (wasOpen) return;
|
||||
input.autocomplete("search", "");
|
||||
});
|
||||
},
|
||||
_source: function(request, response) {
|
||||
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
|
||||
response(this.element.children("option").map(function() {
|
||||
var text = $(this).text();
|
||||
if (this.value && (!request.term || matcher.test(text)))
|
||||
return {
|
||||
label: text,
|
||||
value: text,
|
||||
option: this
|
||||
};
|
||||
}));
|
||||
},
|
||||
_removeIfInvalid: function(event, ui) {
|
||||
if (ui.item) return;
|
||||
var value = this.input.val(),
|
||||
valueLowerCase = value.toLowerCase(),
|
||||
valid = false;
|
||||
this.element.children("option").each(function() {
|
||||
if ($(this).text().toLowerCase() === valueLowerCase) {
|
||||
this.selected = valid = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (valid) return;
|
||||
this.input
|
||||
.val("")
|
||||
.attr("title", value + " didn't match any item")
|
||||
.tooltip("open");
|
||||
this.element.val("");
|
||||
this._delay(function() {
|
||||
this.input.tooltip("close").attr("title", "");
|
||||
}, 2500);
|
||||
this.input.autocomplete("instance").term = "";
|
||||
},
|
||||
_destroy: function() {
|
||||
this.wrapper.remove();
|
||||
this.element.show();
|
||||
}
|
||||
});
|
||||
$("#lang").combobox();
|
||||
$("#toggle").on("click", function() {
|
||||
$("#lang").toggle();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,6 +1,6 @@
|
||||
{{#each this}}
|
||||
<div class="pasteInfo">
|
||||
<p class="timestamp"><time class="timeago" title="{{stamp}}" datetime="{{stamp}}"></time></p>
|
||||
<p class="timestamp"><time title="{{stamp}}"></time></p>
|
||||
<p class="language"><a href="/v/lang/{{language}}">{{language}}</a></p>
|
||||
<p>Paste: <a href="/{{uuid}}/">/{{uuid}}/</a><a href="/v/id/{{uuid}}">Show related</a></p>
|
||||
<p class="desc">{{{desc}}}</p>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<div class="pasteInfo">
|
||||
<p class="timestamp"><time class="timeago" title="{{paste.stamp}}" datetime="{{paste.stamp}}"></time></p>
|
||||
<p class="timestamp"><time title="{{paste.stamp}}"></time></p>
|
||||
<p class="language"><a href="/v/lang/{{paste.language}}">{{paste.language}}</a></p>
|
||||
<p>Paste: <a href="/{{paste.uuid}}/">/{{paste.uuid}}/</a><a href="/v/id/{{paste.uuid}}">Show related</a></p>
|
||||
<p class="desc">{{{paste.desc}}}</p>
|
||||
|
Reference in New Issue
Block a user