update jquery.localize to detect arrays
This commit is contained in:
parent
b8786b2f47
commit
e0e9246f32
12 changed files with 7997 additions and 5098 deletions
69
books.html
69
books.html
|
@ -3,8 +3,8 @@
|
|||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
|
||||
<title>fateforge-tools</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Books - fateforge.tools</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css" />
|
||||
<link href="css/all.min.css" rel="stylesheet" />
|
||||
|
||||
|
@ -30,78 +30,21 @@
|
|||
<div class="gallery"></div>
|
||||
|
||||
|
||||
<!--
|
||||
<div class="gallery-cell" id="ADV1">
|
||||
<div class="book-container">
|
||||
<div class="book">
|
||||
<img src="img\books\ADV1_BC_EN.jpg" />
|
||||
</div>
|
||||
<div class="book-title">Adventurer</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gallery-cell">
|
||||
<div class="book-container">
|
||||
<div class="book">
|
||||
<img src="img\books\GRI1_BC_EN.jpg" />
|
||||
</div>
|
||||
<div class="book-title">Grimoire</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gallery-cell" id="CRE2">
|
||||
<div class="book-container" data-localize="book-CRE2"></div>
|
||||
</div>
|
||||
<div class="gallery-cell">
|
||||
<div class="book-container">
|
||||
<div class="book">
|
||||
<img src="img\books\ENC1_BC_EN.png" />
|
||||
</div>
|
||||
<div class="book-title">Encyclopedia</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gallery-cell">
|
||||
<div class="book-container">
|
||||
<div class="book">
|
||||
<img src="img\books\ENC2_DR.png" />
|
||||
</div>
|
||||
<div class="book-title">Encyclopedia : Netherworld</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="view-container" style="display: flex; align-items: center; justify-content: center">
|
||||
<div class="view-container" style="display: flex;align-items: center;flex-direction: column;">
|
||||
<h1 id="view-title"></h1>
|
||||
<p class="book-desc" id="view-desc"></p>
|
||||
</div>
|
||||
|
||||
<link href="css/flickity.css" rel="stylesheet" />
|
||||
<link href="css/style.css" rel="stylesheet" />
|
||||
<script type="text/javascript" src="lib/showdown.js"></script>
|
||||
<script type="text/javascript" src="lib/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="lib/jquery.localize-dev.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/language.js"></script>
|
||||
<script type="module" src="js/books.js"></script>
|
||||
<!-- <script defer>
|
||||
var lastbook;
|
||||
var flkty = new Flickity(".gallery", {
|
||||
freeScroll: true,
|
||||
wrapAround: true,
|
||||
hash: true, // options
|
||||
});
|
||||
flkty.on("select", function (index) {
|
||||
var currentbook = document.getElementsByClassName("gallery-cell is-selected")[0].getAttribute("id");
|
||||
if (currentbook == lastbook) {
|
||||
return;
|
||||
}
|
||||
//TODO: Fill view-container with books
|
||||
setLocalizeDataAttr("view-title", currentbook + ".title");
|
||||
|
||||
lastbook = currentbook;
|
||||
refreshBooks();
|
||||
});
|
||||
flkty.on("settle", function (index) {
|
||||
console.log("Flickity settled at " + index);
|
||||
refreshBooks();
|
||||
});
|
||||
</script> -->
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -27,7 +27,7 @@
|
|||
transform: rotateY(-30deg);
|
||||
transition: transform 1s ease;
|
||||
animation: 1s ease 0s 1 initAnimation-fd6a;
|
||||
margin-bottom: 15px;
|
||||
margin-bottom: 3px;
|
||||
margin-top: 39px;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta charset="utf-8">
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
|
|
35
js/books.js
35
js/books.js
|
@ -17,35 +17,36 @@ for (const key in data) {
|
|||
gallery.insertAdjacentHTML("afterbegin", bookHTML);
|
||||
};
|
||||
var lastbook;
|
||||
var currentbook;
|
||||
var flkty = new Flickity(".gallery", {
|
||||
freeScroll: true,
|
||||
wrapAround: true,
|
||||
hash: true, // options
|
||||
});
|
||||
refreshBooks();
|
||||
currentbook = document.getElementsByClassName("gallery-cell is-selected")[0].getAttribute("id");
|
||||
//TODO: Fill view-container with books
|
||||
fillBookView();
|
||||
|
||||
flkty.on("select", function (index) {
|
||||
var currentbook = document.getElementsByClassName("gallery-cell is-selected")[0].getAttribute("id");
|
||||
currentbook = document.getElementsByClassName("gallery-cell is-selected")[0].getAttribute("id");
|
||||
if (currentbook == lastbook) {
|
||||
return;
|
||||
}
|
||||
//TODO: Fill view-container with books
|
||||
setLocalizeDataAttr("view-title", currentbook + ".title");
|
||||
|
||||
lastbook = currentbook;
|
||||
refreshBooks();
|
||||
fillBookView();
|
||||
});
|
||||
flkty.on("settle", function (index) {
|
||||
/*flkty.on("settle", function (index) {
|
||||
console.log("Flickity settled at " + index);
|
||||
refreshBooks();
|
||||
});
|
||||
});*/
|
||||
|
||||
function fillBookView(){
|
||||
setLocalizeDataAttr("view-title", currentbook + ".title");
|
||||
setLocalizeDataAttr("view-desc", currentbook + ".desc");
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
document
|
||||
.getElementsByClassName("gallery")[0]
|
||||
.insertAdjacentHTML(
|
||||
"afterbegin",
|
||||
'<div class="gallery-cell" id="ADV1"><div class="book-container"><div class="book"><img src="img\\books\\ADV1_BC_EN.png" /></div><div class="book-title">Adventurer</div></div></div>'
|
||||
);*/
|
||||
|
||||
lastbook = currentbook;
|
||||
console.log(currentLang);
|
||||
refreshBooks();
|
||||
}
|
|
@ -38,6 +38,7 @@ function refreshBooks() {
|
|||
});
|
||||
}
|
||||
|
||||
// Function to fill a data-localize attribute and update DOM
|
||||
function setLocalizeDataAttr(className, dataValue) {
|
||||
$("#" + className).data("localize", dataValue).attr("data-localize", dataValue);
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/*
|
||||
Copyright (c) Jim Garvin (http://github.com/coderifous), 2008.
|
||||
Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses.
|
||||
|
@ -7,18 +6,39 @@ http://github.com/coderifous/jquery-localize
|
|||
Based off of Keith Wood's Localisation jQuery plugin.
|
||||
http://keith-wood.name/localisation.html
|
||||
*/
|
||||
(function($) {
|
||||
(function ($) {
|
||||
var normaliseLang;
|
||||
normaliseLang = function(lang) {
|
||||
lang = lang.replace(/_/, '-').toLowerCase();
|
||||
normaliseLang = function (lang) {
|
||||
lang = lang.replace(/_/, "-").toLowerCase();
|
||||
if (lang.length > 3) {
|
||||
lang = lang.substring(0, 3) + lang.substring(3).toUpperCase();
|
||||
}
|
||||
return lang;
|
||||
};
|
||||
$.defaultLanguage = normaliseLang(navigator.languages && navigator.languages.length > 0 ? navigator.languages[0] : navigator.language || navigator.userLanguage);
|
||||
$.localize = function(pkg, options) {
|
||||
var defaultCallback, deferred, fileExtension, intermediateLangData, jsonCall, lang, loadLanguage, localizeElement, localizeForSpecialKeys, localizeImageElement, localizeInputElement, localizeOptgroupElement, notifyDelegateLanguageLoaded, regexify, setAttrFromValueForKey, setTextFromValueForKey, valueForKey, wrappedSet;
|
||||
$.defaultLanguage = normaliseLang(
|
||||
navigator.languages && navigator.languages.length > 0
|
||||
? navigator.languages[0]
|
||||
: navigator.language || navigator.userLanguage
|
||||
);
|
||||
$.localize = function (pkg, options) {
|
||||
var defaultCallback,
|
||||
deferred,
|
||||
fileExtension,
|
||||
intermediateLangData,
|
||||
jsonCall,
|
||||
lang,
|
||||
loadLanguage,
|
||||
localizeElement,
|
||||
localizeForSpecialKeys,
|
||||
localizeImageElement,
|
||||
localizeInputElement,
|
||||
localizeOptgroupElement,
|
||||
notifyDelegateLanguageLoaded,
|
||||
regexify,
|
||||
setAttrFromValueForKey,
|
||||
setTextFromValueForKey,
|
||||
valueForKey,
|
||||
wrappedSet;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
|
@ -26,7 +46,7 @@ http://keith-wood.name/localisation.html
|
|||
intermediateLangData = {};
|
||||
fileExtension = options.fileExtension || "json";
|
||||
deferred = $.Deferred();
|
||||
loadLanguage = function(pkg, lang, level) {
|
||||
loadLanguage = function (pkg, lang, level) {
|
||||
var file;
|
||||
if (level == null) {
|
||||
level = 1;
|
||||
|
@ -42,27 +62,33 @@ http://keith-wood.name/localisation.html
|
|||
}
|
||||
break;
|
||||
case 2:
|
||||
file = "" + pkg + "-" + (lang.split('-')[0]) + "." + fileExtension;
|
||||
file = "" + pkg + "-" + lang.split("-")[0] + "." + fileExtension;
|
||||
return jsonCall(file, pkg, lang, level);
|
||||
case 3:
|
||||
file = "" + pkg + "-" + (lang.split('-').slice(0, 2).join('-')) + "." + fileExtension;
|
||||
file =
|
||||
"" +
|
||||
pkg +
|
||||
"-" +
|
||||
lang.split("-").slice(0, 2).join("-") +
|
||||
"." +
|
||||
fileExtension;
|
||||
return jsonCall(file, pkg, lang, level);
|
||||
default:
|
||||
return deferred.resolve();
|
||||
}
|
||||
};
|
||||
jsonCall = function(file, pkg, lang, level) {
|
||||
jsonCall = function (file, pkg, lang, level) {
|
||||
var ajaxOptions, errorFunc, successFunc;
|
||||
if (options.pathPrefix != null) {
|
||||
file = "" + options.pathPrefix + "/" + file;
|
||||
}
|
||||
successFunc = function(d) {
|
||||
successFunc = function (d) {
|
||||
$.extend(intermediateLangData, d);
|
||||
notifyDelegateLanguageLoaded(intermediateLangData);
|
||||
return loadLanguage(pkg, lang, level + 1);
|
||||
};
|
||||
errorFunc = function() {
|
||||
if (level === 2 && lang.indexOf('-') > -1) {
|
||||
errorFunc = function () {
|
||||
if (level === 2 && lang.indexOf("-") > -1) {
|
||||
return loadLanguage(pkg, lang, level + 1);
|
||||
} else if (options.fallback && options.fallback !== lang) {
|
||||
return loadLanguage(pkg, options.fallback);
|
||||
|
@ -74,25 +100,25 @@ http://keith-wood.name/localisation.html
|
|||
async: true,
|
||||
timeout: options.timeout != null ? options.timeout : 500,
|
||||
success: successFunc,
|
||||
error: errorFunc
|
||||
error: errorFunc,
|
||||
};
|
||||
if (window.location.protocol === "file:") {
|
||||
ajaxOptions.error = function(xhr) {
|
||||
ajaxOptions.error = function (xhr) {
|
||||
return successFunc($.parseJSON(xhr.responseText));
|
||||
};
|
||||
}
|
||||
return $.ajax(ajaxOptions);
|
||||
};
|
||||
notifyDelegateLanguageLoaded = function(data) {
|
||||
notifyDelegateLanguageLoaded = function (data) {
|
||||
if (options.callback != null) {
|
||||
return options.callback(data, defaultCallback);
|
||||
} else {
|
||||
return defaultCallback(data);
|
||||
}
|
||||
};
|
||||
defaultCallback = function(data) {
|
||||
defaultCallback = function (data) {
|
||||
$.localize.data[pkg] = data;
|
||||
return wrappedSet.each(function() {
|
||||
return wrappedSet.each(function () {
|
||||
var elem, key, value;
|
||||
elem = $(this);
|
||||
key = elem.data("localize");
|
||||
|
@ -103,15 +129,23 @@ http://keith-wood.name/localisation.html
|
|||
}
|
||||
});
|
||||
};
|
||||
localizeElement = function(elem, key, value) {
|
||||
if (elem.is('input')) {
|
||||
localizeElement = function (elem, key, value) {
|
||||
if (elem.is("input")) {
|
||||
localizeInputElement(elem, key, value);
|
||||
} else if (elem.is('textarea')) {
|
||||
} else if (elem.is("textarea")) {
|
||||
localizeInputElement(elem, key, value);
|
||||
} else if (elem.is('img')) {
|
||||
} else if (elem.is("img")) {
|
||||
localizeImageElement(elem, key, value);
|
||||
} else if (elem.is('optgroup')) {
|
||||
} else if (elem.is("optgroup")) {
|
||||
localizeOptgroupElement(elem, key, value);
|
||||
} else if ($.isArray(value)) {
|
||||
elem.empty();
|
||||
for (const key in value) {
|
||||
var converter = new showdown.Converter(),
|
||||
text = value[key],
|
||||
converted = converter.makeHtml(text);
|
||||
elem.append(converted);
|
||||
}
|
||||
} else if (!$.isPlainObject(value)) {
|
||||
elem.html(value);
|
||||
}
|
||||
|
@ -119,7 +153,7 @@ http://keith-wood.name/localisation.html
|
|||
return localizeForSpecialKeys(elem, value);
|
||||
}
|
||||
};
|
||||
localizeInputElement = function(elem, key, value) {
|
||||
localizeInputElement = function (elem, key, value) {
|
||||
var val;
|
||||
val = $.isPlainObject(value) ? value.value : value;
|
||||
if (elem.is("[placeholder]")) {
|
||||
|
@ -128,19 +162,19 @@ http://keith-wood.name/localisation.html
|
|||
return elem.val(val);
|
||||
}
|
||||
};
|
||||
localizeForSpecialKeys = function(elem, value) {
|
||||
localizeForSpecialKeys = function (elem, value) {
|
||||
setAttrFromValueForKey(elem, "title", value);
|
||||
setAttrFromValueForKey(elem, "href", value);
|
||||
return setTextFromValueForKey(elem, "text", value);
|
||||
};
|
||||
localizeOptgroupElement = function(elem, key, value) {
|
||||
localizeOptgroupElement = function (elem, key, value) {
|
||||
return elem.attr("label", value);
|
||||
};
|
||||
localizeImageElement = function(elem, key, value) {
|
||||
localizeImageElement = function (elem, key, value) {
|
||||
setAttrFromValueForKey(elem, "alt", value);
|
||||
return setAttrFromValueForKey(elem, "src", value);
|
||||
};
|
||||
valueForKey = function(key, data) {
|
||||
valueForKey = function (key, data) {
|
||||
var keys, value, _i, _len;
|
||||
keys = key.split(/\./);
|
||||
value = data;
|
||||
|
@ -150,37 +184,43 @@ http://keith-wood.name/localisation.html
|
|||
}
|
||||
return value;
|
||||
};
|
||||
setAttrFromValueForKey = function(elem, key, value) {
|
||||
setAttrFromValueForKey = function (elem, key, value) {
|
||||
value = valueForKey(key, value);
|
||||
if (value != null) {
|
||||
return elem.attr(key, value);
|
||||
}
|
||||
};
|
||||
setTextFromValueForKey = function(elem, key, value) {
|
||||
setTextFromValueForKey = function (elem, key, value) {
|
||||
value = valueForKey(key, value);
|
||||
if (value != null) {
|
||||
return elem.text(value);
|
||||
}
|
||||
};
|
||||
regexify = function(string_or_regex_or_array) {
|
||||
regexify = function (string_or_regex_or_array) {
|
||||
var thing;
|
||||
if (typeof string_or_regex_or_array === "string") {
|
||||
return "^" + string_or_regex_or_array + "$";
|
||||
} else if (string_or_regex_or_array.length != null) {
|
||||
return ((function() {
|
||||
return (function () {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = string_or_regex_or_array.length; _i < _len; _i++) {
|
||||
for (
|
||||
_i = 0, _len = string_or_regex_or_array.length;
|
||||
_i < _len;
|
||||
_i++
|
||||
) {
|
||||
thing = string_or_regex_or_array[_i];
|
||||
_results.push(regexify(thing));
|
||||
}
|
||||
return _results;
|
||||
})()).join("|");
|
||||
})().join("|");
|
||||
} else {
|
||||
return string_or_regex_or_array;
|
||||
}
|
||||
};
|
||||
lang = normaliseLang(options.language ? options.language : $.defaultLanguage);
|
||||
lang = normaliseLang(
|
||||
options.language ? options.language : $.defaultLanguage
|
||||
);
|
||||
if (options.skipLanguage && lang.match(regexify(options.skipLanguage))) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
|
@ -190,5 +230,5 @@ http://keith-wood.name/localisation.html
|
|||
return wrappedSet;
|
||||
};
|
||||
$.fn.localize = $.localize;
|
||||
return $.localize.data = {};
|
||||
return ($.localize.data = {});
|
||||
})(jQuery);
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
/*! Localize - v0.2.0 - 2016-10-13
|
||||
* https://github.com/coderifous/jquery-localize
|
||||
* Copyright (c) 2016 coderifous; Licensed MIT */
|
||||
!function(a){var b;return b=function(a){return a=a.replace(/_/,"-").toLowerCase(),a.length>3&&(a=a.substring(0,3)+a.substring(3).toUpperCase()),a},a.defaultLanguage=b(navigator.languages&&navigator.languages.length>0?navigator.languages[0]:navigator.language||navigator.userLanguage),a.localize=function(c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v;return null==d&&(d={}),v=this,h={},g=d.fileExtension||"json",f=a.Deferred(),k=function(a,b,c){var e;switch(null==c&&(c=1),c){case 1:return h={},d.loadBase?(e=a+("."+g),i(e,a,b,c)):k(a,b,2);case 2:return e=""+a+"-"+b.split("-")[0]+"."+g,i(e,a,b,c);case 3:return e=""+a+"-"+b.split("-").slice(0,2).join("-")+"."+g,i(e,a,b,c);default:return f.resolve()}},i=function(b,c,e,f){var g,i,j;return null!=d.pathPrefix&&(b=""+d.pathPrefix+"/"+b),j=function(b){return a.extend(h,b),q(h),k(c,e,f+1)},i=function(){return 2===f&&e.indexOf("-")>-1?k(c,e,f+1):d.fallback&&d.fallback!==e?k(c,d.fallback):void 0},g={url:b,dataType:"json",async:!0,timeout:null!=d.timeout?d.timeout:500,success:j,error:i},"file:"===window.location.protocol&&(g.error=function(b){return j(a.parseJSON(b.responseText))}),a.ajax(g)},q=function(a){return null!=d.callback?d.callback(a,e):e(a)},e=function(b){return a.localize.data[c]=b,v.each(function(){var c,d,e;return c=a(this),d=c.data("localize"),d||(d=c.attr("rel").match(/localize\[(.*?)\]/)[1]),e=u(d,b),null!=e?l(c,d,e):void 0})},l=function(b,c,d){return b.is("input")?o(b,c,d):b.is("textarea")?o(b,c,d):b.is("img")?n(b,c,d):b.is("optgroup")?p(b,c,d):a.isPlainObject(d)||b.html(d),a.isPlainObject(d)?m(b,d):void 0},o=function(b,c,d){var e;return e=a.isPlainObject(d)?d.value:d,b.is("[placeholder]")?b.attr("placeholder",e):b.val(e)},m=function(a,b){return s(a,"title",b),s(a,"href",b),t(a,"text",b)},p=function(a,b,c){return a.attr("label",c)},n=function(a,b,c){return s(a,"alt",c),s(a,"src",c)},u=function(a,b){var c,d,e,f;for(c=a.split(/\./),d=b,e=0,f=c.length;f>e;e++)a=c[e],d=null!=d?d[a]:null;return d},s=function(a,b,c){return c=u(b,c),null!=c?a.attr(b,c):void 0},t=function(a,b,c){return c=u(b,c),null!=c?a.text(c):void 0},r=function(a){var b;return"string"==typeof a?"^"+a+"$":null!=a.length?function(){var c,d,e;for(e=[],c=0,d=a.length;d>c;c++)b=a[c],e.push(r(b));return e}().join("|"):a},j=b(d.language?d.language:a.defaultLanguage),d.skipLanguage&&j.match(r(d.skipLanguage))?f.resolve():k(c,j,1),v.localizePromise=f,v},a.fn.localize=a.localize,a.localize.data={}}(jQuery);
|
12857
lib/showdown.js
12857
lib/showdown.js
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
6
lib/showdown.min.js
vendored
6
lib/showdown.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -7,8 +7,6 @@
|
|||
|
||||
|
||||
<title>Spells - fateforge.tools</title>
|
||||
|
||||
<title>fateforge-tools</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css" />
|
||||
<link href="css/all.min.css" rel="stylesheet" />
|
||||
<link rel="icon" type="image/x-icon" href="/img/FateforgeTool_logo_80.png">
|
||||
|
|
Loading…
Reference in a new issue