123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461 |
- // Edit extension, https://github.com/datenstrom/yellow-extensions/tree/master/features/edit
- // Copyright (c) 2013-2020 Datenstrom, https://datenstrom.se
- // This file may be used and distributed under the terms of the public license.
- var yellow = {
- onLoad: function() { yellow.edit.load(); },
- onKeydown: function(e) { yellow.edit.keydown(e); },
- onDrag: function(e) { yellow.edit.drag(e); },
- onDrop: function(e) { yellow.edit.drop(e); },
- onClick: function(e) { yellow.edit.click(e); },
- onClickAction: function(e) { yellow.edit.clickAction(e); },
- onUpdatePane: function() { yellow.edit.updatePane(yellow.edit.paneId, yellow.edit.paneAction, yellow.edit.paneStatus); },
- onResizePane: function() { yellow.edit.resizePane(yellow.edit.paneId, yellow.edit.paneAction, yellow.edit.paneStatus); },
- action: function(action, status, args) { yellow.edit.processAction(action, status, args); }
- };
- yellow.edit = {
- paneId: 0, //visible pane ID
- paneAction: 0, //current pane action
- paneStatus: 0, //current pane status
- popupId: 0, //visible popup ID
- intervalId: 0, //timer interval ID
- // Handle initialisation
- load: function() {
- var body = document.getElementsByTagName("body")[0];
- if (body && body.firstChild && !document.getElementById("yellow-bar")) {
- this.createBar("yellow-bar");
- this.processAction(yellow.page.action, yellow.page.status);
- clearInterval(this.intervalId);
- }
- },
-
- // Handle keyboard
- keydown: function(e) {
- if (this.paneId=="yellow-pane-create" || this.paneId=="yellow-pane-edit" || this.paneId=="yellow-pane-delete") this.processShortcut(e);
- if (this.paneId && e.keyCode==27) this.hidePane(this.paneId);
- },
-
- // Handle drag
- drag: function(e) {
- e.stopPropagation();
- e.preventDefault();
- },
-
- // Handle drop
- drop: function(e) {
- e.stopPropagation();
- e.preventDefault();
- var elementText = document.getElementById(this.paneId+"-text");
- var files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
- for (var i=0; i<files.length; i++) this.uploadFile(elementText, files[i]);
- },
-
- // Handle mouse clicked
- click: function(e) {
- if (this.popupId && !document.getElementById(this.popupId).contains(e.target)) this.hidePopup(this.popupId, true);
- if (this.paneId && !document.getElementById(this.paneId).contains(e.target)) this.hidePane(this.paneId, true);
- },
-
- // Handle action clicked
- clickAction: function(e) {
- e.stopPropagation();
- e.preventDefault();
- var element = e.target;
- for (; element; element=element.parentNode) {
- if (element.tagName=="A") break;
- }
- this.processAction(element.getAttribute("data-action"), element.getAttribute("data-status"), element.getAttribute("data-args"));
- },
-
- // Create bar
- createBar: function(barId) {
- var elementBar = document.createElement("div");
- elementBar.className = "yellow-bar";
- elementBar.setAttribute("id", barId);
- if (barId=="yellow-bar") {
- yellow.toolbox.addEvent(document, "click", yellow.onClick);
- yellow.toolbox.addEvent(document, "keydown", yellow.onKeydown);
- yellow.toolbox.addEvent(window, "resize", yellow.onResizePane);
- }
- var elementDiv = document.createElement("div");
- elementDiv.setAttribute("id", barId+"-content");
- if (yellow.system.userName) {
- elementDiv.innerHTML =
- "<div class=\"yellow-bar-left\">"+
- "<a href=\"#\" id=\"yellow-pane-edit-bar\" data-action=\"edit\" aria-expanded=\"false\">"+this.getText("Edit")+"</a>"+
- "</div>"+
- "<div class=\"yellow-bar-right\">"+
- "<a href=\"#\" id=\"yellow-pane-create-bar\" data-action=\"create\" aria-expanded=\"false\">"+this.getText("Create")+"</a>"+
- "<a href=\"#\" id=\"yellow-pane-delete-bar\" data-action=\"delete\" aria-expanded=\"false\">"+this.getText("Delete")+"</a>"+
- "<a href=\"#\" id=\"yellow-pane-menu-bar\" data-action=\"menu\" aria-expanded=\"false\">"+yellow.toolbox.encodeHtml(yellow.system.userName)+"</a>"+
- "</div>"+
- "<div class=\"yellow-bar-banner\"></div>";
- }
- elementBar.appendChild(elementDiv);
- yellow.toolbox.insertBefore(elementBar, document.getElementsByTagName("body")[0].firstChild);
- this.bindActions(elementBar);
- },
-
- // Update bar
- updateBar: function(paneId, name) {
- if (paneId) {
- var element = document.getElementById(paneId+"-bar");
- if (element) {
- if (name.indexOf("selected")!=-1) element.setAttribute("aria-expanded", "true");
- yellow.toolbox.addClass(element, name);
- }
- } else {
- var elements = document.getElementsByClassName(name);
- for (var i=0, l=elements.length; i<l; i++) {
- if (name.indexOf("selected")!=-1) elements[i].setAttribute("aria-expanded", "false");
- yellow.toolbox.removeClass(elements[i], name);
- }
- }
- },
-
- // Create pane
- createPane: function(paneId, paneAction, paneStatus) {
- if (yellow.system.debug) console.log("yellow.edit.createPane id:"+paneId);
- var elementPane = document.createElement("div");
- elementPane.className = "yellow-pane";
- elementPane.setAttribute("id", paneId);
- elementPane.style.display = "none";
- if (paneId=="yellow-pane-create" || paneId=="yellow-pane-edit") {
- yellow.toolbox.addEvent(elementPane, "input", yellow.onUpdatePane);
- yellow.toolbox.addEvent(elementPane, "dragenter", yellow.onDrag);
- yellow.toolbox.addEvent(elementPane, "dragover", yellow.onDrag);
- yellow.toolbox.addEvent(elementPane, "drop", yellow.onDrop);
- }
- if (paneId=="yellow-pane-create" || paneId=="yellow-pane-edit" || paneId=="yellow-pane-delete" || paneId=="yellow-pane-menu") {
- var elementArrow = document.createElement("span");
- elementArrow.className = "yellow-arrow";
- elementArrow.setAttribute("id", paneId+"-arrow");
- elementPane.appendChild(elementArrow);
- }
- var elementDiv = document.createElement("div");
- elementDiv.className = "yellow-content";
- elementDiv.setAttribute("id", paneId+"-content");
- switch (paneId) {
- case "yellow-pane-login":
- elementDiv.innerHTML =
- "<form method=\"post\">"+
- "<a href=\"#\" class=\"yellow-close\" data-action=\"close\"><i class=\"yellow-icon yellow-icon-close\"></i></a>"+
- "<div class=\"yellow-title\"><h1>"+this.getText("LoginTitle")+"</h1></div>"+
- "<div class=\"yellow-fields\">"+
- "<input type=\"hidden\" name=\"action\" value=\"login\" />"+
- "<p><label for=\"yellow-pane-login-email\">"+this.getText("LoginEmail")+"</label><br /><input class=\"yellow-form-control\" name=\"email\" id=\"yellow-pane-login-email\" maxlength=\"64\" value=\""+yellow.toolbox.encodeHtml(yellow.system.editLoginEmail)+"\" /></p>"+
- "<p><label for=\"yellow-pane-login-password\">"+this.getText("LoginPassword")+"</label><br /><input class=\"yellow-form-control\" type=\"password\" name=\"password\" id=\"yellow-pane-login-password\" maxlength=\"64\" value=\""+yellow.toolbox.encodeHtml(yellow.system.editLoginPassword)+"\" /></p>"+
- "<p><input class=\"yellow-btn\" type=\"submit\" value=\""+this.getText("LoginButton")+"\" /></p>"+
- "<p><a href=\"#\" id=\"yellow-pane-login-forgot\" class=\"yellow-center\" data-action=\"forgot\">"+this.getText("LoginForgot")+"</a><br /><a href=\"#\" id=\"yellow-pane-login-signup\" class=\"yellow-center\" data-action=\"signup\">"+this.getText("LoginSignup")+"</a></p>"+
- "</div>"+
- "</form>";
- break;
- case "yellow-pane-signup":
- elementDiv.innerHTML =
- "<form method=\"post\">"+
- "<a href=\"#\" class=\"yellow-close\" data-action=\"close\"><i class=\"yellow-icon yellow-icon-close\"></i></a>"+
- "<div class=\"yellow-title\"><h1>"+this.getText("SignupTitle")+"</h1></div>"+
- "<div class=\"yellow-status\"><p id=\"yellow-pane-signup-status\" class=\""+paneStatus+"\">"+this.getText("SignupStatus", "", paneStatus)+"</p></div>"+
- "<div class=\"yellow-fields\">"+
- "<input type=\"hidden\" name=\"action\" value=\"signup\" />"+
- "<p><label for=\"yellow-pane-signup-name\">"+this.getText("SignupName")+"</label><br /><input class=\"yellow-form-control\" name=\"name\" id=\"yellow-pane-signup-name\" maxlength=\"64\" value=\""+yellow.toolbox.encodeHtml(this.getRequest("name"))+"\" /></p>"+
- "<p><label for=\"yellow-pane-signup-email\">"+this.getText("SignupEmail")+"</label><br /><input class=\"yellow-form-control\" name=\"email\" id=\"yellow-pane-signup-email\" maxlength=\"64\" value=\""+yellow.toolbox.encodeHtml(this.getRequest("email"))+"\" /></p>"+
- "<p><label for=\"yellow-pane-signup-password\">"+this.getText("SignupPassword")+"</label><br /><input class=\"yellow-form-control\" type=\"password\" name=\"password\" id=\"yellow-pane-signup-password\" maxlength=\"64\" value=\"\" /></p>"+
- "<p><input type=\"checkbox\" name=\"consent\" value=\"consent\" id=\"yellow-pane-signup-consent\""+(this.getRequest("consent") ? " checked=\"checked\"" : "")+"> <label for=\"yellow-pane-signup-consent\">"+this.getText("SignupConsent")+"</label></p>"+
- "<p><input class=\"yellow-btn\" type=\"submit\" value=\""+this.getText("SignupButton")+"\" /></p>"+
- "</div>"+
- "</form>";
- break;
- case "yellow-pane-forgot":
- elementDiv.innerHTML =
- "<form method=\"post\">"+
- "<a href=\"#\" class=\"yellow-close\" data-action=\"close\"><i class=\"yellow-icon yellow-icon-close\"></i></a>"+
- "<div class=\"yellow-title\"><h1>"+this.getText("ForgotTitle")+"</h1></div>"+
- "<div class=\"yellow-status\"><p id=\"yellow-pane-forgot-status\" class=\""+paneStatus+"\">"+this.getText("ForgotStatus", "", paneStatus)+"</p></div>"+
- "<div class=\"yellow-fields\">"+
- "<input type=\"hidden\" name=\"action\" value=\"forgot\" />"+
- "<p><label for=\"yellow-pane-forgot-email\">"+this.getText("ForgotEmail")+"</label><br /><input class=\"yellow-form-control\" name=\"email\" id=\"yellow-pane-forgot-email\" maxlength=\"64\" value=\""+yellow.toolbox.encodeHtml(this.getRequest("email"))+"\" /></p>"+
- "<p><input class=\"yellow-btn\" type=\"submit\" value=\""+this.getText("OkButton")+"\" /></p>"+
- "</div>"+
- "</form>";
- break;
- case "yellow-pane-recover":
- elementDiv.innerHTML =
- "<form method=\"post\">"+
- "<a href=\"#\" class=\"yellow-close\" data-action=\"close\"><i class=\"yellow-icon yellow-icon-close\"></i></a>"+
- "<div class=\"yellow-title\"><h1>"+this.getText("RecoverTitle")+"</h1></div>"+
- "<div class=\"yellow-status\"><p id=\"yellow-pane-recover-status\" class=\""+paneStatus+"\">"+this.getText("RecoverStatus", "", paneStatus)+"</p></div>"+
- "<div class=\"yellow-fields\">"+
- "<p><label for=\"yellow-pane-recover-password\">"+this.getText("RecoverPassword")+"</label><br /><input class=\"yellow-form-control\" type=\"password\" name=\"password\" id=\"yellow-pane-recover-password\" maxlength=\"64\" value=\"\" /></p>"+
- "<p><input class=\"yellow-btn\" type=\"submit\" value=\""+this.getText("OkButton")+"\" /></p>"+
- "</div>"+
- "</form>";
- break;
- case "yellow-pane-quit":
- elementDiv.innerHTML =
- "<form method=\"post\">"+
- "<a href=\"#\" class=\"yellow-close\" data-action=\"close\"><i class=\"yellow-icon yellow-icon-close\"></i></a>"+
- "<div class=\"yellow-title\"><h1>"+this.getText("QuitTitle")+"</h1></div>"+
- "<div class=\"yellow-status\"><p id=\"yellow-pane-quit-status\" class=\""+paneStatus+"\">"+this.getText("QuitStatus", "", paneStatus)+"</p></div>"+
- "<div class=\"yellow-fields\">"+
- "<input type=\"hidden\" name=\"action\" value=\"quit\" />"+
- "<input type=\"hidden\" name=\"csrftoken\" value=\""+yellow.toolbox.encodeHtml(this.getCookie("csrftoken"))+"\" />"+
- "<p><label for=\"yellow-pane-quit-name\">"+this.getText("SignupName")+"</label><br /><input class=\"yellow-form-control\" name=\"name\" id=\"yellow-pane-quit-name\" maxlength=\"64\" value=\""+yellow.toolbox.encodeHtml(this.getRequest("name"))+"\" /></p>"+
- "<p><input class=\"yellow-btn\" type=\"submit\" value=\""+this.getText("DeleteButton")+"\" /></p>"+
- "</div>"+
- "</form>";
- break;
- case "yellow-pane-account":
- elementDiv.innerHTML =
- "<form method=\"post\">"+
- "<a href=\"#\" class=\"yellow-close\" data-action=\"close\"><i class=\"yellow-icon yellow-icon-close\"></i></a>"+
- "<div class=\"yellow-title\"><h1 id=\"yellow-pane-account-title\">"+this.getText("AccountTitle")+"</h1></div>"+
- "<div class=\"yellow-status\"><p id=\"yellow-pane-account-status\" class=\""+paneStatus+"\">"+this.getText("AccountStatus", "", paneStatus)+"</p></div>"+
- "<div class=\"yellow-settings\">"+
- "<div id=\"yellow-pane-account-settings-actions\" class=\"yellow-settings-left\"><p>"+this.getRawDataActions(paneAction)+"</p></div>"+
- "<div id=\"yellow-pane-account-settings-separator\" class=\"yellow-settings-left yellow-settings-separator\"> </div>"+
- "<div id=\"yellow-pane-account-settings-fields\" class=\"yellow-settings-right yellow-fields\">"+
- "<input type=\"hidden\" name=\"action\" value=\"account\" />"+
- "<input type=\"hidden\" name=\"csrftoken\" value=\""+yellow.toolbox.encodeHtml(this.getCookie("csrftoken"))+"\" />"+
- "<p><label for=\"yellow-pane-account-name\">"+this.getText("SignupName")+"</label><br /><input class=\"yellow-form-control\" name=\"name\" id=\"yellow-pane-account-name\" maxlength=\"64\" value=\""+yellow.toolbox.encodeHtml(this.getRequest("name"))+"\" /></p>"+
- "<p><label for=\"yellow-pane-account-email\">"+this.getText("SignupEmail")+"</label><br /><input class=\"yellow-form-control\" name=\"email\" id=\"yellow-pane-account-email\" maxlength=\"64\" value=\""+yellow.toolbox.encodeHtml(this.getRequest("email"))+"\" /></p>"+
- "<p><label for=\"yellow-pane-account-password\">"+this.getText("SignupPassword")+"</label><br /><input class=\"yellow-form-control\" type=\"password\" name=\"password\" id=\"yellow-pane-account-password\" maxlength=\"64\" value=\"\" /></p>"+
- "<p>"+this.getRawDataLanguages(paneId)+"</p>"+
- "<p>"+this.getText("AccountInformation")+" <a href=\"#\" data-action=\"quit\">"+this.getText("AccountMore")+"</a></p>"+
- "<p><input class=\"yellow-btn\" type=\"submit\" value=\""+this.getText("ChangeButton")+"\" /></p>"+
- "</div>"+
- "<div class=\"yellow-settings yellow-settings-banner\"></div>"+
- "</div>"+
- "</form>";
- break;
- case "yellow-pane-system":
- elementDiv.innerHTML =
- "<form method=\"post\">"+
- "<a href=\"#\" class=\"yellow-close\" data-action=\"close\"><i class=\"yellow-icon yellow-icon-close\"></i></a>"+
- "<div class=\"yellow-title\"><h1 id=\"yellow-pane-system-title\">"+this.getText("SystemTitle")+"</h1></div>"+
- "<div class=\"yellow-status\"><p id=\"yellow-pane-system-status\" class=\""+paneStatus+"\">"+this.getText("SystemStatus", "", paneStatus)+"</p></div>"+
- "<div class=\"yellow-settings\">"+
- "<div id=\"yellow-pane-system-settings-actions\" class=\"yellow-settings-left\"><p>"+this.getRawDataActions(paneAction)+"</p></div>"+
- "<div id=\"yellow-pane-system-settings-separator\" class=\"yellow-settings-left yellow-settings-separator\"> </div>"+
- "<div id=\"yellow-pane-system-settings-fields\" class=\"yellow-settings-right yellow-fields\">"+
- "<input type=\"hidden\" name=\"action\" value=\"system\" />"+
- "<input type=\"hidden\" name=\"csrftoken\" value=\""+yellow.toolbox.encodeHtml(this.getCookie("csrftoken"))+"\" />"+
- "<p><label for=\"yellow-pane-system-sitename\">"+this.getText("SystemSitename")+"</label><br /><input class=\"yellow-form-control\" name=\"sitename\" id=\"yellow-pane-system-sitename\" maxlength=\"64\" value=\""+yellow.toolbox.encodeHtml(this.getRequest("sitename"))+"\" /></p>"+
- "<p><label for=\"yellow-pane-system-author\">"+this.getText("SystemAuthor")+"</label><br /><input class=\"yellow-form-control\" name=\"author\" id=\"yellow-pane-system-author\" maxlength=\"64\" value=\""+yellow.toolbox.encodeHtml(this.getRequest("author"))+"\" /></p>"+
- "<p><label for=\"yellow-pane-system-email\">"+this.getText("SystemEmail")+"</label><br /><input class=\"yellow-form-control\" name=\"email\" id=\"yellow-pane-system-email\" maxlength=\"64\" value=\""+yellow.toolbox.encodeHtml(this.getRequest("email"))+"\" /></p>"+
- "<p>"+this.getText("SystemInformation")+"</p>"+
- "<p><input class=\"yellow-btn\" type=\"submit\" value=\""+this.getText("ChangeButton")+"\" /></p>"+
- "</div>"+
- "<div class=\"yellow-settings yellow-settings-banner\"></div>"+
- "</div>"+
- "</form>";
- break;
- case "yellow-pane-update":
- elementDiv.innerHTML =
- "<form method=\"post\">"+
- "<a href=\"#\" class=\"yellow-close\" data-action=\"close\"><i class=\"yellow-icon yellow-icon-close\"></i></a>"+
- "<div class=\"yellow-title\"><h1 id=\"yellow-pane-update-title\">"+yellow.toolbox.encodeHtml(yellow.system.coreVersion)+"</h1></div>"+
- "<div class=\"yellow-status\"><p id=\"yellow-pane-update-status\" class=\""+paneStatus+"\">"+this.getText("UpdateStatus", "", paneStatus)+"</p></div>"+
- "<div class=\"yellow-output\" id=\"yellow-pane-update-output\">"+yellow.page.rawDataOutput+"</div>"+
- "<div class=\"yellow-buttons\" id=\"yellow-pane-update-buttons\">"+
- "<p><a href=\"#\" class=\"yellow-btn\" data-action=\"close\">"+this.getText("OkButton")+"</a></p>"+
- "</div>"+
- "</form>";
- break;
- case "yellow-pane-create":
- elementDiv.innerHTML =
- "<form method=\"post\">"+
- "<div id=\"yellow-pane-create-toolbar\">"+
- "<div class=\"yellow-toolbar yellow-toolbar-left\"><h1 id=\"yellow-pane-create-toolbar-title\">"+this.getText("Create")+"</h1></div>"+
- "<ul id=\"yellow-pane-create-toolbar-buttons\" class=\"yellow-toolbar yellow-toolbar-left\">"+this.getRawDataButtons(paneId)+"</ul>"+
- "<ul id=\"yellow-pane-create-toolbar-main\" class=\"yellow-toolbar yellow-toolbar-right\">"+
- "<li><a href=\"#\" id=\"yellow-pane-create-cancel\" class=\"yellow-toolbar-btn\" data-action=\"close\">"+this.getText("CancelButton")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-pane-create-submit\" class=\"yellow-toolbar-btn\" data-action=\"submit\">"+this.getText("CreateButton")+"</a></li>"+
- "</ul>"+
- "<ul class=\"yellow-toolbar yellow-toolbar-banner\"></ul>"+
- "</div>"+
- "<textarea id=\"yellow-pane-create-text\" class=\"yellow-edit-text\"></textarea>"+
- "<div id=\"yellow-pane-create-preview\" class=\"yellow-edit-preview\"></div>"+
- "</form>";
- break;
- case "yellow-pane-edit":
- elementDiv.innerHTML =
- "<form method=\"post\">"+
- "<div id=\"yellow-pane-edit-toolbar\">"+
- "<div class=\"yellow-toolbar yellow-toolbar-left\"><h1 id=\"yellow-pane-edit-toolbar-title\">"+this.getText("Edit")+"</h1></div>"+
- "<ul id=\"yellow-pane-edit-toolbar-buttons\" class=\"yellow-toolbar yellow-toolbar-left\">"+this.getRawDataButtons(paneId)+"</ul>"+
- "<ul id=\"yellow-pane-edit-toolbar-main\" class=\"yellow-toolbar yellow-toolbar-right\">"+
- "<li><a href=\"#\" id=\"yellow-pane-edit-cancel\" class=\"yellow-toolbar-btn\" data-action=\"close\">"+this.getText("CancelButton")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-pane-edit-submit\" class=\"yellow-toolbar-btn\" data-action=\"submit\">"+this.getText("EditButton")+"</a></li>"+
- "</ul>"+
- "<ul class=\"yellow-toolbar yellow-toolbar-banner\"></ul>"+
- "</div>"+
- "<textarea id=\"yellow-pane-edit-text\" class=\"yellow-edit-text\"></textarea>"+
- "<div id=\"yellow-pane-edit-preview\" class=\"yellow-edit-preview\"></div>"+
- "</form>";
- break;
- case "yellow-pane-delete":
- elementDiv.innerHTML =
- "<form method=\"post\">"+
- "<div id=\"yellow-pane-delete-toolbar\">"+
- "<div class=\"yellow-toolbar yellow-toolbar-left\"><h1 id=\"yellow-pane-delete-toolbar-title\">"+this.getText("Delete")+"</h1></div>"+
- "<ul id=\"yellow-pane-delete-toolbar-buttons\" class=\"yellow-toolbar yellow-toolbar-left\">"+this.getRawDataButtons(paneId)+"</ul>"+
- "<ul id=\"yellow-pane-delete-toolbar-main\" class=\"yellow-toolbar yellow-toolbar-right\">"+
- "<li><a href=\"#\" id=\"yellow-pane-delete-cancel\" class=\"yellow-toolbar-btn\" data-action=\"close\">"+this.getText("CancelButton")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-pane-delete-submit\" class=\"yellow-toolbar-btn\" data-action=\"submit\">"+this.getText("DeleteButton")+"</a></li>"+
- "</ul>"+
- "<ul class=\"yellow-toolbar yellow-toolbar-banner\"></ul>"+
- "</div>"+
- "<textarea id=\"yellow-pane-delete-text\" class=\"yellow-edit-text\"></textarea>"+
- "<div id=\"yellow-pane-delete-preview\" class=\"yellow-edit-preview\"></div>"+
- "</form>";
- break;
- case "yellow-pane-menu":
- elementDiv.innerHTML =
- "<ul class=\"yellow-dropdown\">"+
- "<li><span>"+yellow.toolbox.encodeHtml(yellow.system.userEmail)+"</span></li>"+
- "<li><a href=\"#\" data-action=\"settings\">"+this.getText("MenuSettings")+"</a></li>" +
- "<li><a href=\"#\" data-action=\"help\">"+this.getText("MenuHelp")+"</a></li>" +
- "<li><a href=\"#\" data-action=\"submit\" data-args=\"action:logout\">"+this.getText("MenuLogout")+"</a></li>"+
- "</ul>";
- break;
- case "yellow-pane-information":
- elementDiv.innerHTML =
- "<form method=\"post\">"+
- "<a href=\"#\" class=\"yellow-close\" data-action=\"close\"><i class=\"yellow-icon yellow-icon-close\"></i></a>"+
- "<div class=\"yellow-title\"><h1 id=\"yellow-pane-information-title\">"+this.getText(paneAction+"Title")+"</h1></div>"+
- "<div class=\"yellow-status\"><p id=\"yellow-pane-information-status\" class=\""+paneStatus+"\">"+this.getText(paneAction+"Status", "", paneStatus)+"</p></div>"+
- "<div class=\"yellow-buttons\" id=\"yellow-pane-information-buttons\">"+
- "<p><a href=\"#\" class=\"yellow-btn\" data-action=\"close\">"+this.getText("OkButton")+"</a></p>"+
- "</div>"+
- "</form>";
- break;
- default: elementDiv.innerHTML =
- "<a href=\"#\" class=\"yellow-close\" data-action=\"close\"><i class=\"yellow-icon yellow-icon-close\"></i></a>"+
- "<div class=\"yellow-error\">Pane '"+paneId+"' was not found. Oh no...</div>";
- }
- elementPane.appendChild(elementDiv);
- yellow.toolbox.insertAfter(elementPane, document.getElementsByTagName("body")[0].firstChild);
- this.bindActions(elementPane);
- },
- // Update pane
- updatePane: function(paneId, paneAction, paneStatus, paneInit) {
- switch (paneId) {
- case "yellow-pane-login":
- if (paneInit && yellow.system.editLoginRestriction) {
- yellow.toolbox.setVisible(document.getElementById("yellow-pane-login-signup"), false);
- }
- break;
- case "yellow-pane-quit":
- if (paneStatus=="none") {
- document.getElementById("yellow-pane-quit-status").innerHTML = this.getText("QuitStatusNone");
- document.getElementById("yellow-pane-quit-name").value = "";
- }
- break;
- case "yellow-pane-account":
- if (paneInit && yellow.system.editSettingsActions=="none") {
- document.getElementById("yellow-pane-account-title").innerHTML = this.getText("MenuSettings");
- }
- if (paneStatus=="none") {
- document.getElementById("yellow-pane-account-status").innerHTML = this.getText("AccountStatusNone");
- document.getElementById("yellow-pane-account-name").value = yellow.system.userName;
- document.getElementById("yellow-pane-account-email").value = yellow.system.userEmail;
- document.getElementById("yellow-pane-account-password").value = "";
- document.getElementById("yellow-pane-account-"+yellow.system.userLanguage).checked = true;
- }
- break;
- case "yellow-pane-system":
- if (paneStatus=="none") {
- document.getElementById("yellow-pane-system-status").innerHTML = this.getText("SystemStatusNone");
- document.getElementById("yellow-pane-system-sitename").value = yellow.system.sitename;
- document.getElementById("yellow-pane-system-author").value = yellow.system.author;
- document.getElementById("yellow-pane-system-email").value = yellow.system.email;
- }
- break;
- case "yellow-pane-update":
- if (paneStatus=="none") {
- document.getElementById("yellow-pane-update-status").innerHTML = this.getText("UpdateStatusCheck");
- document.getElementById("yellow-pane-update-output").innerHTML = "";
- setTimeout("yellow.action('submit', '', 'action:update/option:check/');", 500);
- }
- if (paneStatus=="updates") {
- document.getElementById("yellow-pane-update-status").innerHTML = "<a href=\"#\" data-action=\"submit\" data-args=\"action:update\">"+this.getText("UpdateStatusUpdates")+"</a>";
- }
- break;
- case "yellow-pane-create":
- case "yellow-pane-edit":
- case "yellow-pane-delete":
- document.getElementById(paneId+"-text").focus();
- if (paneInit) {
- yellow.toolbox.setVisible(document.getElementById(paneId+"-text"), true);
- yellow.toolbox.setVisible(document.getElementById(paneId+"-preview"), false);
- document.getElementById(paneId+"-toolbar-title").innerHTML = yellow.toolbox.encodeHtml(yellow.page.title);
- document.getElementById(paneId+"-text").value = paneId=="yellow-pane-create" ? yellow.page.rawDataNew : yellow.page.rawDataEdit;
- var matches = document.getElementById(paneId+"-text").value.match(/^(\xEF\xBB\xBF)?\-\-\-[\r\n]+/);
- var position = document.getElementById(paneId+"-text").value.indexOf("\n", matches ? matches[0].length : 0);
- document.getElementById(paneId+"-text").setSelectionRange(position, position);
- if (yellow.system.editToolbarButtons!="none") {
- yellow.toolbox.setVisible(document.getElementById(paneId+"-toolbar-title"), false);
- this.updateToolbar(0, "yellow-toolbar-checked");
- }
- if (!this.isUserAccess(paneAction, yellow.page.location) || (yellow.page.rawDataReadonly && paneId!="yellow-pane-create")) {
- yellow.toolbox.setVisible(document.getElementById(paneId+"-submit"), false);
- document.getElementById(paneId+"-text").readOnly = true;
- }
- }
- if (!document.getElementById(paneId+"-text").readOnly) {
- paneAction = this.paneAction = this.getPaneAction(paneId);
- var className = "yellow-toolbar-btn yellow-toolbar-btn-"+paneAction;
- if (document.getElementById(paneId+"-submit").className != className) {
- document.getElementById(paneId+"-submit").className = className;
- document.getElementById(paneId+"-submit").innerHTML = this.getText(paneAction+"Button");
- document.getElementById(paneId+"-submit").setAttribute("data-args", "action:"+paneAction);
- this.resizePane(paneId, paneAction, paneStatus);
- }
- }
- break;
- }
- this.bindActions(document.getElementById(paneId));
- },
- // Resize pane
- resizePane: function(paneId, paneAction, paneStatus) {
- var elementBar = document.getElementById("yellow-bar-content");
- var paneLeft = yellow.toolbox.getOuterLeft(elementBar);
- var paneTop = yellow.toolbox.getOuterTop(elementBar) + yellow.toolbox.getOuterHeight(elementBar) + 10;
- var paneWidth = yellow.toolbox.getOuterWidth(elementBar);
- var paneHeight = yellow.toolbox.getWindowHeight() - paneTop - Math.min(yellow.toolbox.getOuterHeight(elementBar) + 10, (yellow.toolbox.getWindowWidth()-yellow.toolbox.getOuterWidth(elementBar))/2);
- switch (paneId) {
- case "yellow-pane-account":
- case "yellow-pane-system":
- yellow.toolbox.setOuterLeft(document.getElementById(paneId), paneLeft);
- yellow.toolbox.setOuterTop(document.getElementById(paneId), paneTop);
- yellow.toolbox.setOuterWidth(document.getElementById(paneId), paneWidth);
- var elementWidth = yellow.toolbox.getWidth(document.getElementById(paneId));
- var actionsWidth = yellow.toolbox.getOuterWidth(document.getElementById(paneId+"-settings-actions"));
- var fieldsWidth = yellow.toolbox.getOuterWidth(document.getElementById(paneId+"-settings-fields"));
- var separatorWidth = Math.max(10, ((elementWidth-fieldsWidth)/2)-actionsWidth);
- yellow.toolbox.setOuterWidth(document.getElementById(paneId+"-settings-separator"), separatorWidth);
- break;
- case "yellow-pane-create":
- case "yellow-pane-edit":
- case "yellow-pane-delete":
- yellow.toolbox.setOuterLeft(document.getElementById(paneId), paneLeft);
- yellow.toolbox.setOuterTop(document.getElementById(paneId), paneTop);
- yellow.toolbox.setOuterHeight(document.getElementById(paneId), paneHeight);
- yellow.toolbox.setOuterWidth(document.getElementById(paneId), paneWidth);
- var elementWidth = yellow.toolbox.getWidth(document.getElementById(paneId));
- yellow.toolbox.setOuterWidth(document.getElementById(paneId+"-text"), elementWidth);
- yellow.toolbox.setOuterWidth(document.getElementById(paneId+"-preview"), elementWidth);
- var buttonsWidth = 0;
- var buttonsWidthMax = yellow.toolbox.getOuterWidth(document.getElementById(paneId+"-toolbar")) -
- yellow.toolbox.getOuterWidth(document.getElementById(paneId+"-toolbar-main")) - 1;
- var element = document.getElementById(paneId+"-toolbar-buttons").firstChild;
- for (; element; element=element.nextSibling) {
- element.removeAttribute("style");
- buttonsWidth += yellow.toolbox.getOuterWidth(element);
- if (buttonsWidth>buttonsWidthMax) yellow.toolbox.setVisible(element, false);
- }
- yellow.toolbox.setOuterWidth(document.getElementById(paneId+"-toolbar-title"), buttonsWidthMax);
- var height1 = yellow.toolbox.getHeight(document.getElementById(paneId));
- var height2 = yellow.toolbox.getOuterHeight(document.getElementById(paneId+"-toolbar"));
- yellow.toolbox.setOuterHeight(document.getElementById(paneId+"-text"), height1 - height2);
- yellow.toolbox.setOuterHeight(document.getElementById(paneId+"-preview"), height1 - height2);
- var elementLink = document.getElementById(paneId+"-bar");
- var position = yellow.toolbox.getOuterLeft(elementLink) + yellow.toolbox.getOuterWidth(elementLink)/2;
- position -= yellow.toolbox.getOuterLeft(document.getElementById(paneId)) + 1;
- yellow.toolbox.setOuterLeft(document.getElementById(paneId+"-arrow"), position);
- break;
- case "yellow-pane-menu":
- yellow.toolbox.setOuterLeft(document.getElementById("yellow-pane-menu"), paneLeft + paneWidth - yellow.toolbox.getOuterWidth(document.getElementById("yellow-pane-menu")));
- yellow.toolbox.setOuterTop(document.getElementById("yellow-pane-menu"), paneTop);
- var elementLink = document.getElementById("yellow-pane-menu-bar");
- var position = yellow.toolbox.getOuterLeft(elementLink) + yellow.toolbox.getOuterWidth(elementLink)/2;
- position -= yellow.toolbox.getOuterLeft(document.getElementById("yellow-pane-menu"));
- yellow.toolbox.setOuterLeft(document.getElementById("yellow-pane-menu-arrow"), position);
- break;
- default:
- yellow.toolbox.setOuterLeft(document.getElementById(paneId), paneLeft);
- yellow.toolbox.setOuterTop(document.getElementById(paneId), paneTop);
- yellow.toolbox.setOuterWidth(document.getElementById(paneId), paneWidth);
- break;
- }
- },
-
- // Show or hide pane
- showPane: function(paneId, paneAction, paneStatus, paneModal) {
- if (this.paneId!=paneId || this.paneAction!=paneAction) {
- this.hidePane(this.paneId);
- var paneInit = !document.getElementById(paneId);
- if (!document.getElementById(paneId)) this.createPane(paneId, paneAction, paneStatus);
- var element = document.getElementById(paneId);
- if (!yellow.toolbox.isVisible(element)) {
- if (yellow.system.debug) console.log("yellow.edit.showPane id:"+paneId);
- yellow.toolbox.setVisible(element, true);
- if (paneModal) {
- yellow.toolbox.addClass(document.body, "yellow-body-modal-open");
- yellow.toolbox.addValue("meta[name=viewport]", "content", ", maximum-scale=1, user-scalable=0");
- }
- this.paneId = paneId;
- this.paneAction = paneAction;
- this.paneStatus = paneStatus;
- this.updatePane(paneId, paneAction, paneStatus, paneInit);
- this.resizePane(paneId, paneAction, paneStatus);
- this.updateBar(paneId, "yellow-bar-selected");
- }
- } else {
- this.hidePane(this.paneId, true);
- }
- },
- // Hide pane
- hidePane: function(paneId, fadeout) {
- var element = document.getElementById(paneId);
- if (yellow.toolbox.isVisible(element)) {
- if (yellow.system.debug) console.log("yellow.edit.hidePane id:"+paneId);
- yellow.toolbox.removeClass(document.body, "yellow-body-modal-open");
- yellow.toolbox.removeValue("meta[name=viewport]", "content", ", maximum-scale=1, user-scalable=0");
- yellow.toolbox.setVisible(element, false, fadeout);
- this.paneId = 0;
- this.paneAction = 0;
- this.paneStatus = 0;
- this.updateBar(0, "yellow-bar-selected");
- }
- this.hidePopup(this.popupId);
- },
-
- // Process action
- processAction: function(action, status, args) {
- action = action ? action : "none";
- status = status ? status : "none";
- args = args ? args : "none";
- if (action!="none") {
- if (yellow.system.debug) console.log("yellow.edit.processAction action:"+action+" status:"+status);
- var paneId = (status!="next" && status!="done") ? "yellow-pane-"+action : "yellow-pane-information";
- switch(action) {
- case "login": this.showPane(paneId, action, status); break;
- case "signup": this.showPane(paneId, action, status); break;
- case "confirm": this.showPane(paneId, action, status); break;
- case "approve": this.showPane(paneId, action, status); break;
- case "forgot": this.showPane(paneId, action, status); break;
- case "recover": this.showPane(paneId, action, status); break;
- case "reactivate": this.showPane(paneId, action, status); break;
- case "verify": this.showPane(paneId, action, status); break;
- case "change": this.showPane(paneId, action, status); break;
- case "quit": this.showPane(paneId, action, status); break;
- case "remove": this.showPane(paneId, action, status); break;
- case "account": this.showPane(paneId, action, status); break;
- case "system": this.showPane(paneId, action, status); break;
- case "update": this.showPane(paneId, action, status); break;
- case "create": this.showPane(paneId, action, status, true); break;
- case "edit": this.showPane(paneId, action, status, true); break;
- case "delete": this.showPane(paneId, action, status, true); break;
- case "menu": this.showPane(paneId, action, status); break;
- case "close": this.hidePane(this.paneId); break;
- case "toolbar": this.processToolbar(status, args); break;
- case "settings": this.processSettings(args); break;
- case "submit": this.processSubmit(args); break;
- case "help": this.processHelp(); break;
- }
- }
- },
-
- // Process toolbar
- processToolbar: function(status, args) {
- if (yellow.system.debug) console.log("yellow.edit.processToolbar status:"+status);
- var elementText = document.getElementById(this.paneId+"-text");
- var elementPreview = document.getElementById(this.paneId+"-preview");
- if (!yellow.toolbox.isVisible(elementPreview) && !elementText.readOnly) {
- switch (status) {
- case "h1": yellow.editor.setMarkdown(elementText, "# ", "insert-multiline-block", true); break;
- case "h2": yellow.editor.setMarkdown(elementText, "## ", "insert-multiline-block", true); break;
- case "h3": yellow.editor.setMarkdown(elementText, "### ", "insert-multiline-block", true); break;
- case "paragraph": yellow.editor.setMarkdown(elementText, "", "remove-multiline-block");
- yellow.editor.setMarkdown(elementText, "", "remove-fenced-block"); break;
- case "notice": yellow.editor.setMarkdown(elementText, "! ", "insert-multiline-block", true); break;
- case "quote": yellow.editor.setMarkdown(elementText, "> ", "insert-multiline-block", true); break;
- case "pre": yellow.editor.setMarkdown(elementText, "```\n", "insert-fenced-block", true); break;
- case "bold": yellow.editor.setMarkdown(elementText, "**", "insert-inline", true); break;
- case "italic": yellow.editor.setMarkdown(elementText, "*", "insert-inline", true); break;
- case "strikethrough": yellow.editor.setMarkdown(elementText, "~~", "insert-inline", true); break;
- case "code": yellow.editor.setMarkdown(elementText, "`", "insert-autodetect", true); break;
- case "ul": yellow.editor.setMarkdown(elementText, "* ", "insert-multiline-block", true); break;
- case "ol": yellow.editor.setMarkdown(elementText, "1. ", "insert-multiline-block", true); break;
- case "tl": yellow.editor.setMarkdown(elementText, "- [ ] ", "insert-multiline-block", true); break;
- case "link": yellow.editor.setMarkdown(elementText, "[link](url)", "insert", false, yellow.editor.getMarkdownLink); break;
- case "text": yellow.editor.setMarkdown(elementText, args, "insert"); break;
- case "draft": yellow.editor.setMetaData(elementText, "status", "draft", true); break;
- case "file": this.showFileDialog(); break;
- case "undo": yellow.editor.undo(); break;
- case "redo": yellow.editor.redo(); break;
- }
- }
- if (status=="preview" && !elementText.readOnly) this.showPreview(elementText, elementPreview);
- if (status=="save" && !elementText.readOnly && this.paneAction!="delete") this.processSubmit("action:"+this.paneAction);
- if (status=="help") window.open(this.getText("HelpUrl", "yellow"), "_blank");
- if (status=="markdown") window.open(this.getText("MarkdownUrl", "yellow"), "_blank");
- if (this.isExpandable(status)) {
- this.showPopup("yellow-popup-"+status, status);
- } else {
- this.hidePopup(this.popupId);
- }
- },
-
- // Update toolbar
- updateToolbar: function(status, name) {
- if (status) {
- var element = document.getElementById(this.paneId+"-toolbar-"+status);
- if (element) {
- if (name.indexOf("selected")!=-1) element.setAttribute("aria-expanded", "true");
- yellow.toolbox.addClass(element, name);
- }
- } else {
- var elements = document.getElementsByClassName(name);
- for (var i=0, l=elements.length; i<l; i++) {
- if (name.indexOf("selected")!=-1) elements[i].setAttribute("aria-expanded", "false");
- yellow.toolbox.removeClass(elements[i], name);
- }
- }
- },
-
- // Process shortcut
- processShortcut: function(e) {
- var shortcut = yellow.toolbox.getEventShortcut(e);
- if (shortcut) {
- var tokens = yellow.system.editKeyboardShortcuts.split(/\s*,\s*/);
- for (var i=0; i<tokens.length; i++) {
- var pair = tokens[i].split(" ");
- if (shortcut==pair[0] || shortcut.replace("meta+", "ctrl+")==pair[0]) {
- if (yellow.system.debug) console.log("yellow.edit.processShortcut shortcut:"+shortcut);
- e.stopPropagation();
- e.preventDefault();
- this.processToolbar(pair[1]);
- }
- }
- }
- },
-
- // Process settings
- processSettings: function(args) {
- var action = args!="none" ? args : "account";
- if (action!=this.paneAction && action!="settings") this.processAction(action);
- },
-
- // Process submit
- processSubmit: function(args) {
- var settings = { "action":"none", "csrftoken":this.getCookie("csrftoken") };
- var tokens = args.split("/");
- for (var i=0; i<tokens.length; i++) {
- var pair = tokens[i].split(/[:=]/);
- if (!pair[0] || !pair[1]) continue;
- settings[pair[0]] = pair[1];
- }
- if (settings["action"]=="create" || settings["action"]=="edit" || settings["action"]=="delete") {
- settings.rawdatasource = yellow.page.rawDataSource;
- settings.rawdataedit = document.getElementById(this.paneId+"-text").value;
- settings.rawdataendofline = yellow.page.rawDataEndOfLine;
- }
- if (settings["action"]!="none") yellow.toolbox.submitForm(settings);
- },
-
- // Process help
- processHelp: function() {
- this.hidePane(this.paneId);
- window.open(this.getText("HelpUrl", "yellow"), "_self");
- },
-
- // Create popup
- createPopup: function(popupId) {
- if (yellow.system.debug) console.log("yellow.edit.createPopup id:"+popupId);
- var elementPopup = document.createElement("div");
- elementPopup.className = "yellow-popup";
- elementPopup.setAttribute("id", popupId);
- elementPopup.style.display = "none";
- var elementDiv = document.createElement("div");
- elementDiv.setAttribute("id", popupId+"-content");
- switch (popupId) {
- case "yellow-popup-format":
- elementDiv.innerHTML =
- "<ul class=\"yellow-dropdown yellow-dropdown-menu\">"+
- "<li><a href=\"#\" id=\"yellow-popup-format-h1\" data-action=\"toolbar\" data-status=\"h1\">"+this.getText("ToolbarH1")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-popup-format-h2\" data-action=\"toolbar\" data-status=\"h2\">"+this.getText("ToolbarH2")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-popup-format-h3\" data-action=\"toolbar\" data-status=\"h3\">"+this.getText("ToolbarH3")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-popup-format-paragraph\" data-action=\"toolbar\" data-status=\"paragraph\">"+this.getText("ToolbarParagraph")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-popup-format-pre\" data-action=\"toolbar\" data-status=\"pre\">"+this.getText("ToolbarPre")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-popup-format-notice\" data-action=\"toolbar\" data-status=\"notice\">"+this.getText("ToolbarNotice")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-popup-format-quote\" data-action=\"toolbar\" data-status=\"quote\">"+this.getText("ToolbarQuote")+"</a></li>"+
- "</ul>";
- break;
- case "yellow-popup-heading":
- elementDiv.innerHTML =
- "<ul class=\"yellow-dropdown yellow-dropdown-menu\">"+
- "<li><a href=\"#\" id=\"yellow-popup-heading-h1\" data-action=\"toolbar\" data-status=\"h1\">"+this.getText("ToolbarH1")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-popup-heading-h2\" data-action=\"toolbar\" data-status=\"h2\">"+this.getText("ToolbarH2")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-popup-heading-h3\" data-action=\"toolbar\" data-status=\"h3\">"+this.getText("ToolbarH3")+"</a></li>"+
- "</ul>";
- break;
- case "yellow-popup-list":
- elementDiv.innerHTML =
- "<ul class=\"yellow-dropdown yellow-dropdown-menu\">"+
- "<li><a href=\"#\" id=\"yellow-popup-list-ul\" data-action=\"toolbar\" data-status=\"ul\">"+this.getText("ToolbarUl")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-popup-list-ol\" data-action=\"toolbar\" data-status=\"ol\">"+this.getText("ToolbarOl")+"</a></li>"+
- "<li><a href=\"#\" id=\"yellow-popup-list-tl\" data-action=\"toolbar\" data-status=\"tl\">"+this.getText("ToolbarTl")+"</a></li>"+
- "</ul>";
- break;
- case "yellow-popup-emojiawesome":
- var rawDataEmojis = "";
- if (yellow.system.emojiawesomeToolbarButtons && yellow.system.emojiawesomeToolbarButtons!="none") {
- var tokens = yellow.system.emojiawesomeToolbarButtons.split(" ");
- for (var i=0; i<tokens.length; i++) {
- var token = tokens[i].replace(/[\:]/g,"");
- var className = token.replace("+1", "plus1").replace("-1", "minus1").replace(/_/g, "-");
- rawDataEmojis += "<li><a href=\"#\" id=\"yellow-popup-list-"+yellow.toolbox.encodeHtml(token)+"\" data-action=\"toolbar\" data-status=\"text\" data-args=\":"+yellow.toolbox.encodeHtml(token)+":\"><i class=\"ea ea-"+yellow.toolbox.encodeHtml(className)+"\"></i></a></li>";
- }
- }
- elementDiv.innerHTML = "<ul class=\"yellow-dropdown yellow-dropdown-menu\">"+rawDataEmojis+"</ul>";
- break;
- case "yellow-popup-fontawesome":
- var rawDataIcons = "";
- if (yellow.system.fontawesomeToolbarButtons && yellow.system.fontawesomeToolbarButtons!="none") {
- var tokens = yellow.system.fontawesomeToolbarButtons.split(" ");
- for (var i=0; i<tokens.length; i++) {
- var token = tokens[i].replace(/[\:]/g,"");
- rawDataIcons += "<li><a href=\"#\" id=\"yellow-popup-list-"+yellow.toolbox.encodeHtml(token)+"\" data-action=\"toolbar\" data-status=\"text\" data-args=\":"+yellow.toolbox.encodeHtml(token)+":\"><i class=\"fa "+yellow.toolbox.encodeHtml(token)+"\"></i></a></li>";
- }
- }
- elementDiv.innerHTML = "<ul class=\"yellow-dropdown yellow-dropdown-menu\">"+rawDataIcons+"</ul>";
- break;
- }
- elementPopup.appendChild(elementDiv);
- yellow.toolbox.insertAfter(elementPopup, document.getElementsByTagName("body")[0].firstChild);
- this.bindActions(elementPopup);
- },
-
- // Show or hide popup
- showPopup: function(popupId, status) {
- if (this.popupId!=popupId) {
- this.hidePopup(this.popupId);
- if (!document.getElementById(popupId)) this.createPopup(popupId);
- var element = document.getElementById(popupId);
- if (yellow.system.debug) console.log("yellow.edit.showPopup id:"+popupId);
- yellow.toolbox.setVisible(element, true);
- this.popupId = popupId;
- this.updateToolbar(status, "yellow-toolbar-selected");
- var elementParent = document.getElementById(this.paneId+"-toolbar-"+status);
- var popupLeft = yellow.toolbox.getOuterLeft(elementParent);
- var popupTop = yellow.toolbox.getOuterTop(elementParent) + yellow.toolbox.getOuterHeight(elementParent) - 1;
- yellow.toolbox.setOuterLeft(document.getElementById(popupId), popupLeft);
- yellow.toolbox.setOuterTop(document.getElementById(popupId), popupTop);
- } else {
- this.hidePopup(this.popupId, true);
- }
- },
-
- // Hide popup
- hidePopup: function(popupId, fadeout) {
- var element = document.getElementById(popupId);
- if (yellow.toolbox.isVisible(element)) {
- if (yellow.system.debug) console.log("yellow.edit.hidePopup id:"+popupId);
- yellow.toolbox.setVisible(element, false, fadeout);
- this.popupId = 0;
- this.updateToolbar(0, "yellow-toolbar-selected");
- }
- },
-
- // Show or hide preview
- showPreview: function(elementText, elementPreview) {
- if (!yellow.toolbox.isVisible(elementPreview)) {
- var thisObject = this;
- var formData = new FormData();
- formData.append("action", "preview");
- formData.append("csrftoken", this.getCookie("csrftoken"));
- formData.append("rawdataedit", elementText.value);
- formData.append("rawdataendofline", yellow.page.rawDataEndOfLine);
- var request = new XMLHttpRequest();
- request.open("POST", window.location.pathname, true);
- request.onload = function() { if (this.status==200) thisObject.showPreviewDone.call(thisObject, elementText, elementPreview, this.responseText); };
- request.send(formData);
- } else {
- this.showPreviewDone(elementText, elementPreview, "");
- }
- },
-
- // Preview done
- showPreviewDone: function(elementText, elementPreview, responseText) {
- var showPreview = responseText.length!=0;
- yellow.toolbox.setVisible(elementText, !showPreview);
- yellow.toolbox.setVisible(elementPreview, showPreview);
- if (showPreview) {
- this.updateToolbar("preview", "yellow-toolbar-checked");
- elementPreview.innerHTML = responseText;
- dispatchEvent(new Event("load"));
- } else {
- this.updateToolbar(0, "yellow-toolbar-checked");
- elementText.focus();
- }
- },
-
- // Show file dialog and trigger upload
- showFileDialog: function() {
- var element = document.createElement("input");
- element.setAttribute("id", "yellow-file-dialog");
- element.setAttribute("type", "file");
- element.setAttribute("accept", yellow.system.editUploadExtensions);
- element.setAttribute("multiple", "multiple");
- yellow.toolbox.addEvent(element, "change", yellow.onDrop);
- element.click();
- },
-
- // Upload file
- uploadFile: function(elementText, file) {
- var extension = (file.name.lastIndexOf(".")!=-1 ? file.name.substring(file.name.lastIndexOf("."), file.name.length) : "").toLowerCase();
- var extensions = yellow.system.editUploadExtensions.split(/\s*,\s*/);
- if (file.size<=yellow.system.coreFileSizeMax && extensions.indexOf(extension)!=-1) {
- var text = this.getText("UploadProgress")+"\u200b";
- yellow.editor.setMarkdown(elementText, text, "insert");
- var thisObject = this;
- var formData = new FormData();
- formData.append("action", "upload");
- formData.append("csrftoken", this.getCookie("csrftoken"));
- formData.append("file", file);
- var request = new XMLHttpRequest();
- request.open("POST", window.location.pathname, true);
- request.onload = function() { if (this.status==200) { thisObject.uploadFileDone.call(thisObject, elementText, this.responseText); } else { thisObject.uploadFileError.call(thisObject, elementText, this.responseText); } };
- request.send(formData);
- } else {
- var textError = extensions.indexOf(extension)!=-1 ? "file too big!" : "file format not supported!";
- var textNew = "[Can't upload file '"+file.name+"', "+textError+"]";
- yellow.editor.setMarkdown(elementText, textNew, "insert");
- }
- },
-
- // Upload done
- uploadFileDone: function(elementText, responseText) {
- var result = JSON.parse(responseText);
- if (result) {
- var textOld = this.getText("UploadProgress")+"\u200b";
- var textNew;
- if (result.location.substring(0, yellow.system.coreImageLocation.length)==yellow.system.coreImageLocation) {
- textNew = "[image "+result.location.substring(yellow.system.coreImageLocation.length)+"]";
- } else {
- textNew = "[link]("+result.location+")";
- }
- yellow.editor.replace(elementText, textOld, textNew);
- }
- },
-
- // Upload error
- uploadFileError: function(elementText, responseText) {
- var result = JSON.parse(responseText);
- if (result) {
- var textOld = this.getText("UploadProgress")+"\u200b";
- var textNew = "["+result.error+"]";
- yellow.editor.replace(elementText, textOld, textNew);
- }
- },
- // Bind actions to links
- bindActions: function(element) {
- var elements = element.getElementsByTagName("a");
- for (var i=0, l=elements.length; i<l; i++) {
- if (elements[i].getAttribute("data-action")) elements[i].onclick = yellow.onClickAction;
- if (elements[i].getAttribute("data-action")=="toolbar") elements[i].onmousedown = function(e) { e.preventDefault(); };
- }
- },
-
- // Return pane action
- getPaneAction: function(paneId) {
- var panePrefix = "yellow-pane-";
- var paneAction = paneId.substring(panePrefix.length);
- if (paneAction=="edit") {
- if (document.getElementById("yellow-pane-edit-text").value.length==0) paneAction = "delete";
- if (yellow.page.statusCode==434) paneAction = "create";
- }
- return paneAction;
- },
-
- // Return raw data for actions
- getRawDataActions: function(paneAction) {
- var rawDataActions = "";
- if (yellow.system.editSettingsActions && yellow.system.editSettingsActions!="none") {
- var tokens = yellow.system.editSettingsActions.split(/\s*,\s*/);
- for (var i=0; i<tokens.length; i++) {
- var token = tokens[i];
- rawDataActions += "<a href=\"#\""+(token==paneAction ? "class=\"active\"": "")+" data-action=\"settings\" data-args=\""+yellow.toolbox.encodeHtml(token)+"\">"+this.getText(token+"Title")+"</a><br />";
- }
- }
- return rawDataActions;
- },
-
- // Return raw data for languages
- getRawDataLanguages: function(paneId) {
- var rawDataLanguages = "";
- if (yellow.system.coreLanguages && Object.keys(yellow.system.coreLanguages).length>1) {
- for (var language in yellow.system.coreLanguages) {
- var checked = language==this.getRequest("language") ? " checked=\"checked\"" : "";
- rawDataLanguages += "<label for=\""+paneId+"-"+language+"\"><input type=\"radio\" name=\"language\" id=\""+paneId+"-"+language+"\" value=\""+language+"\""+checked+"> "+yellow.toolbox.encodeHtml(yellow.system.coreLanguages[language])+"</label><br />";
- }
- }
- return rawDataLanguages
- },
-
- // Return raw data for buttons
- getRawDataButtons: function(paneId) {
- var rawDataButtons = "";
- if (yellow.system.editToolbarButtons && yellow.system.editToolbarButtons!="none") {
- var tokens = yellow.system.editToolbarButtons.split(/\s*,\s*/);
- for (var i=0; i<tokens.length; i++) {
- var token = tokens[i];
- if (token!="separator") {
- var shortcut = this.getShortcut(token);
- var rawDataShortcut = shortcut ? " "+yellow.toolbox.encodeHtml(shortcut) : "";
- var rawDataExpandable = this.isExpandable(token) ? " aria-expanded=\"false\"" : "";
- rawDataButtons += "<li><a href=\"#\" id=\""+paneId+"-toolbar-"+yellow.toolbox.encodeHtml(token)+"\" class=\"yellow-toolbar-btn-icon yellow-toolbar-tooltip\" data-action=\"toolbar\" data-status=\""+yellow.toolbox.encodeHtml(token)+"\" aria-label=\""+this.getText("Toolbar", "", token)+rawDataShortcut+"\""+rawDataExpandable+"><i class=\"yellow-icon yellow-icon-"+yellow.toolbox.encodeHtml(token)+"\"></i></a></li>";
- } else {
- rawDataButtons += "<li><a href=\"#\" class=\"yellow-toolbar-btn-separator\"></a></li>";
- }
- }
- }
- return rawDataButtons;
- },
-
- // Return request string
- getRequest: function(key, prefix) {
- if (!prefix) prefix = "request";
- key = prefix + yellow.toolbox.toUpperFirst(key);
- return (key in yellow.page) ? yellow.page[key] : "";
- },
-
- // Return shortcut string
- getShortcut: function(key) {
- var shortcut = "";
- var tokens = yellow.system.editKeyboardShortcuts.split(/\s*,\s*/);
- for (var i=0; i<tokens.length; i++) {
- var pair = tokens[i].split(" ");
- if (key==pair[1]) {
- shortcut = pair[0];
- break;
- }
- }
- var labels = yellow.text.editKeyboardLabels.split(/\s*,\s*/);
- if (navigator.platform.indexOf("Mac")==-1) {
- shortcut = shortcut.toUpperCase().replace("CTRL+", labels[0]).replace("ALT+", labels[1]).replace("SHIFT+", labels[2]);
- } else {
- shortcut = shortcut.toUpperCase().replace("CTRL+ALT+", "ALT+CTRL+").replace("CTRL+SHIFT+", "SHIFT+CTRL+");
- shortcut = shortcut.replace("CTRL+", labels[3]).replace("ALT+", labels[4]).replace("SHIFT+", labels[5]);
- }
- return shortcut;
- },
- // Return text string
- getText: function(key, prefix, postfix) {
- if (!prefix) prefix = "edit";
- if (!postfix) postfix = "";
- key = prefix + yellow.toolbox.toUpperFirst(key) + yellow.toolbox.toUpperFirst(postfix);
- return (key in yellow.text) ? yellow.text[key] : "["+key+"]";
- },
- // Return cookie string
- getCookie: function(name) {
- return yellow.toolbox.getCookie(name);
- },
-
- // Check if user with access
- isUserAccess: function(action, location) {
- var tokens = yellow.system.userAccess.split(/\s*,\s*/);
- return tokens.indexOf(action)!=-1 && (!location || location.substring(0, yellow.system.userHome.length)==yellow.system.userHome);
- },
- // Check if element is expandable
- isExpandable: function(name) {
- return (name=="format" || name=="heading" || name=="list" || name=="emojiawesome" || name=="fontawesome");
- },
-
- // Check if extension exists
- isExtension: function(name) {
- return name in yellow.system.coreExtensions;
- }
- };
- yellow.editor = {
- // Set Markdown formatting
- setMarkdown: function(element, prefix, type, toggle, callback) {
- var information = this.getMarkdownInformation(element, prefix, type);
- var selectionStart = (information.type.indexOf("block")!=-1) ? information.top : information.start;
- var selectionEnd = (information.type.indexOf("block")!=-1) ? information.bottom : information.end;
- if (information.found && toggle) information.type = information.type.replace("insert", "remove");
- if (information.type=="remove-fenced-block" || information.type=="remove-inline") {
- selectionStart -= information.prefix.length; selectionEnd += information.prefix.length;
- }
- var text = information.text;
- var textSelectionBefore = text.substring(0, selectionStart);
- var textSelection = text.substring(selectionStart, selectionEnd);
- var textSelectionAfter = text.substring(selectionEnd, text.length);
- var textSelectionNew, selectionStartNew, selectionEndNew;
- switch (information.type) {
- case "insert-multiline-block":
- textSelectionNew = this.getMarkdownMultilineBlock(textSelection, information);
- selectionStartNew = information.start + this.getMarkdownDifference(textSelection, textSelectionNew, true);
- selectionEndNew = information.end + this.getMarkdownDifference(textSelection, textSelectionNew);
- if (information.start==information.top && information.start!=information.end) selectionStartNew = information.top;
- if (information.end==information.top && information.start!=information.end) selectionEndNew = information.top;
- break;
- case "remove-multiline-block":
- textSelectionNew = this.getMarkdownMultilineBlock(textSelection, information);
- selectionStartNew = information.start + this.getMarkdownDifference(textSelection, textSelectionNew, true);
- selectionEndNew = information.end + this.getMarkdownDifference(textSelection, textSelectionNew);
- if (selectionStartNew<=information.top) selectionStartNew = information.top;
- if (selectionEndNew<=information.top) selectionEndNew = information.top;
- break;
- case "insert-fenced-block":
- textSelectionNew = this.getMarkdownFencedBlock(textSelection, information);
- selectionStartNew = information.start + information.prefix.length;
- selectionEndNew = information.end + this.getMarkdownDifference(textSelection, textSelectionNew) - information.prefix.length;
- break;
- case "remove-fenced-block":
- textSelectionNew = this.getMarkdownFencedBlock(textSelection, information);
- selectionStartNew = information.start - information.prefix.length;
- selectionEndNew = information.end + this.getMarkdownDifference(textSelection, textSelectionNew) + information.prefix.length;
- break;
- case "insert-inline":
- textSelectionNew = information.prefix + textSelection + information.prefix;
- selectionStartNew = information.start + information.prefix.length;
- selectionEndNew = information.end + information.prefix.length;
- break;
- case "remove-inline":
- textSelectionNew = text.substring(information.start, information.end);
- selectionStartNew = information.start - information.prefix.length;
- selectionEndNew = information.end - information.prefix.length;
- break;
- case "insert":
- textSelectionNew = callback ? callback(textSelection, information) : information.prefix;
- selectionStartNew = information.start + textSelectionNew.length;
- selectionEndNew = selectionStartNew;
- }
- if (textSelection!=textSelectionNew || selectionStart!=selectionStartNew || selectionEnd!=selectionEndNew) {
- element.focus();
- element.setSelectionRange(selectionStart, selectionEnd);
- document.execCommand("insertText", false, textSelectionNew);
- element.value = textSelectionBefore + textSelectionNew + textSelectionAfter;
- element.setSelectionRange(selectionStartNew, selectionEndNew);
- }
- if (yellow.system.debug) console.log("yellow.editor.setMarkdown type:"+information.type);
- },
-
- // Return Markdown formatting information
- getMarkdownInformation: function(element, prefix, type) {
- var text = element.value;
- var start = element.selectionStart;
- var end = element.selectionEnd;
- var top = start, bottom = end;
- while (text.charAt(top-1)!="\n" && top>0) top--;
- if (bottom==top && bottom<text.length) bottom++;
- while (text.charAt(bottom-1)!="\n" && bottom<text.length) bottom++;
- if (type=="insert-autodetect") {
- if (text.substring(start, end).indexOf("\n")!=-1) {
- type = "insert-fenced-block"; prefix = "```\n";
- } else {
- type = "insert-inline"; prefix = "`";
- }
- }
- var found = false;
- if (type.indexOf("multiline-block")!=-1) {
- if (text.substring(top, top+prefix.length)==prefix) found = true;
- } else if (type.indexOf("fenced-block")!=-1) {
- if (text.substring(top-prefix.length, top)==prefix && text.substring(bottom, bottom+prefix.length)==prefix) {
- found = true;
- }
- } else {
- if (text.substring(start-prefix.length, start)==prefix && text.substring(end, end+prefix.length)==prefix) {
- if (prefix=="*") {
- var lettersBefore = 0, lettersAfter = 0;
- for (var index=start-1; text.charAt(index)=="*"; index--) lettersBefore++;
- for (var index=end; text.charAt(index)=="*"; index++) lettersAfter++;
- found = lettersBefore!=2 && lettersAfter!=2;
- } else {
- found = true;
- }
- }
- }
- return { "text":text, "prefix":prefix, "type":type, "start":start, "end":end, "top":top, "bottom":bottom, "found":found };
- },
-
- // Return Markdown length difference
- getMarkdownDifference: function(textSelection, textSelectionNew, firstTextLine) {
- var textSelectionLength, textSelectionLengthNew;
- if (firstTextLine) {
- var position = textSelection.indexOf("\n");
- var positionNew = textSelectionNew.indexOf("\n");
- textSelectionLength = position!=-1 ? position+1 : textSelection.length+1;
- textSelectionLengthNew = positionNew!=-1 ? positionNew+1 : textSelectionNew.length+1;
- } else {
- var position = textSelection.indexOf("\n");
- var positionNew = textSelectionNew.indexOf("\n");
- textSelectionLength = position!=-1 ? textSelection.length : textSelection.length+1;
- textSelectionLengthNew = positionNew!=-1 ? textSelectionNew.length : textSelectionNew.length+1;
- }
- return textSelectionLengthNew - textSelectionLength;
- },
-
- // Return Markdown for multiline block
- getMarkdownMultilineBlock: function(textSelection, information) {
- var textSelectionNew = "";
- var lines = yellow.toolbox.getTextLines(textSelection);
- for (var i=0; i<lines.length; i++) {
- var matches = lines[i].match(/^(\s*[\#\*\-\!\>\s]+)?(\s+\[.\]|\s*\d+\.)?[ \t]+/);
- if (matches) {
- textSelectionNew += lines[i].substring(matches[0].length);
- } else {
- textSelectionNew += lines[i];
- }
- }
- textSelection = textSelectionNew;
- if (information.type.indexOf("remove")==-1) {
- textSelectionNew = "";
- var linePrefix = information.prefix;
- lines = yellow.toolbox.getTextLines(textSelection.length!=0 ? textSelection : "\n");
- for (var i=0; i<lines.length; i++) {
- textSelectionNew += linePrefix+lines[i];
- if (information.prefix=="1. ") {
- var matches = linePrefix.match(/^(\d+)\.\s/);
- if (matches) linePrefix = (parseInt(matches[1])+1)+". ";
- }
- }
- textSelection = textSelectionNew;
- }
- return textSelection;
- },
-
- // Return Markdown for fenced block
- getMarkdownFencedBlock: function(textSelection, information) {
- var textSelectionNew = "";
- var lines = yellow.toolbox.getTextLines(textSelection);
- for (var i=0; i<lines.length; i++) {
- var matches = lines[i].match(/^```/);
- if (!matches) textSelectionNew += lines[i];
- }
- textSelection = textSelectionNew;
- if (information.type.indexOf("remove")==-1) {
- if (textSelection.length==0) textSelection = "\n";
- textSelection = information.prefix + textSelection + information.prefix;
- }
- return textSelection;
- },
-
- // Return Markdown for link
- getMarkdownLink: function(textSelection, information) {
- return textSelection.length!=0 ? information.prefix.replace("link", textSelection) : information.prefix;
- },
-
- // Set meta data
- setMetaData: function(element, key, value, toggle) {
- var information = this.getMetaDataInformation(element, key);
- if (information.bottom!=0) {
- var selectionStart = information.found ? information.start : information.bottom;
- var selectionEnd = information.found ? information.end : information.bottom;
- var text = information.text;
- var textSelectionBefore = text.substring(0, selectionStart);
- var textSelection = text.substring(selectionStart, selectionEnd);
- var textSelectionAfter = text.substring(selectionEnd, text.length);
- var textSelectionNew = yellow.toolbox.toUpperFirst(key)+": "+value+"\n";
- if (information.found && information.value==value && toggle) textSelectionNew = "";
- var selectionStartNew = selectionStart;
- var selectionEndNew = selectionStart + textSelectionNew.trim().length;
- element.focus();
- element.setSelectionRange(selectionStart, selectionEnd);
- document.execCommand("insertText", false, textSelectionNew);
- element.value = textSelectionBefore + textSelectionNew + textSelectionAfter;
- element.setSelectionRange(selectionStartNew, selectionEndNew);
- element.scrollTop = 0;
- if (yellow.system.debug) console.log("yellow.editor.setMetaData key:"+key);
- }
- },
-
- // Return meta data information
- getMetaDataInformation: function(element, key) {
- var text = element.value;
- var value = "";
- var start = 0, end = 0, top = 0, bottom = 0;
- var found = false;
- var parts = text.match(/^(\xEF\xBB\xBF)?(\-\-\-[\r\n]+)([\s\S]+?)\-\-\-[\r\n]+/);
- if (parts) {
- key = yellow.toolbox.toLowerFirst(key);
- start = end = top = ((parts[1] ? parts[1] : "")+parts[2]).length;
- bottom = ((parts[1] ? parts[1] : "")+parts[2]+parts[3]).length;
- var lines = yellow.toolbox.getTextLines(parts[3]);
- for (var i=0; i<lines.length; i++) {
- var matches = lines[i].match(/^\s*(.*?)\s*:\s*(.*?)\s*$/);
- if (matches && yellow.toolbox.toLowerFirst(matches[1])==key && matches[2].length!=0) {
- value = matches[2];
- end = start + lines[i].length;
- found = true;
- break;
- }
- start = end = start + lines[i].length;
- }
- }
- return { "text":text, "value":value, "start":start, "end":end, "top":top, "bottom":bottom, "found":found };
- },
-
- // Replace text
- replace: function(element, textOld, textNew) {
- var text = element.value;
- var selectionStart = element.selectionStart;
- var selectionEnd = element.selectionEnd;
- var selectionStartFound = text.indexOf(textOld);
- var selectionEndFound = selectionStartFound + textOld.length;
- if (selectionStartFound!=-1) {
- var selectionStartNew = selectionStart<selectionStartFound ? selectionStart : selectionStart+textNew.length-textOld.length;
- var selectionEndNew = selectionEnd<selectionEndFound ? selectionEnd : selectionEnd+textNew.length-textOld.length;
- var textBefore = text.substring(0, selectionStartFound);
- var textAfter = text.substring(selectionEndFound, text.length);
- if (textOld!=textNew) {
- element.focus();
- element.setSelectionRange(selectionStartFound, selectionEndFound);
- document.execCommand("insertText", false, textNew);
- element.value = textBefore + textNew + textAfter;
- element.setSelectionRange(selectionStartNew, selectionEndNew);
- }
- }
- },
-
- // Undo changes
- undo: function() {
- document.execCommand("undo");
- },
- // Redo changes
- redo: function() {
- document.execCommand("redo");
- }
- };
- yellow.toolbox = {
- // Insert element before reference element
- insertBefore: function(element, elementReference) {
- elementReference.parentNode.insertBefore(element, elementReference);
- },
- // Insert element after reference element
- insertAfter: function(element, elementReference) {
- elementReference.parentNode.insertBefore(element, elementReference.nextSibling);
- },
- // Add element class
- addClass: function(element, name) {
- element.classList.add(name);
- },
-
- // Remove element class
- removeClass: function(element, name) {
- element.classList.remove(name);
- },
- // Add attribute information
- addValue: function(selector, name, value) {
- var element = document.querySelector(selector);
- element.setAttribute(name, element.getAttribute(name) + value);
- },
- // Remove attribute information
- removeValue: function(selector, name, value) {
- var element = document.querySelector(selector);
- element.setAttribute(name, element.getAttribute(name).replace(value, ""));
- },
-
- // Add event handler
- addEvent: function(element, type, handler) {
- element.addEventListener(type, handler, false);
- },
-
- // Remove event handler
- removeEvent: function(element, type, handler) {
- element.removeEventListener(type, handler, false);
- },
-
- // Return shortcut from keyboard event, alphanumeric only
- getEventShortcut: function(e) {
- var shortcut = "";
- if (e.keyCode>=48 && e.keyCode<=90) {
- shortcut += (e.ctrlKey ? "ctrl+" : "")+(e.metaKey ? "meta+" : "")+(e.altKey ? "alt+" : "")+(e.shiftKey ? "shift+" : "");
- shortcut += String.fromCharCode(e.keyCode).toLowerCase();
- }
- return shortcut;
- },
-
- // Return element width in pixel
- getWidth: function(element) {
- return element.offsetWidth - this.getBoxSize(element).width;
- },
-
- // Return element height in pixel
- getHeight: function(element) {
- return element.offsetHeight - this.getBoxSize(element).height;
- },
-
- // Set element width in pixel, including padding and border
- setOuterWidth: function(element, width) {
- element.style.width = Math.max(0, width - this.getBoxSize(element).width) + "px";
- },
-
- // Set element height in pixel, including padding and border
- setOuterHeight: function(element, height) {
- element.style.height = Math.max(0, height - this.getBoxSize(element).height) + "px";
- },
-
- // Return element width in pixel, including padding and border
- getOuterWidth: function(element, includeMargin) {
- var width = element.offsetWidth;
- if (includeMargin) width += this.getMarginSize(element).width;
- return width;
- },
- // Return element height in pixel, including padding and border
- getOuterHeight: function(element, includeMargin) {
- var height = element.offsetHeight;
- if (includeMargin) height += this.getMarginSize(element).height;
- return height;
- },
-
- // Set element left position in pixel
- setOuterLeft: function(element, left) {
- element.style.left = Math.max(0, left) + "px";
- },
-
- // Set element top position in pixel
- setOuterTop: function(element, top) {
- element.style.top = Math.max(0, top) + "px";
- },
-
- // Return element left position in pixel
- getOuterLeft: function(element) {
- return element.getBoundingClientRect().left + window.pageXOffset;
- },
-
- // Return element top position in pixel
- getOuterTop: function(element) {
- return element.getBoundingClientRect().top + window.pageYOffset;
- },
-
- // Return window width in pixel
- getWindowWidth: function() {
- return window.innerWidth;
- },
-
- // Return window height in pixel
- getWindowHeight: function() {
- return window.innerHeight;
- },
-
- // Return element CSS property
- getStyle: function(element, property) {
- return window.getComputedStyle(element).getPropertyValue(property);
- },
-
- // Return element CSS padding and border
- getBoxSize: function(element) {
- var paddingLeft = parseFloat(this.getStyle(element, "padding-left")) || 0;
- var paddingRight = parseFloat(this.getStyle(element, "padding-right")) || 0;
- var borderLeft = parseFloat(this.getStyle(element, "border-left-width")) || 0;
- var borderRight = parseFloat(this.getStyle(element, "border-right-width")) || 0;
- var width = paddingLeft + paddingRight + borderLeft + borderRight;
- var paddingTop = parseFloat(this.getStyle(element, "padding-top")) || 0;
- var paddingBottom = parseFloat(this.getStyle(element, "padding-bottom")) || 0;
- var borderTop = parseFloat(this.getStyle(element, "border-top-width")) || 0;
- var borderBottom = parseFloat(this.getStyle(element, "border-bottom-width")) || 0;
- var height = paddingTop + paddingBottom + borderTop + borderBottom;
- return { "width":width, "height":height };
- },
-
- // Return element CSS margin
- getMarginSize: function(element) {
- var marginLeft = parseFloat(this.getStyle(element, "margin-left")) || 0;
- var marginRight = parseFloat(this.getStyle(element, "margin-right")) || 0;
- var width = marginLeft + marginRight;
- var marginTop = parseFloat(this.getStyle(element, "margin-top")) || 0;
- var marginBottom = parseFloat(this.getStyle(element, "margin-bottom")) || 0;
- var height = marginTop + marginBottom;
- return { "width":width, "height":height };
- },
-
- // Set element visibility
- setVisible: function(element, show, fadeout) {
- if (fadeout && !show) {
- var opacity = 1;
- function renderFrame() {
- opacity -= .1;
- if (opacity<=0) {
- element.style.opacity = "initial";
- element.style.display = "none";
- } else {
- element.style.opacity = opacity;
- requestAnimationFrame(renderFrame);
- }
- }
- renderFrame();
- } else {
- element.style.display = show ? "block" : "none";
- }
- },
- // Check if element exists and is visible
- isVisible: function(element) {
- return element && element.style.display!="none";
- },
-
- // Convert first letter to lowercase
- toLowerFirst: function(string) {
- return string.charAt(0).toLowerCase()+string.slice(1);
- },
- // Convert first letter to uppercase
- toUpperFirst: function(string) {
- return string.charAt(0).toUpperCase()+string.slice(1);
- },
-
- // Return lines from text string, including newline
- getTextLines: function(string) {
- var lines = string.split("\n");
- for (var i=0; i<lines.length; i++) lines[i] = lines[i]+"\n";
- if (string.length==0 || string.charAt(string.length-1)=="\n") lines.pop();
- return lines;
- },
-
- // Return cookie string
- getCookie: function(name) {
- var matches = document.cookie.match("(^|; )"+name+"=([^;]+)");
- return matches ? unescape(matches[2]) : "";
- },
-
- // Encode HTML special characters
- encodeHtml: function(string) {
- return string
- .replace(/&/g, "&")
- .replace(/</g, "<")
- .replace(/>/g, ">")
- .replace(/"/g, """);
- },
-
- // Submit form with post method
- submitForm: function(args) {
- var elementForm = document.createElement("form");
- elementForm.setAttribute("method", "post");
- for (var key in args) {
- if (!args.hasOwnProperty(key)) continue;
- var elementInput = document.createElement("input");
- elementInput.setAttribute("type", "hidden");
- elementInput.setAttribute("name", key);
- elementInput.setAttribute("value", args[key]);
- elementForm.appendChild(elementInput);
- }
- document.body.appendChild(elementForm);
- elementForm.submit();
- }
- };
- yellow.edit.intervalId = setInterval("yellow.onLoad()", 1);
|