diff --git a/dist/easycoder-min.js b/dist/easycoder-min.js index 0e722bd..c725358 100644 --- a/dist/easycoder-min.js +++ b/dist/easycoder-min.js @@ -164,18 +164,18 @@ a.next(),{domain:"browser",type:"contentOf",symbol:b.name};throw Error("'"+a.get (a.next(),a.isSymbol()&&(b=a.getSymbolRecord(),"dom"===b.extra)))return a.next(),{domain:"browser",type:"attributeOf",attribute:c,symbol:b.name};break;case "style":c=a.getNextValue();if(a.tokenIs("of")&&a.nextIsSymbol()){var d=a.getSymbolRecord();if("dom"===d.extra)return a.next(),{domain:"browser",type:b,style:c,target:d.name}}break;case "confirm":return b=a.getNextValue(),{domain:"browser",type:"confirm",text:b};case "prompt":return b=a.getNextValue(),c=null,a.tokenIs("with")&&(c=a.getNextValue()), {domain:"browser",type:"prompt",text:b,pre:c};case "screen":c=a.nextToken();if(["width","height"].includes(c))return a.next(),{domain:"browser",type:b,attribute:c};break;case "top":case "bottom":case "left":case "right":case "width":case "height":return EasyCoder_Browser.value.getCoord(a,b,c);case "scroll":if(a.nextTokenIs("position"))return a.next(),{domain:"browser",type:"scrollPosition"};break;case "document":if(a.nextTokenIs("path"))return a.next(),{domain:"browser",type:"docPath"};break;case "storage":if(a.nextTokenIs("keys"))return a.next(), {domain:"browser",type:"storageKeys"};break;case "parent":switch(a.nextToken()){case "name":return a.next(),{domain:"browser",type:"varName"};case "index":return a.next(),{domain:"browser",type:"varIndex"}}break;case "history":if(a.nextTokenIs("state"))return a.next(),{domain:"browser",type:"historyState"};break;case "pick":case "drag":if(a.nextTokenIs("position"))return a.next(),{domain:"browser",type:b+"Position"};case "click":if(b=a.nextToken(),["left","top"].includes(b))return a.next(),{domain:"browser", -type:"click",which:b}}return null},getCoord:function(a,b,c){if(a.nextTokenIs("of")){if(a.nextTokenIs("window"))return a.next(),{domain:"browser",type:b,symbol:"window",offset:c};if(a.isSymbol()){var d=a.getSymbolRecord();if("dom"===d.extra)return a.next(),{domain:"browser",type:b,symbol:d.name,offset:c}}}return null},get:function(a,b){switch(b.type){case "file":case "input":case "select":case "textarea":var c=a.getSymbolRecord(b.value);var d=c.element[c.index];return{type:"constant",numeric:!1,content:d.value}; -case "exists":return c=a.getSymbolRecord(b.value),{domain:"browser",type:"boolean",content:"undefined"!==typeof c.element[c.index]};case "mobile":return{domain:"browser",type:"boolean",content:"undefined"!==typeof window.orientation||-1!==navigator.userAgent.indexOf("IEMobile")};case "portrait":return{domain:"browser",type:"boolean",content:document.documentElement.clientWidth= -document.documentElement.clientHeight};case "br":return{type:"constant",numeric:!1,content:decodeURIComponent("%3Cbr%20%2F%3E")};case "attributeOf":return c=a.getSymbolRecord(b.symbol),b=a.getValue(b.attribute),d=c.element[c.index],0===b.indexOf("data-")?a.getSimpleValue(d.dataset[b.substr(5)]):a.getSimpleValue(d[b]);case "style":return c=a.getSymbolRecord(b.target),b=a.getValue(b.style),d=c.element[c.index],a.getSimpleValue(d.style[b]);case "confirm":return{type:"boolean",content:window.confirm(a.getValue(b.text))}; -case "prompt":return d=a.getValue(b.text),b=a.getValue(b.pre),{type:"constant",numeric:!1,content:b?window.prompt(d,b):window.prompt(d)};case "contentOf":c=a.getSymbolRecord(b.symbol);d=c.element[c.index];switch(c.keyword){case "input":case "textarea":b=d.value;break;case "pre":b=d.innerHTML;break;default:b=d.innerHTML.split("\n").join("")}return{type:"constant",numeric:!1,content:b};case "selected":return c=a.getSymbolRecord(b.symbol),d=c.element[c.index],a=d.selectedIndex,d=0<=a?d.options[a].text: -"",b="index"===b.arg?a:d,{type:"constant",numeric:!1,content:b};case "top":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenY};c=a.getSymbolRecord(b.symbol);a=c.element[c.index];b=Math.round(b.offset?a.offsetTop:a.getBoundingClientRect().top);return{type:"constant",numeric:!0,content:b};case "bottom":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenY+window.innerHeight};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().bottom); -return{type:"constant",numeric:!0,content:b};case "left":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenLeft};c=a.getSymbolRecord(b.symbol);a=c.element[c.index];b=Math.round(b.offset?a.offsetLeft:a.getBoundingClientRect().left);return{type:"constant",numeric:!0,content:b};case "right":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenX+window.innerWidth};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().right); -return{type:"constant",numeric:!0,content:b};case "width":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.innerWidth};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().width);return{type:"constant",numeric:!0,content:b};case "height":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.innerHeight};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().height);return{type:"constant",numeric:!0, -content:b};case "color":return{type:"constant",numeric:!1,content:"#"+a.value.evaluate(a,b.value).content.toString(16).padStart(6,"0")};case "docPath":return{type:"constant",numeric:!1,content:a.docPath};case "storageKeys":return{type:"constant",numeric:!1,content:JSON.stringify(Object.keys(localStorage))};case "location":return{type:"constant",numeric:!1,content:window.location.href};case "historyState":return{type:"constant",numeric:!1,content:window.history.state};case "scrollPosition":return{type:"constant", -numeric:!0,content:scrollPosition};case "varName":return{type:"constant",numeric:!1,content:a.varName};case "varIndex":return{type:"constant",numeric:!0,content:a.varIndex};case "key":return{type:"constant",numeric:!1,content:a.key};case "hostname":return{type:"constant",numeric:!1,content:location.hostname};case "screen":return{type:"constant",numeric:!0,content:screen[b.attribute]};case "pickPosition":return{type:"constant",numeric:!1,content:JSON.stringify({x:document.pickX,y:document.pickY})}; -case "dragPosition":return{type:"constant",numeric:!1,content:JSON.stringify({x:document.dragX,y:document.dragY})};case "click":a=EasyCoder_Browser.clickData;if("undefined"===typeof a)return 0;d=a.target.getBoundingClientRect();return{type:"constant",numeric:!0,content:"left"===b.which?a.clientX-Math.round(d.left):a.clientY-Math.round(d.top)}}}},condition:{compile:function(a){if(a.tokenIs("confirm"))return{domain:"browser",type:"confirm",value:a.getNextValue()};if(a.tokenIs("element")&&a.nextIsSymbol()){var b= -a.getSymbolRecord();if("dom"===b.extra){var c=a.nextToken();if("has"===c){if(a.nextTokenIs("the")&&a.next(),a.tokenIs("focus"))return a.next(),{domain:"browser",type:"focus",element:b.name}}else if("contains"===c)return a=a.getNextValue(),{domain:"browser",type:"contains",element:b.name,position:a}}}return null},test:function(a,b){switch(b.type){case "confirm":return confirm(a.getValue(b.value));case "focus":var c=a.getSymbolRecord(b.element);return c.element[c.index]===document.activeElement;case "contains":c= -a.getSymbolRecord(b.element);var d=c.element[c.index].getBoundingClientRect();c=Math.round(d.left);var e=Math.round(d.right),f=Math.round(d.top);d=Math.round(d.bottom);b=JSON.parse(a.getValue(b.position));a=b.x;b=b.y;return a>=c&&a<=e&&b>=f&&b<=d?!0:!1}}},setStyles:function(a,b){a=document.getElementById(a);b=b.split(";");b=$jscomp.makeIterator(b);for(var c=b.next();!c.done;c=b.next())c=c.value.split(":"),a.setAttribute(c[0],c[1])}},scrollPosition=0; +type:"click",which:b}}return null},getCoord:function(a,b,c){if(a.nextTokenIs("of")){a.nextTokenIs("the")&&a.nextToken();var d=a.getToken();if(["window","viewport"].includes(d))return a.next(),{domain:"browser",type:b,symbol:d,offset:c};if(a.isSymbol()&&(d=a.getSymbolRecord(),"dom"===d.extra))return a.next(),{domain:"browser",type:b,symbol:d.name,offset:c}}return null},get:function(a,b){switch(b.type){case "file":case "input":case "select":case "textarea":var c=a.getSymbolRecord(b.value);var d=c.element[c.index]; +return{type:"constant",numeric:!1,content:d.value};case "exists":return c=a.getSymbolRecord(b.value),{domain:"browser",type:"boolean",content:"undefined"!==typeof c.element[c.index]};case "mobile":return{domain:"browser",type:"boolean",content:"undefined"!==typeof window.orientation||-1!==navigator.userAgent.indexOf("IEMobile")};case "portrait":return{domain:"browser",type:"boolean",content:document.documentElement.clientWidth=document.documentElement.clientHeight};case "br":return{type:"constant",numeric:!1,content:decodeURIComponent("%3Cbr%20%2F%3E")};case "attributeOf":return c=a.getSymbolRecord(b.symbol),b=a.getValue(b.attribute),d=c.element[c.index],0===b.indexOf("data-")?a.getSimpleValue(d.dataset[b.substr(5)]):a.getSimpleValue(d[b]);case "style":return c=a.getSymbolRecord(b.target),b=a.getValue(b.style),d=c.element[c.index],a.getSimpleValue(d.style[b]); +case "confirm":return{type:"boolean",content:window.confirm(a.getValue(b.text))};case "prompt":return d=a.getValue(b.text),b=a.getValue(b.pre),{type:"constant",numeric:!1,content:b?window.prompt(d,b):window.prompt(d)};case "contentOf":c=a.getSymbolRecord(b.symbol);d=c.element[c.index];switch(c.keyword){case "input":case "textarea":b=d.value;break;case "pre":b=d.innerHTML;break;default:b=d.innerHTML.split("\n").join("")}return{type:"constant",numeric:!1,content:b};case "selected":return c=a.getSymbolRecord(b.symbol), +d=c.element[c.index],a=d.selectedIndex,d=0<=a?d.options[a].text:"",b="index"===b.arg?a:d,{type:"constant",numeric:!1,content:b};case "top":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenY};c=a.getSymbolRecord(b.symbol);a=c.element[c.index];b=Math.round(b.offset?a.offsetTop:a.getBoundingClientRect().top);return{type:"constant",numeric:!0,content:b};case "bottom":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenY+window.innerHeight};c=a.getSymbolRecord(b.symbol); +b=Math.round(c.element[c.index].getBoundingClientRect().bottom);return{type:"constant",numeric:!0,content:b};case "left":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenLeft};c=a.getSymbolRecord(b.symbol);a=c.element[c.index];b=Math.round(b.offset?a.offsetLeft:a.getBoundingClientRect().left);return{type:"constant",numeric:!0,content:b};case "right":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenX+window.innerWidth};c=a.getSymbolRecord(b.symbol); +b=Math.round(c.element[c.index].getBoundingClientRect().right);return{type:"constant",numeric:!0,content:b};case "width":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.innerWidth};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().width);return{type:"constant",numeric:!0,content:b};case "height":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.innerHeight};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().height); +return{type:"constant",numeric:!0,content:b};case "color":return{type:"constant",numeric:!1,content:"#"+a.value.evaluate(a,b.value).content.toString(16).padStart(6,"0")};case "docPath":return{type:"constant",numeric:!1,content:a.docPath};case "storageKeys":return{type:"constant",numeric:!1,content:JSON.stringify(Object.keys(localStorage))};case "location":return{type:"constant",numeric:!1,content:window.location.href};case "historyState":return{type:"constant",numeric:!1,content:window.history.state}; +case "scrollPosition":return{type:"constant",numeric:!0,content:scrollPosition};case "varName":return{type:"constant",numeric:!1,content:a.varName};case "varIndex":return{type:"constant",numeric:!0,content:a.varIndex};case "key":return{type:"constant",numeric:!1,content:a.key};case "hostname":return{type:"constant",numeric:!1,content:location.hostname};case "screen":return{type:"constant",numeric:!0,content:screen[b.attribute]};case "pickPosition":return{type:"constant",numeric:!1,content:JSON.stringify({x:document.pickX, +y:document.pickY})};case "dragPosition":return{type:"constant",numeric:!1,content:JSON.stringify({x:document.dragX,y:document.dragY})};case "click":a=EasyCoder_Browser.clickData;if("undefined"===typeof a)return 0;d=a.target.getBoundingClientRect();return{type:"constant",numeric:!0,content:"left"===b.which?a.clientX-Math.round(d.left):a.clientY-Math.round(d.top)}}}},condition:{compile:function(a){if(a.tokenIs("confirm"))return{domain:"browser",type:"confirm",value:a.getNextValue()};if(a.tokenIs("element")&& +a.nextIsSymbol()){var b=a.getSymbolRecord();if("dom"===b.extra){var c=a.nextToken();if("has"===c){if(a.nextTokenIs("the")&&a.next(),a.tokenIs("focus"))return a.next(),{domain:"browser",type:"focus",element:b.name}}else if("contains"===c)return a=a.getNextValue(),{domain:"browser",type:"contains",element:b.name,position:a}}}return null},test:function(a,b){switch(b.type){case "confirm":return confirm(a.getValue(b.value));case "focus":var c=a.getSymbolRecord(b.element);return c.element[c.index]===document.activeElement; +case "contains":c=a.getSymbolRecord(b.element);var d=c.element[c.index].getBoundingClientRect();c=Math.round(d.left);var e=Math.round(d.right),f=Math.round(d.top);d=Math.round(d.bottom);b=JSON.parse(a.getValue(b.position));a=b.x;b=b.y;return a>=c&&a<=e&&b>=f&&b<=d?!0:!1}}},setStyles:function(a,b){a=document.getElementById(a);b=b.split(";");b=$jscomp.makeIterator(b);for(var c=b.next();!c.done;c=b.next())c=c.value.split(":"),a.setAttribute(c[0],c[1])}},scrollPosition=0; window.addEventListener("scroll",function(){scrollPosition=this.scrollY});window.onpopstate=function(a){window.EasyCoder.timestamp=Date.now();(a=JSON.parse(a.state))&&a.script&&((a=window.EasyCoder.scripts[a.script])?a.onBrowserBack&&a.run(a.onBrowserBack):console.log("No script property in window state object"))}; var EasyCoder_Json={name:"EasyCoder_JSON",Json:{compile:function(a){var b=a.getLino(),c=a.nextToken();switch(c){case "set":a.next();if(a.isSymbol())if(c=a.getSymbolRecord(),"variable"===c.keyword){if(a.nextTokenIs("to")){var d=a.nextToken();if('["array","object"]'.includes(d))return a.next(),a.addCommand({domain:"json",keyword:"json",lino:b,request:"setVariable",target:c.name,type:d}),!0}}else if("select"===c.keyword&&a.nextTokenIs("from")&&(a.next(),a.isSymbol()&&(d=a.getSymbolRecord(),"variable"=== d.keyword))){var e=null;a.nextTokenIs("as")&&(e=a.getNextValue());a.addCommand({domain:"json",keyword:"json",lino:b,request:"setList",target:c.name,source:d.name,display:e});return!0}break;case "sort":case "shuffle":case "format":if(a.nextIsSymbol()&&(d=a.getSymbolRecord(),"variable"===d.keyword))return a.next(),a.addCommand({domain:"json",keyword:"json",lino:b,request:c,target:d.name}),!0;break;case "parse":if(a.nextTokenIs("url")&&(d=a.getNextValue(),a.tokenIs("as")&&a.nextIsSymbol()&&(e=a.getSymbolRecord(), @@ -226,5 +226,5 @@ f.condition=EasyCoder_Condition;f.domain=this.domain;f.imports=b;f.continue=!1;b this.require;b.isUndefined=this.isUndefined;b.isJsonString=this.isJsonString;b.getSymbolRecord=this.getSymbolRecord;b.verifySymbol=this.verifySymbol;b.runtimeError=this.runtimeError;b.nonNumericValueError=this.nonNumericValueError;b.variableDoesNotHoldAValueError=this.variableDoesNotHoldAValueError;b.reportError=this.reportError;b.register=this.register;b.symbols=f.getSymbols();b.unblocked=!1;b.encoding="ec";b.popups=[];b.stack=[];b.queue=[0];b.module=c;b.parent=d;c&&(c.program=b.script);return b}, tokeniseFile:function(a){var b=[],c=[],d=0;a.forEach(function(a,f){b.push({lino:f+1,line:a});for(var e=a.length,g="",k=!0,l=0;l { if (compiler.nextTokenIs(`of`)) { - if (compiler.nextTokenIs(`window`)) { + if (compiler.nextTokenIs(`the`)) { + compiler.nextToken(); + } + const symbol = compiler.getToken(); + if ([`window`, `viewport`].includes(symbol)) { compiler.next(); return { domain: `browser`, type, - symbol: `window`, + symbol, offset }; } @@ -8363,7 +8367,7 @@ const EasyCoder = { } }, }; -EasyCoder.version = `2.6.1`; +EasyCoder.version = `2.7.0`; EasyCoder.timestamp = Date.now(); console.log(`EasyCoder loaded; waiting for page`); diff --git a/dist/easycoder.php b/dist/easycoder.php index 2509dc7..3d82974 100644 --- a/dist/easycoder.php +++ b/dist/easycoder.php @@ -3,7 +3,7 @@ * Plugin Name: EasyCoder * Plugin URI: https://easycoder.software * Description: Control the appearance and behavior of your posts and pages by embedding simple English-like scripts, without the need to learn JavaScript. - * Version: 2.6.1 + * Version: 2.7.0 * Author: EasyCoder Software * Author URI: https://easycoder.software */ @@ -16,9 +16,9 @@ add_action('wp_enqueue_scripts', 'easycoder_enqueue_script', 2); function easycoder_enqueue_script() { wp_enqueue_script('easycoder_script', - 'https://cdn.jsdelivr.net/gh/easycoder/easycoder.github.io/dist/easycoder.js', array(), '2.6.1'); + 'https://cdn.jsdelivr.net/gh/easycoder/easycoder.github.io/dist/easycoder.js', array(), '2.7.0'); // wp_enqueue_script('easycoder_script', 'https://rembrandt.easycoder.software/dist/easycoder.js', - array(), '2.6.1'); + array(), '2.7.0'); } // Set up default plugin and REST scripts diff --git a/dist/readme.txt b/dist/readme.txt index 2c0e5e4..7925690 100644 --- a/dist/readme.txt +++ b/dist/readme.txt @@ -54,6 +54,9 @@ For tutorials and a programmers' reference see our [EasyCoder Software Codex](ht == Changelog == += 2.7.0 04-may 2020 = +* Added 'click left' and 'click top' + = 2.6.1 16-apr 2020 = * Use CDN to deliver all files diff --git a/js/easycoder/Browser.js b/js/easycoder/Browser.js index 5207da0..21b7306 100644 --- a/js/easycoder/Browser.js +++ b/js/easycoder/Browser.js @@ -2982,12 +2982,16 @@ const EasyCoder_Browser = { getCoord: (compiler, type, offset) => { if (compiler.nextTokenIs(`of`)) { - if (compiler.nextTokenIs(`window`)) { + if (compiler.nextTokenIs(`the`)) { + compiler.nextToken(); + } + const symbol = compiler.getToken(); + if ([`window`, `viewport`].includes(symbol)) { compiler.next(); return { domain: `browser`, type, - symbol: `window`, + symbol, offset }; }