diff --git a/unpacked/extensions/MathMenu.js b/unpacked/extensions/MathMenu.js index 5c948f585..ef36bf526 100644 --- a/unpacked/extensions/MathMenu.js +++ b/unpacked/extensions/MathMenu.js @@ -125,15 +125,20 @@ "font-family": (isMSIE ? "'Arial unicode MS'" : null) }, ".MathJax_MenuActive .MathJax_MenuArrow": {color:"white"}, + ".MathJax_MenuArrow.RTL": {left:".5em", right:"auto"}, ".MathJax_MenuCheck": { position:"absolute", left:".7em", "font-family": (isMSIE ? "'Arial unicode MS'" : null) }, + ".MathJax_MenuCheck.RTL": {right:".7em", left:"auto"}, ".MathJax_MenuRadioCheck": { position:"absolute", left: (isPC ? "1em" : ".7em") }, + ".MathJax_MenuRadioCheck.RTL": { + right: (isPC ? "1em" : ".7em"), left:"auto" + }, ".MathJax_MenuLabel": { padding: (isPC ? "2px 2em 4px 1.33em" : "1px 2em 3px 1.33em"), @@ -185,7 +190,7 @@ /* * Display the menu */ - Post: function (event,parent) { + Post: function (event,parent,forceLTR) { if (!event) {event = window.event}; var div = document.getElementById("MathJax_MenuFrame"); if (!div) { @@ -193,13 +198,14 @@ delete ITEM.lastItem; delete ITEM.lastMenu; delete MENU.skipUp; SIGNAL.Post(["post",MENU.jax]); + MENU.isRTL = (MathJax.Localization.fontDirection() === "rtl"); } var menu = HTML.addElement(div,"div",{ onmouseup: MENU.Mouseup, ondblclick: FALSE, ondragstart: FALSE, onselectstart: FALSE, oncontextmenu: FALSE, menuItem: this, className: "MathJax_Menu" }); - MathJax.Localization.setCSS(menu); + if (!forceLTR) {MathJax.Localization.setCSS(menu)} for (var i = 0, m = this.items.length; i < m; i++) {this.items[i].Create(menu)} if (MENU.isMobile) { @@ -228,8 +234,11 @@ x += parent.offsetLeft; y += parent.offsetTop; parent = parent.parentNode; } - if (x + menu.offsetWidth > document.body.offsetWidth - this.margin && !MENU.isMobile) - {side = "right"; x = Math.max(this.margin,x - mw - menu.offsetWidth + 6)} + if (!MENU.isMobile) { + if ((MENU.isRTL && x - mw - menu.offsetWidth > this.margin) || + (!MENU.isRTL && x + menu.offsetWidth > document.body.offsetWidth - this.margin)) + {side = "right"; x = Math.max(this.margin,x - mw - menu.offsetWidth + 6)} + } if (!isPC) { // in case these ever get implemented menu.style["borderRadiusTop"+side] = 0; // Opera 10.5 @@ -438,7 +447,10 @@ Activate: function (menu) {this.Deactivate(menu); menu.className += " MathJax_MenuActive"}, Deactivate: function (menu) {menu.className = menu.className.replace(/ MathJax_MenuActive/,"")}, - With: function (def) {if (def) {HUB.Insert(this,def)}; return this} + With: function (def) {if (def) {HUB.Insert(this,def)}; return this}, + + isRTL: function () {return MENU.isRTL}, + rtlClass: function () {return (this.isRTL() ? " RTL" : "")} }); /*************************************************************/ @@ -472,6 +484,7 @@ MENU.ITEM.SUBMENU = MENU.ITEM.Subclass({ menu: null, // the submenu marker: (isPC && !HUB.Browser.isSafari ? "\u25B6" : "\u25B8"), // the menu arrow + markerRTL: (isPC && !HUB.Browser.isSafari ? "\u25B0" : "\u25C2"), Init: function (name,def) { if (!(name instanceof Array)) {name = [name,name]} // make [id,label] pair @@ -481,7 +494,9 @@ }, Label: function (def,menu) { this.menu.posted = false; - return [this.Name()+" ",["span",{className:"MathJax_MenuArrow"},[this.marker]]]; + return [this.Name()+" ",["span",{ + className:"MathJax_MenuArrow" + this.rtlClass() + },[this.isRTL() ? this.markerRTL : this.marker]]]; }, Timer: function (event,menu) { if (this.timer) {clearTimeout(this.timer)} @@ -498,7 +513,7 @@ if (!this.disabled) { if (!this.menu.posted) { if (this.timer) {clearTimeout(this.timer); delete this.timer} - this.menu.Post(event,menu); + this.menu.Post(event,menu,this.ltr); } else { var menus = document.getElementById("MathJax_MenuFrame").childNodes, m = menus.length-1; @@ -529,7 +544,7 @@ if (this.value == null) {this.value = this.name[0]} }, Label: function (def,menu) { - var span = {className:"MathJax_MenuRadioCheck"}; + var span = {className:"MathJax_MenuRadioCheck" + this.rtlClass()}; if (CONFIG.settings[this.variable] !== this.value) {span = {style:{display:"none"}}} return [["span",span,[this.marker]]," "+this.Name()]; }, @@ -565,7 +580,7 @@ this.name = name; this.variable = variable; this.With(def); }, Label: function (def,menu) { - var span = {className:"MathJax_MenuCheck"}; + var span = {className:"MathJax_MenuCheck" + this.rtlClass()}; if (!CONFIG.settings[this.variable]) {span = {style:{display:"none"}}} return [["span",span,[this.marker]]," "+this.Name()]; }, @@ -1107,7 +1122,7 @@ ITEM.RULE().With({hidden:!CONFIG.showDiscoverable, name:["","discover_rule"]}), ITEM.CHECKBOX(["Discoverable","Highlight on Hover"], "discoverable", {hidden:!CONFIG.showDiscoverable}) ), - ITEM.SUBMENU(["Locale","Language"], {hidden:!CONFIG.showLocale}, + ITEM.SUBMENU(["Locale","Language"], {hidden:!CONFIG.showLocale, ltr:true}, ITEM.RADIO("en", "locale", {action: MENU.Locale}), ITEM.RULE().With({hidden:!CONFIG.showLocaleURL, name:["","localURL_rule"]}), ITEM.COMMAND(["LoadLocale","Load from URL ..."], MENU.LoadLocale, {hidden:!CONFIG.showLocaleURL})