// License: GPL v2 or (at your option) any later version
//
// PukiWiki JavaScript client script
-if (window.addEventListener) {
- window.addEventListener('DOMContentLoaded', function() {
+window.addEventListener && window.addEventListener('DOMContentLoaded', function() {
+ // Name for comment
+ function setYourName() {
+ var NAME_KEY_ID = 'pukiwiki_comment_plugin_name';
+ var actionPathname = null;
+ function getPathname(formAction) {
+ if (actionPathname) return actionPathname;
+ try {
+ var u = new URL(formAction, document.location);
+ var u2 = new URL('./', u);
+ actionPathname = u2.pathname;
+ return u2.pathname;
+ } catch (e) {
+ // Note: Internet Explorer doesn't support URL class
+ var m = formAction.match(/^https?:\/\/([^\/]+)(\/([^\?&]+\/)?)/);
+ if (m) {
+ actionPathname = m[2]; // pathname
+ } else {
+ actionPathname = '/';
+ }
+ return actionPathname;
+ }
+ }
+ function getNameKey(form) {
+ var pathname = getPathname(form.action);
+ var key = 'path.' + pathname + '.' + NAME_KEY_ID;
+ return key;
+ }
+ function isEmpty(s) {
+ if (s.match(/^\s*$/)) {
+ return true;
+ }
+ return false;
+ }
+ function getForm(element) {
+ if (element.form && element.form.tagName === 'FORM' && false) {
+ return element.form;
+ }
+ var e = element.parentElement;
+ for (var i = 0; i < 5; i++) {
+ if (e.tagName === 'FORM') {
+ return e;
+ }
+ e = e.parentElement;
+ }
+ return null;
+ }
+ function handleCommentPlugin(form) {
+ var namePrevious = '';
+ var nameKey = getNameKey(form);
+ if (typeof localStorage !== 'undefined') {
+ namePrevious = localStorage[nameKey];
+ }
+ var onFocusForm = function () {
+ if (form.name && !form.name.value && namePrevious) {
+ form.name.value = namePrevious;
+ }
+ };
+ var addOnForcusForm = function(eNullable) {
+ if (!eNullable) return;
+ var e = eNullable;
+ e.addEventListener && e.addEventListener('focus', onFocusForm);
+ }
+ if (namePrevious) {
+ var textList = form.querySelectorAll('input[type=text],textarea');
+ textList.forEach(function (v) {
+ addOnForcusForm(v);
+ });
+ }
+ form.addEventListener('submit', function(evt) {
+ if (typeof localStorage !== 'undefined') {
+ localStorage[nameKey] = form.name.value;
+ }
+ }, false);
+ }
+ function setNameForComment() {
+ if (!document.querySelectorAll) return;
+ var elements = document.querySelectorAll(
+ 'input[type=hidden][name=plugin][value=comment],' +
+ 'input[type=hidden][name=plugin][value=pcomment],' +
+ 'input[type=hidden][name=plugin][value=article],' +
+ 'input[type=hidden][name=plugin][value=bugtrack]');
+ for (var i = 0; i < elements.length; i++) {
+ var form = getForm(elements[i]);
+ if (form) {
+ handleCommentPlugin(form)
+ }
+ }
+ }
+ setNameForComment();
+ }
+ // AutoTicketLink
+ function autoTicketLink() {
if (!Array.prototype.indexOf || !document.createDocumentFragment) {
return;
}
}
function getSiteListFromBody() {
var list = [];
- var defRoot = document.querySelector('.pukiwiki-ticketlink-def');
- var siteNodes = defRoot.querySelectorAll('.pukiwiki-ticketlink-site');
+ var defRoot = document.querySelector('#pukiwiki-site-properties .ticketlink-def');
+ if (!defRoot) {
+ return [];
+ }
+ var siteNodes = defRoot.querySelectorAll('.ticketlink-site');
Array.prototype.forEach.call(siteNodes, function (e) {
- var siteInfoText = e.dataset && e.dataset.site;
+ var siteInfoText = e.getAttribute('data-site');
if (!siteInfoText) return;
var info = textToSiteInfo(siteInfoText);
if (info) {
}
var target = document.getElementById('body');
walkElement(target);
- });
-}
+ }
+ setYourName();
+ autoTicketLink();
+});