mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-12 06:30:07 +01:00
Rebuild JS
This commit is contained in:
parent
22ca916daf
commit
c881954698
5 changed files with 62 additions and 56 deletions
|
@ -1,19 +1,23 @@
|
|||
function htmlToElement(html) {
|
||||
const $$ = function(selector) {
|
||||
return document.querySelectorAll(selector) || [];
|
||||
};
|
||||
|
||||
const makeEl = function(html) {
|
||||
const template = document.createElement('template');
|
||||
|
||||
template.innerHTML = html.trim();
|
||||
|
||||
return template.content.firstChild;
|
||||
}
|
||||
};
|
||||
|
||||
function escapeHtml(unsafe) {
|
||||
const escape = function(unsafe) {
|
||||
return unsafe
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
};
|
||||
|
||||
class TagsInput {
|
||||
constructor(element, options = {}) {
|
||||
|
@ -29,12 +33,19 @@ class TagsInput {
|
|||
attach() {
|
||||
this.element.style.display = 'none';
|
||||
|
||||
this.containerNode = htmlToElement('<div class="tags-input"></div>');
|
||||
this.inputNode = htmlToElement('<input class="input" type="text" placeholder="10 tags maximum" value="" />');
|
||||
this.containerNode = makeEl('<div class="tags-input"></div>');
|
||||
this.inputNode = makeEl('<input class="input" type="text" placeholder="10 tags maximum" value="" />');
|
||||
this.containerNode.appendChild(this.inputNode);
|
||||
|
||||
this.element.parentNode.insertBefore(this.containerNode, this.element.nextSibling);
|
||||
|
||||
/* Load existing tags from input */
|
||||
if (this.element.value) {
|
||||
for (const tag of this.element.value.split(',')) {
|
||||
this.addTag(tag);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle addition and removal of tags via key-presses */
|
||||
this.containerNode.addEventListener('keydown', this._handleInputKeyUp.bind(this));
|
||||
|
||||
|
@ -70,7 +81,7 @@ class TagsInput {
|
|||
this.tags.push(tagValue.toLowerCase());
|
||||
|
||||
this.inputNode.parentNode.insertBefore(
|
||||
htmlToElement('<span class="tag is-info" data-value="' + escapeHtml(tagValue) + '">' + escapeHtml(tagValue) + '<span class="delete is-small" /></span>'),
|
||||
makeEl('<span class="tag is-info" data-value="' + escape(tagValue) + '">' + escape(tagValue) + '<span class="delete is-small" /></span>'),
|
||||
this.inputNode
|
||||
);
|
||||
|
||||
|
@ -109,18 +120,14 @@ class TagsInput {
|
|||
}
|
||||
}
|
||||
|
||||
class Meme {
|
||||
constructor() {
|
||||
alert('xss');
|
||||
const setupSite = function() {
|
||||
Array.prototype.forEach.call($$('.js-tag-input'), (el) => {
|
||||
new TagsInput(el).attach();
|
||||
});
|
||||
};
|
||||
|
||||
if (document.readyState !== 'loading') {
|
||||
setupSite();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', setupSite);
|
||||
}
|
||||
|
||||
meme() {
|
||||
console.log('meme');
|
||||
}
|
||||
}
|
||||
|
||||
const meme = new Meme();
|
||||
|
||||
meme.meme();
|
||||
|
||||
new TagsInput(null);
|
||||
|
|
2
assets/bundle.min.js
vendored
2
assets/bundle.min.js
vendored
|
@ -1,2 +1,2 @@
|
|||
function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function n(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}function i(e){var t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild}function a(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}var s=function(){function t(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e(this,t),this.element=n,this.tags=[],this.options=i,this.maxTags=i.maxTags||10,this.inputNode=null,this.containerNode=null}return n(t,[{key:"attach",value:function(){this.element.style.display="none",this.containerNode=i('<div class="tags-input"></div>'),this.inputNode=i('<input class="input" type="text" placeholder="10 tags maximum" value="" />'),this.containerNode.appendChild(this.inputNode),this.element.parentNode.insertBefore(this.containerNode,this.element.nextSibling),this.containerNode.addEventListener("keydown",this._handleInputKeyUp.bind(this)),this.containerNode.addEventListener("click",this._handleContainerClick.bind(this))}},{key:"detach",value:function(){this.tags.clear(),this.containerNode.remove(),this.element.style.display="inline-block"}},{key:"updateHiddenInputValue",value:function(){this.element.value=this.tags.join(",")}},{key:"deleteTagNode",value:function(e){this.tags.splice(this.tags.indexOf(e.dataset.value.toLowerCase()),1),e.remove(),this.tags.length<this.maxTags&&(this.inputNode.disabled=!1)}},{key:"addTag",value:function(e){""!==(e=e.trim())&&-1===this.tags.indexOf(e.toLowerCase())&&(this.tags.push(e.toLowerCase()),this.inputNode.parentNode.insertBefore(i('<span class="tag is-info" data-value="'+a(e)+'">'+a(e)+'<span class="delete is-small" /></span>'),this.inputNode),this.tags.length>=this.maxTags&&(this.inputNode.disabled=!0))}},{key:"_handleInputKeyUp",value:function(e){var t=this.inputNode.value;"Backspace"===e.key&&""===t?this.inputNode.previousSibling&&(this.deleteTagNode(this.inputNode.previousSibling),this.updateHiddenInputValue()):","===e.key&&(this.addTag(t),this.inputNode.value="",this.updateHiddenInputValue(),e.preventDefault())}},{key:"_handleContainerClick",value:function(e){e.target&&e.target.classList.contains("delete")&&(this.deleteTagNode(e.target.closest(".tag")),this.updateHiddenInputValue())}}]),t}();(new(function(){function t(){e(this,t),alert("xss")}return n(t,[{key:"meme",value:function(){console.log("meme")}}]),t}())).meme(),new s(null);
|
||||
function e(e,n){var i="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!i){if(Array.isArray(e)||(i=function(e,n){if(!e)return;if("string"==typeof e)return t(e,n);var i=Object.prototype.toString.call(e).slice(8,-1);"Object"===i&&e.constructor&&(i=e.constructor.name);if("Map"===i||"Set"===i)return Array.from(e);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return t(e,n)}(e))||n&&e&&"number"==typeof e.length){i&&(e=i);var a=0,r=function(){};return{s:r,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,l=!1;return{s:function(){i=i.call(e)},n:function(){var e=i.next();return s=e.done,e},e:function(e){l=!0,o=e},f:function(){try{s||null==i.return||i.return()}finally{if(l)throw o}}}}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}var a=function(e){var t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild},r=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},o=function(){function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,t),this.element=e,this.tags=[],this.options=i,this.maxTags=i.maxTags||10,this.inputNode=null,this.containerNode=null}var o,s,l;return o=t,(s=[{key:"attach",value:function(){if(this.element.style.display="none",this.containerNode=a('<div class="tags-input"></div>'),this.inputNode=a('<input class="input" type="text" placeholder="10 tags maximum" value="" />'),this.containerNode.appendChild(this.inputNode),this.element.parentNode.insertBefore(this.containerNode,this.element.nextSibling),this.element.value){var t,n=e(this.element.value.split(","));try{for(n.s();!(t=n.n()).done;){var i=t.value;this.addTag(i)}}catch(e){n.e(e)}finally{n.f()}}this.containerNode.addEventListener("keydown",this._handleInputKeyUp.bind(this)),this.containerNode.addEventListener("click",this._handleContainerClick.bind(this))}},{key:"detach",value:function(){this.tags.clear(),this.containerNode.remove(),this.element.style.display="inline-block"}},{key:"updateHiddenInputValue",value:function(){this.element.value=this.tags.join(",")}},{key:"deleteTagNode",value:function(e){this.tags.splice(this.tags.indexOf(e.dataset.value.toLowerCase()),1),e.remove(),this.tags.length<this.maxTags&&(this.inputNode.disabled=!1)}},{key:"addTag",value:function(e){""!==(e=e.trim())&&-1===this.tags.indexOf(e.toLowerCase())&&(this.tags.push(e.toLowerCase()),this.inputNode.parentNode.insertBefore(a('<span class="tag is-info" data-value="'+r(e)+'">'+r(e)+'<span class="delete is-small" /></span>'),this.inputNode),this.tags.length>=this.maxTags&&(this.inputNode.disabled=!0))}},{key:"_handleInputKeyUp",value:function(e){var t=this.inputNode.value;"Backspace"===e.key&&""===t?this.inputNode.previousSibling&&(this.deleteTagNode(this.inputNode.previousSibling),this.updateHiddenInputValue()):","===e.key&&(this.addTag(t),this.inputNode.value="",this.updateHiddenInputValue(),e.preventDefault())}},{key:"_handleContainerClick",value:function(e){e.target&&e.target.classList.contains("delete")&&(this.deleteTagNode(e.target.closest(".tag")),this.updateHiddenInputValue())}}])&&i(o.prototype,s),l&&i(o,l),t}(),s=function(){var e;Array.prototype.forEach.call((e=".js-tag-input",document.querySelectorAll(e)||[]),(function(e){new o(e).attach()}))};"loading"!==document.readyState?s():document.addEventListener("DOMContentLoaded",s);
|
||||
//# sourceMappingURL=bundle.min.js.map
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -26,6 +26,28 @@ function urlForMember(string $member_name) : string {
|
|||
return '/user.php?name=' . urlencode($member_name);
|
||||
}
|
||||
|
||||
function optionsForSelect(array $displays, array $values, string $currentSelection = null) : string {
|
||||
$size = count($displays);
|
||||
|
||||
if (count($values) !== $size) {
|
||||
throw new Exception('Option names and option values must be the same count');
|
||||
}
|
||||
|
||||
$html = '';
|
||||
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$html .= '<option value="' . pp_html_escape($values[$i]) . '"';
|
||||
|
||||
if ($currentSelection === $values[$i]) {
|
||||
$html .= ' selected="selected"';
|
||||
}
|
||||
|
||||
$html .= '>' . pp_html_escape($displays[$i]) . '</option>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/* Database functions */
|
||||
function getSiteInfo() : array {
|
||||
return require(__DIR__ . '/../config/site.php');
|
||||
|
|
|
@ -17,21 +17,16 @@
|
|||
<div class="content is-normal">
|
||||
<ul>
|
||||
<li>Ponepaste has now a favorite system. You can now favorite pastes and
|
||||
bookmark them on your userpage under "Favorites"
|
||||
</li>
|
||||
bookmark them on your user page under "Favorites"</li>
|
||||
<li>Report function and UI has been overhauled.</li>
|
||||
<li>The archive page has now been updated, tags are now clickable for a
|
||||
faster search.
|
||||
</li>
|
||||
faster search.</li>
|
||||
<li>Tags UI has been overhauled. Tags containing "SAFE" and "NSFW" will
|
||||
appear green and red.
|
||||
</li>
|
||||
appear green and red.</li>
|
||||
<li>When Creating paste the tag input box has been updated with a new visual
|
||||
style.
|
||||
</li>
|
||||
style.</li>
|
||||
<li>Tags are now being canonized, if you see your tags change, it's just the
|
||||
admin working in the background
|
||||
</li>
|
||||
admin working in the background</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -220,30 +215,12 @@
|
|||
}
|
||||
?>
|
||||
<select name="paste_expire_date">
|
||||
<option value="N" <?php echo ($post_expire == "N") ? 'selected="selected"' : ''; ?>>
|
||||
Never
|
||||
</option>
|
||||
<option value="self" <?php echo ($post_expire == "self") ? 'selected="selected"' : ''; ?>>
|
||||
View Once
|
||||
</option>
|
||||
<option value="10M" <?php echo ($post_expire == "10M") ? 'selected="selected"' : ''; ?>>
|
||||
10 Minutes
|
||||
</option>
|
||||
<option value="1H" <?php echo ($post_expire == "1H") ? 'selected="selected"' : ''; ?>>
|
||||
1 Hour
|
||||
</option>
|
||||
<option value="1D" <?php echo ($post_expire == "1D") ? 'selected="selected"' : ''; ?>>
|
||||
1 Day
|
||||
</option>
|
||||
<option value="1W" <?php echo ($post_expire == "1W") ? 'selected="selected"' : ''; ?>>
|
||||
1 Week
|
||||
</option>
|
||||
<option value="2W" <?php echo ($post_expire == "2W") ? 'selected="selected"' : ''; ?>>
|
||||
2 Weeks
|
||||
</option>
|
||||
<option value="1M" <?php echo ($post_expire == "1M") ? 'selected="selected"' : ''; ?>>
|
||||
1 Month
|
||||
</option>
|
||||
|
||||
<?= optionsForSelect(
|
||||
['Never', 'View Once', '10 minutes', '1 hour', '1 day', '1 week', '2 weeks', '1 month'],
|
||||
['N', 'self', '10M', '1H', '1D', '1W', '2W', '1M'],
|
||||
$post_expire
|
||||
); ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue