diff --git a/static/js/s1/hebrew.js b/static/js/s1/hebrew.js index 3f9960aea5..235deaa482 100644 --- a/static/js/s1/hebrew.js +++ b/static/js/s1/hebrew.js @@ -6,244 +6,16 @@ */ -var GERESH = '\u05F3'; -var GERSHAYIM = '\u05F4'; - function right(string, numChars) { 'use strict'; return string.slice(string.length - numChars); } -function enumerate(list) { - - return list.reduce(function(prevValue, curValue, index) { - prevValue.push([index, curValue]); - return prevValue; - }, []); - -} - -function log10(val) { - return Math.log(val) / Math.LN10; -} - -function sum(list) { - return list.reduce(function(prev, curr) { - return prev + curr; - }, 0); -} - -// Bad idea? -Array.prototype.callOnMyself = function(callback) { - return callback(this, arguments); -}; - -var hebToInt = function(unicodeChar) { - 'use strict'; - - var hebrewNumerals = { - "\u05D0": 1, - "\u05D1": 2, - "\u05D2": 3, - "\u05D3": 4, - "\u05D4": 5, - "\u05D5": 6, - "\u05D6": 7, - "\u05D7": 8, - "\u05D8": 9, - "\u05D9": 10, - "\u05DB": 20, - "\u05DC": 30, - "\u05DE": 40, - "\u05E0": 50, - "\u05E1": 60, - "\u05E2": 70, - "\u05E4": 80, - "\u05E6": 90, - "\u05E7": 100, - "\u05E8": 200, - "\u05E9": 300, - "\u05EA": 400, - - // "\u05f3": "'", // Hebrew geresh - // "\u05F4": '"', // Hebrew gershayim - }; - - if (hebrewNumerals.hasOwnProperty(unicodeChar)) { - return hebrewNumerals[unicodeChar]; - } else { - throw "Invalid Hebrew numeral character " + unicodeChar; - } - -}; - -var splitThousands = function(n, littleEndian) { - // littleEndian defaults to true - if (littleEndian === undefined) { - littleEndian = true; - } - - // Ignore geresh on digit < 10, if present - - if (right(n, 1) === GERESH) { - n = n.slice(0, n.length - 1); - } - - var re = new RegExp(GERESH, "g"); - - var ret = n.replace(re, "'").split("'"); - if (!!littleEndian) { - return ret.reverse(); - } else { - return ret - } - -}; - -var hebStringToInt = function(n) { - - return n.replace(/[\u05F4\"]/g, '').split('') - .map(function(a) {return hebToInt(a); }) - .reduce(function(a, b) { return a + b; }, 0); - -}; - -var decodeHebrewNumeral = function(n) { - - return splitThousands(n).reduce(function(a, b) { - a.push(hebStringToInt(b)); - return a; - }, []) - .callOnMyself(enumerate) - .map(function(a) { return Math.pow(10, 3*a[0]) * a[1]; }) - .reduce(function(prev, curr) { - return prev + curr; - }, 0); - -}; /******* ENCODING *********/ -var chunks = function(l, n) { - var out = []; - for (var i = 0; i < l.length; i+=n) { - out.push(l.slice(i, i + n)) - } - - return out; -}; - -var intToHeb = function(integer) { - - var hebrewNumerals = { - 0: "", - 1: "\u05D0", - 2: "\u05D1", - 3: "\u05D2", - 4: "\u05D3", - 5: "\u05D4", - 6: "\u05D5", - 7: "\u05D6", - 8: "\u05D7", - 9: "\u05D8", - 10: "\u05D9", - 15: "\u05D8\u05D5", // Will not be hit when used with break_int_magnitudes - 16: "\u05D8\u05D6", // Will not be hit when used with break_int_magnitudes - 20: "\u05DB", - 30: "\u05DC", - 40: "\u05DE", - 50: "\u05E0", - 60: "\u05E1", - 70: "\u05E2", - 80: "\u05E4", - 90: "\u05E6", - 100: "\u05E7", - 200: "\u05E8", - 300: "\u05E9", - 400: "\u05EA" - }; - - // Fill in the hebrewNumerals mappings up to 1100 - for (var i = 500; i < 1200; i += 100) { - hebrewNumerals[i] = Array(Math.floor(i / 400) + 1).join(hebrewNumerals[400]) + hebrewNumerals[i % 400]; - } - - if (integer > 1100) { - throw "Asked to convert individual integer " + integer + " above 1100"; - } else if (!(integer in hebrewNumerals)) { - throw "Asked to convert integer " + integer + " that lacks individual Hebrew character"; - } else { - return hebrewNumerals[integer]; - } -}; - -var breakIntMagnitudes = function(n, start) { - - if (start === undefined) { - start = Math.pow(10, Math.floor(log10(n))); - } else if (!(start % 10 === 0 || start === 1)) { - throw "Argument 'start' " + start + " must be 1 or divisible by 10"; - } - - if (start === 1) { - return [n]; - } else { - return [ Math.floor(n / start) * start ].concat( - breakIntMagnitudes(n - Math.floor(n / start) * start, start / 10) - ); - } - -}; - -var sanitize = function(inputString, punctuation) { - - if (punctuation === undefined) { - punctuation = true; - } - - var replacementPairs = [ - [/\u05d9\u05d4/g, '\u05d8\u05d5'], //15 - [/\u05d9\u05d5/g, '\u05d8\u05d6'], //16 - [/\u05e8\u05e2\u05d4/g, '\u05e2\u05e8\u05d4'], //275 - [/\u05e8\u05e2\u05d1/g, '\u05e2\u05e8\u05d1'], //272 - [/\u05e8\u05e2/g, '\u05e2\u05e8'], //270 - ]; - - replacementPairs.forEach(function(pair) { - inputString = inputString.replace(pair[0], pair[1]); - }); - - if (punctuation) { - // add gershayim at the end if longer than one character - if (inputString.length > 1) { - // if a geresh is not one of the last two items in the string - if (right(inputString, 2).indexOf(GERESH) < 0) { - inputString = inputString.substr(0, inputString.length - 1) + GERSHAYIM + right(inputString, 1); - } - } else { - inputString += GERESH; - } - } - - return inputString; - -}; - - -var encodeSmallHebrewNumeral = function(n) { - - if (n >= 1200) { - throw "Tried to encode small numeral " + n + " greater than 1200"; - } else { - return breakIntMagnitudes(n, 100).reduce(function(prev, curr) { - prev.push(tibetanNumeral(curr)); - return prev; - }, []).join(''); - } - -}; var tibetanNumeral = function(num) { if (num < 10) { @@ -282,27 +54,4 @@ function tibetanNumberFromEngNumber(numberAsString) { case "9": return "༩"; } -} - -var encodeHebrewNumeral = function(n, punctuation) { - - var ret; - - if (punctuation === undefined) { - punctuation = true; - } - - if ( n < 1200) { - ret = encodeSmallHebrewNumeral(n); - } else { - ret = chunks(breakIntMagnitudes(n).reverse(), 3) - .callOnMyself(enumerate) - .map(function(a) { return Math.floor(sum(a[1])) * Math.pow(10, -3 * a[0]); }) - .reverse() - .map(function(a) { return encodeSmallHebrewNumeral(a); }) - .join(GERESH); - } - - return sanitize(ret, punctuation); - -}; \ No newline at end of file +} \ No newline at end of file diff --git a/static/js/s1/util.js b/static/js/s1/util.js index 4d36b771b1..def71be535 100644 --- a/static/js/s1/util.js +++ b/static/js/s1/util.js @@ -97,11 +97,11 @@ sjs.cache = { } // Trim the data to "chapter" level - if (data.sections.length == data.sectionNames.length) { + if (data.sections.length === data.sectionNames.length) { ref = ref.replace(/:/g, ".").slice(0, ref.lastIndexOf(".")); data.sections = data.sections.slice(0, data.sections.length - 1); } - if (data.toSections.length == data.sectionNames.length) { + if (data.toSections.length === data.sectionNames.length) { data.toSections = data.toSections.slice(0, data.toSections.length - 1); } @@ -1014,7 +1014,7 @@ sjs.textBrowser = { "དཔེ་ཆ་ཡོངས་རྫོགས།" + ""; for (var i = 0; i < this._path.length; i++) { - var name = sjs.interfaceLang == "he" ? Sefaria.hebrewTerm(this._path[i]) : this._path[i] + var name = sjs.interfaceLang === "he" ? Sefaria.hebrewTerm(this._path[i]) : this._path[i] html += " > " + name + ""; } $("#browserPath").html(html); @@ -1027,7 +1027,7 @@ sjs.textBrowser = { ref = ref.replace(/_/g, " ").replace(/\./g, " "); } var oref = Sefaria.ref(ref); - var displayRef = sjs.interfaceLang == "he" ? (oref ? oref.heRef : " ") : ref; + var displayRef = sjs.interfaceLang === "he" ? (oref ? oref.heRef : " ") : ref; $("#browserMessage").html(displayRef); if (ref) { $("#browserOK").removeClass("disabled"); @@ -1060,7 +1060,7 @@ sjs.textBrowser = { } var html = ""; var longer = data.text.length > data.he.length ? data.text : data.he; - if (longer.length == 0) { + if (longer.length === 0) { html = "
" + "No text available." + "אין טקסט זמין." diff --git a/static/js/sefaria/hebrew.js b/static/js/sefaria/hebrew.js index 12a576e1b2..719a3362b8 100644 --- a/static/js/sefaria/hebrew.js +++ b/static/js/sefaria/hebrew.js @@ -299,7 +299,7 @@ class Hebrew { static dafToInt(daf) { var amud = daf.slice(-1); var i = parseInt(daf.slice(0, -1)) - 1; - i = amud == "a" ? i * 2 : i*2 +1; + i = amud === "a" ? i * 2 : i*2 +1; return i; } @@ -318,66 +318,66 @@ class Hebrew { } Hebrew.hebrewNumerals = { - "\u05D0": 1, - "\u05D1": 2, - "\u05D2": 3, - "\u05D3": 4, - "\u05D4": 5, - "\u05D5": 6, - "\u05D6": 7, - "\u05D7": 8, - "\u05D8": 9, - "\u05D9": 10, - "\u05D8\u05D5": 15, - "\u05D8\u05D6": 16, - "\u05DB": 20, - "\u05DC": 30, - "\u05DE": 40, - "\u05E0": 50, - "\u05E1": 60, - "\u05E2": 70, - "\u05E4": 80, - "\u05E6": 90, - "\u05E7": 100, - "\u05E8": 200, - "\u05E9": 300, - "\u05EA": 400, - "\u05EA\u05E7": 500, - "\u05EA\u05E8": 600, - "\u05EA\u05E9": 700, - "\u05EA\u05EA": 800, - 1: "\u05D0", - 2: "\u05D1", - 3: "\u05D2", - 4: "\u05D3", - 5: "\u05D4", - 6: "\u05D5", - 7: "\u05D6", - 8: "\u05D7", - 9: "\u05D8", - 10: "\u05D9", - 15: "\u05D8\u05D5", - 16: "\u05D8\u05D6", - 20: "\u05DB", - 30: "\u05DC", - 40: "\u05DE", - 50: "\u05E0", - 60: "\u05E1", - 70: "\u05E2", - 80: "\u05E4", - 90: "\u05E6", - 100: "\u05E7", - 200: "\u05E8", - 300: "\u05E9", - 400: "\u05EA", - 500: "\u05EA\u05E7", - 600: "\u05EA\u05E8", - 700: "\u05EA\u05E9", - 800: "\u05EA\u05EA", - 900: "\u05EA\u05EA\u05E7", - 1000: "\u05EA\u05EA\u05E8", - 1100: "\u05EA\u05EA\u05E9", - 1200: "\u05EA\u05EA\u05EA" + "༡": 1, + "༢": 2, + "༣": 3, + "༤": 4, + "༥": 5, + "༦": 6, + "༧": 7, + "༨": 8, + "༩": 9, + "༡༠": 10, + "༡༥": 15, + "༡༦": 16, + "༢༠": 20, + "༣༠": 30, + "༤༠": 40, + "༥༠": 50, + "༦༠": 60, + "༧༠": 70, + "༨༠": 80, + "༩༠": 90, + "༡༠༠": 100, + "༢༠༠": 200, + "༣༠༠": 300, + "༤༠༠": 400, + "༥༠༠": 500, + "༦༠༠": 600, + "༧༠༠": 700, + "༨༠༠": 800, + 1: "༡", + 2: "༢", + 3: "༣", + 4: "༤", + 5: "༥", + 6: "༦", + 7: "༧", + 8: "༨", + 9: "༩", + 10: "༡༠", + 15: "༡༥", + 16: "༡༦", + 20: "༢༠", + 30: "༣༠", + 40: "༤༠", + 50: "༥༠", + 60: "༦༠", + 70: "༧༠", + 80: "༨༠", + 90: "༩༠", + 100: "༡༠༠", + 200: "༢༠༠", + 300: "༣༠༠", + 400: "༤༠༠", + 500: "༥༠༠", + 600: "༦༠༠", + 700: "༧༠༠", + 800: "༨༠༠", + 900: "༩༠༠", + 1000: "༡༠༠༠", + 1100: "༡༡༠༠", + 1200: "༡༢༠༠" }; export default Hebrew; diff --git a/static/js/sefaria/sefaria.js b/static/js/sefaria/sefaria.js index 8f25a4c6b1..93cbaef58b 100644 --- a/static/js/sefaria/sefaria.js +++ b/static/js/sefaria/sefaria.js @@ -892,7 +892,7 @@ Sefaria = extend(Sefaria, { if (data.textDepth === data.sections.length) { return; } - const isSuperSection = data.textDepth == data.sections.length + 2; + const isSuperSection = data.textDepth === data.sections.length + 2; settings = settings || {}; let en = typeof data.text === "string" ? [data.text] : data.text;