Include the JSON parser natively in framework.js

We've also included it as a separate framework.parser.js file in case its needed by some external lib, such as Storm UI
This commit is contained in:
Samuel Georges 2019-09-14 17:56:18 +10:00
parent 68f0cd640d
commit 2962f75221
12 changed files with 438 additions and 110 deletions

View File

@ -70,7 +70,7 @@
/*
* This function transfers the supplied variables as hidden form inputs,
* to any popup that is spawned within the supplied container. The spawned
* to any popup that is spawned within the supplied container. The spawned
* popup must contain a form element.
*/
this.bindToPopups = function(container, vars) {
@ -87,7 +87,7 @@
if (typeof value == 'object') return value
try {
return $.oc.JSON("{" + value + "}")
return ocJSON("{" + value + "}")
}
catch (e) {
throw new Error('Error parsing the '+name+' attribute value. '+e)
@ -97,4 +97,4 @@
}
$.oc.relationBehavior = new RelationBehavior;
}(window.jQuery);
}(window.jQuery);

View File

@ -264,7 +264,7 @@
if (typeof value == 'object') return value
try {
return $.oc.JSON("{" + value + "}")
return ocJSON("{" + value + "}")
}
catch (e) {
throw new Error('Error parsing the '+name+' attribute value. '+e)

View File

@ -1,4 +1,5 @@
"use strict";!function(){function a(e,r,n){for(var t="",o=r;o<e.length;o++){if(n&&n===e[o])return t;if(!n&&(" "===e[o]||":"===e[o]))return t;t+=e[o],"\\"===e[o]&&o+1<e.length&&(t+=e[o+1],o++)}throw new Error("Broken JSON syntax near "+t)}function u(e,r){if('"'===e[r]||"'"===e[r]){for(var n=e[r],t=r+1;t<e.length;t++)if("\\"===e[t])n+=e[t],t+1<e.length&&(n+=e[t+1]),t++;else{if(e[t]===e[r])return{originLength:(n+=e[r]).length,body:n};n+=e[t]}throw new Error("Broken JSON string body near "+n)}if("t"===e[r]){if(e.indexOf("true",r)===r)return{originLength:"true".length,body:"true"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("f"===e[r]){if(e.indexOf("f",r)===r)return{originLength:"false".length,body:"false"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("n"===e[r]){if(e.indexOf("null",r)===r)return{originLength:"null".length,body:"null"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("-"===e[r]||"+"===e[r]||"."===e[r]||"0"<=e[r]&&e[r]<="9"){for(n="",t=r;t<e.length;t++){if(!("-"===e[t]||"+"===e[t]||"."===e[t]||"0"<=e[t]&&e[t]<="9"))return{originLength:n.length,body:n};n+=e[t]}throw new Error("Broken JSON number body near "+n)}if("{"!==e[r]&&"["!==e[r])throw new Error("Broken JSON body near "+e.substr(0<=r-5?r-5:0,50));var o=[e[r]];for(n=e[r],t=r+1;t<e.length;t++){if(n+=e[t],"\\"===e[t])t+1<e.length&&(n+=e[t+1]),t++;else if('"'===e[t])'"'===o[o.length-1]?o.pop():"'"!==o[o.length-1]&&o.push(e[t]);else if("'"===e[t])"'"===o[o.length-1]?o.pop():'"'!==o[o.length-1]&&o.push(e[t]);else if('"'!==o[o.length-1]&&"'"!==o[o.length-1])if("{"===e[t])o.push("{");else if("}"===e[t]){if("{"!==o[o.length-1])throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n);o.pop()}else if("["===e[t])o.push("[");else if("]"===e[t]){if("["!==o[o.length-1])throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n);o.pop()}if(!o.length)return{originLength:t-r,body:n}}throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n)}function s(e){return" "===e||"\n"===e||"\t"===e}void 0===$.oc&&($.oc={}),$.oc.JSON=function(e){var r=function e(r){if(!(r=r.trim()).length)throw new Error("Broken JSON object.");for(var n="";r&&","===r[0];)r=r.substr(1);if('"'===r[0]||"'"===r[0]){if(r[r.length-1]!==r[0])throw new Error("Invalid string JSON object.");for(var t='"',o=1;o<r.length;o++)if("\\"===r[o])"'"===r[o+1]||(t+=r[o]),t+=r[o+1],o++;else{if(r[o]===r[0])return t+='"';'"'===r[o]?t+='\\"':t+=r[o]}throw new Error("Invalid string JSON object.")}if("true"===r||"false"===r)return r;if("null"===r)return"null";var i,f=parseFloat(r);if(!isNaN(f))return f.toString();if("{"===r[0]){var l="needKey";for(n="{",o=1;o<r.length;o++)if(!s(r[o]))if("needKey"!==l||'"'!==r[o]&&"'"!==r[o]){if("needKey"===l&&"\\"!==(i=r[o])[0]&&("a"<=i[0]&&i[0]<="z"||"A"<=i[0]&&i[0]<="Z"||"_"===i[0]||"0"<=i[0]&&i[0]<="9"||"$"===i[0]||255<i.charCodeAt(0))){var h;n+='"',n+=h=a(r,o),n+='"',o+=h.length-1,l="afterKey"}else if("afterKey"===l&&":"===r[o])n+=":",l=":";else if(":"===l)o=o+(t=u(r,o)).originLength-1,n+=e(t.body),l="afterBody";else if("afterBody"===l||"needKey"===l){for(var g=o;","===r[g]||s(r[g]);)g++;if("}"===r[g]&&g===r.length-1){for(;","===n[n.length-1];)n=n.substr(0,n.length-1);return n+="}"}g!==o&&"{"!==n&&(n+=",",l="needKey",o=g-1)}}else n+='"'+(h=a(r,o+1,r[o]))+'"',o+=h.length,o+=1,l="afterKey";throw new Error("Broken JSON object near "+n)}if("["===r[0]){for(n="[",l="needBody",o=1;o<r.length;o++)if(" "!==r[o]&&"\n"!==r[o]&&"\t"!==r[o])if("needBody"===l){if(","===r[o]){n+="null,";continue}if("]"===r[o]&&o===r.length-1)return","===n[n.length-1]&&(n=n.substr(0,n.length-1)),n+="]";o=o+(t=u(r,o)).originLength-1,n+=e(t.body),l="afterBody"}else if("afterBody"===l)if(","===r[o])for(n+=",",l="needBody";","===r[o+1]||s(r[o+1]);)","===r[o+1]&&(n+="null,"),o++;else if("]"===r[o]&&o===r.length-1)return n+="]";throw new Error("Broken JSON array near "+n)}}(e);return JSON.parse(r)}}();if(window.jQuery===undefined){throw new Error('The jQuery library is not loaded. The OctoberCMS framework cannot be initialized.');}
if(window.jQuery===undefined){throw new Error('The jQuery library is not loaded. The OctoberCMS framework cannot be initialized.');}
if(window.jQuery.request!==undefined){throw new Error('The OctoberCMS framework is already loaded.');}
+function($){"use strict";var Request=function(element,handler,options){var $el=this.$el=$(element);this.options=options||{};if(handler===undefined){throw new Error('The request handler name is not specified.')}
if(!handler.match(/^(?:\w+\:{2})?on*/)){throw new Error('Invalid handler name. The correct handler name format is: "onEvent".')}
@ -109,7 +110,7 @@ $.fn.request.noConflict=function(){$.fn.request=old
return this}
function paramToObj(name,value){if(value===undefined)value=''
if(typeof value=='object')return value
try{return $.oc.JSON("{"+value+"}")}
try{return ocJSON("{"+value+"}")}
catch(e){throw new Error('Error parsing the '+name+' attribute value. '+e)}}
$(document).on('change','select[data-request], input[type=radio][data-request], input[type=checkbox][data-request], input[type=file][data-request]',function documentOnChange(){$(this).request()})
$(document).on('click','a[data-request], button[data-request], input[type=button][data-request], input[type=submit][data-request]',function documentOnClick(e){e.preventDefault()
@ -140,4 +141,39 @@ return false})
$(window).on('beforeunload',function documentOnBeforeUnload(){window.ocUnloading=true})
$(document).ready(function triggerRenderOnReady(){$(document).trigger('render')})
$(window).on('ajaxUpdateComplete',function triggerRenderOnAjaxUpdateComplete(){$(document).trigger('render')})
$.fn.render=function(callback){$(document).on('render',callback)}}(window.jQuery);
$.fn.render=function(callback){$(document).on('render',callback)}}(window.jQuery);+function(window){"use strict";function parseKey(str,pos,quote){var key="";for(var i=pos;i<str.length;i++){if(quote&&quote===str[i]){return key;}else if(!quote&&(str[i]===" "||str[i]===":")){return key;}
key+=str[i];if(str[i]==="\\"&&i+1<str.length){key+=str[i+1];i++;}}
throw new Error("Broken JSON syntax near "+key);}
function getBody(str,pos){if(str[pos]==="\""||str[pos]==="'"){var body=str[pos];for(var i=pos+1;i<str.length;i++){if(str[i]==="\\"){body+=str[i];if(i+1<str.length)body+=str[i+1];i++;}else if(str[i]===str[pos]){body+=str[pos];return{originLength:body.length,body:body};}else body+=str[i];}
throw new Error("Broken JSON string body near "+body);}
if(str[pos]==="t"){if(str.indexOf("true",pos)===pos){return{originLength:"true".length,body:"true"};}
throw new Error("Broken JSON boolean body near "+str.substr(0,pos+10));}
if(str[pos]==="f"){if(str.indexOf("f",pos)===pos){return{originLength:"false".length,body:"false"};}
throw new Error("Broken JSON boolean body near "+str.substr(0,pos+10));}
if(str[pos]==="n"){if(str.indexOf("null",pos)===pos){return{originLength:"null".length,body:"null"};}
throw new Error("Broken JSON boolean body near "+str.substr(0,pos+10));}
if(str[pos]==="-"||str[pos]==="+"||str[pos]==="."||(str[pos]>="0"&&str[pos]<="9")){var body="";for(var i=pos;i<str.length;i++){if(str[i]==="-"||str[i]==="+"||str[i]==="."||(str[i]>="0"&&str[i]<="9")){body+=str[i];}else{return{originLength:body.length,body:body};}}
throw new Error("Broken JSON number body near "+body);}
if(str[pos]==="{"||str[pos]==="["){var stack=[str[pos]];var body=str[pos];for(var i=pos+1;i<str.length;i++){body+=str[i];if(str[i]==="\\"){if(i+1<str.length)body+=str[i+1];i++;}else if(str[i]==="\""){if(stack[stack.length-1]==="\""){stack.pop();}else if(stack[stack.length-1]!=="'"){stack.push(str[i]);}}else if(str[i]==="'"){if(stack[stack.length-1]==="'"){stack.pop();}else if(stack[stack.length-1]!=="\""){stack.push(str[i]);}}else if(stack[stack.length-1]!=="\""&&stack[stack.length-1]!=="'"){if(str[i]==="{"){stack.push("{");}else if(str[i]==="}"){if(stack[stack.length-1]==="{"){stack.pop();}else{throw new Error("Broken JSON "+(str[pos]==="{"?"object":"array")+" body near "+body);}}else if(str[i]==="["){stack.push("[");}else if(str[i]==="]"){if(stack[stack.length-1]==="["){stack.pop();}else{throw new Error("Broken JSON "+(str[pos]==="{"?"object":"array")+" body near "+body);}}}
if(!stack.length){return{originLength:i-pos,body:body};}}
throw new Error("Broken JSON "+(str[pos]==="{"?"object":"array")+" body near "+body);}
throw new Error("Broken JSON body near "+str.substr((pos-5>=0)?pos-5:0,50));}
function canBeKeyHead(ch){if(ch[0]==="\\")return false;if((ch[0]>='a'&&ch[0]<='z')||(ch[0]>='A'&&ch[0]<='Z')||ch[0]==='_')return true;if(ch[0]>='0'&&ch[0]<='9')return true;if(ch[0]==='$')return true;if(ch.charCodeAt(0)>255)return true;return false;}
function isBlankChar(ch){return ch===" "||ch==="\n"||ch==="\t";}
function parse(str){str=str.trim();if(!str.length)throw new Error("Broken JSON object.");var result="";while(str&&str[0]===","){str=str.substr(1);}
if(str[0]==="\""||str[0]==="'"){if(str[str.length-1]!==str[0]){throw new Error("Invalid string JSON object.");}
var body="\"";for(var i=1;i<str.length;i++){if(str[i]==="\\"){if(str[i+1]==="'"){body+=str[i+1]}else{body+=str[i];body+=str[i+1];}
i++;}else if(str[i]===str[0]){body+="\"";return body}else if(str[i]==="\""){body+="\\\""}else body+=str[i];}
throw new Error("Invalid string JSON object.");}
if(str==="true"||str==="false"){return str;}
if(str==="null"){return"null";}
var num=parseFloat(str);if(!isNaN(num)){return num.toString();}
if(str[0]==="{"){var type="needKey";var result="{";for(var i=1;i<str.length;i++){if(isBlankChar(str[i])){continue;}else if(type==="needKey"&&(str[i]==="\""||str[i]==="'")){var key=parseKey(str,i+1,str[i]);result+="\""+key+"\"";i+=key.length;i+=1;type="afterKey";}else if(type==="needKey"&&canBeKeyHead(str[i])){var key=parseKey(str,i);result+="\"";result+=key;result+="\"";i+=key.length-1;type="afterKey";}else if(type==="afterKey"&&str[i]===":"){result+=":";type=":";}else if(type===":"){var body=getBody(str,i);i=i+body.originLength-1;result+=parse(body.body);type="afterBody";}else if(type==="afterBody"||type==="needKey"){var last=i;while(str[last]===","||isBlankChar(str[last])){last++;}
if(str[last]==="}"&&last===str.length-1){while(result[result.length-1]===","){result=result.substr(0,result.length-1);}
result+="}";return result;}else if(last!==i&&result!=="{"){result+=",";type="needKey";i=last-1;}}}
throw new Error("Broken JSON object near "+result);}
if(str[0]==="["){var result="[";var type="needBody";for(var i=1;i<str.length;i++){if(" "===str[i]||"\n"===str[i]||"\t"===str[i]){continue;}else if(type==="needBody"){if(str[i]===","){result+="null,";continue;}
if(str[i]==="]"&&i===str.length-1){if(result[result.length-1]===",")result=result.substr(0,result.length-1);result+="]";return result;}
var body=getBody(str,i);i=i+body.originLength-1;result+=parse(body.body);type="afterBody";}else if(type==="afterBody"){if(str[i]===","){result+=",";type="needBody";while(str[i+1]===","||isBlankChar(str[i+1])){if(str[i+1]===",")result+="null,";i++;}}else if(str[i]==="]"&&i===str.length-1){result+="]";return result;}}}
throw new Error("Broken JSON array near "+result);}}
window.ocJSON=function(json){var jsonString=parse(json);return JSON.parse(jsonString);};}(window);

View File

@ -1,41 +1,5 @@
"use strict";(function(){function parseKey(str,pos,quote){var key="";for(var i=pos;i<str.length;i++){if(quote&&quote===str[i]){return key;}else if(!quote&&(str[i]===" "||str[i]===":")){return key;}
key+=str[i];if(str[i]==="\\"&&i+1<str.length){key+=str[i+1];i++;}}
throw new Error("Broken JSON syntax near "+key);}
function getBody(str,pos){if(str[pos]==="\""||str[pos]==="'"){var body=str[pos];for(var i=pos+1;i<str.length;i++){if(str[i]==="\\"){body+=str[i];if(i+1<str.length)body+=str[i+1];i++;}else if(str[i]===str[pos]){body+=str[pos];return{originLength:body.length,body:body};}else body+=str[i];}
throw new Error("Broken JSON string body near "+body);}
if(str[pos]==="t"){if(str.indexOf("true",pos)===pos){return{originLength:"true".length,body:"true"};}
throw new Error("Broken JSON boolean body near "+str.substr(0,pos+10));}
if(str[pos]==="f"){if(str.indexOf("f",pos)===pos){return{originLength:"false".length,body:"false"};}
throw new Error("Broken JSON boolean body near "+str.substr(0,pos+10));}
if(str[pos]==="n"){if(str.indexOf("null",pos)===pos){return{originLength:"null".length,body:"null"};}
throw new Error("Broken JSON boolean body near "+str.substr(0,pos+10));}
if(str[pos]==="-"||str[pos]==="+"||str[pos]==="."||(str[pos]>="0"&&str[pos]<="9")){var body="";for(var i=pos;i<str.length;i++){if(str[i]==="-"||str[i]==="+"||str[i]==="."||(str[i]>="0"&&str[i]<="9")){body+=str[i];}else{return{originLength:body.length,body:body};}}
throw new Error("Broken JSON number body near "+body);}
if(str[pos]==="{"||str[pos]==="["){var stack=[str[pos]];var body=str[pos];for(var i=pos+1;i<str.length;i++){body+=str[i];if(str[i]==="\\"){if(i+1<str.length)body+=str[i+1];i++;}else if(str[i]==="\""){if(stack[stack.length-1]==="\""){stack.pop();}else if(stack[stack.length-1]!=="'"){stack.push(str[i]);}}else if(str[i]==="'"){if(stack[stack.length-1]==="'"){stack.pop();}else if(stack[stack.length-1]!=="\""){stack.push(str[i]);}}else if(stack[stack.length-1]!=="\""&&stack[stack.length-1]!=="'"){if(str[i]==="{"){stack.push("{");}else if(str[i]==="}"){if(stack[stack.length-1]==="{"){stack.pop();}else{throw new Error("Broken JSON "+(str[pos]==="{"?"object":"array")+" body near "+body);}}else if(str[i]==="["){stack.push("[");}else if(str[i]==="]"){if(stack[stack.length-1]==="["){stack.pop();}else{throw new Error("Broken JSON "+(str[pos]==="{"?"object":"array")+" body near "+body);}}}
if(!stack.length){return{originLength:i-pos,body:body};}}
throw new Error("Broken JSON "+(str[pos]==="{"?"object":"array")+" body near "+body);}
throw new Error("Broken JSON body near "+str.substr((pos-5>=0)?pos-5:0,50));}
function canBeKeyHead(ch){if(ch[0]==="\\")return false;if((ch[0]>='a'&&ch[0]<='z')||(ch[0]>='A'&&ch[0]<='Z')||ch[0]==='_')return true;if(ch[0]>='0'&&ch[0]<='9')return true;if(ch[0]==='$')return true;if(ch.charCodeAt(0)>255)return true;return false;}
function isBlankChar(ch){return ch===" "||ch==="\n"||ch==="\t";}
function parse(str){str=str.trim();if(!str.length)throw new Error("Broken JSON object.");var result="";while(str&&str[0]===","){str=str.substr(1);}
if(str[0]==="\""||str[0]==="'"){if(str[str.length-1]!==str[0]){throw new Error("Invalid string JSON object.");}
var body="\"";for(var i=1;i<str.length;i++){if(str[i]==="\\"){if(str[i+1]==="'"){body+=str[i+1]}else{body+=str[i];body+=str[i+1];}
i++;}else if(str[i]===str[0]){body+="\"";return body}else if(str[i]==="\""){body+="\\\""}else body+=str[i];}
throw new Error("Invalid string JSON object.");}
if(str==="true"||str==="false"){return str;}
if(str==="null"){return"null";}
var num=parseFloat(str);if(!isNaN(num)){return num.toString();}
if(str[0]==="{"){var type="needKey";var result="{";for(var i=1;i<str.length;i++){if(isBlankChar(str[i])){continue;}else if(type==="needKey"&&(str[i]==="\""||str[i]==="'")){var key=parseKey(str,i+1,str[i]);result+="\""+key+"\"";i+=key.length;i+=1;type="afterKey";}else if(type==="needKey"&&canBeKeyHead(str[i])){var key=parseKey(str,i);result+="\"";result+=key;result+="\"";i+=key.length-1;type="afterKey";}else if(type==="afterKey"&&str[i]===":"){result+=":";type=":";}else if(type===":"){var body=getBody(str,i);i=i+body.originLength-1;result+=parse(body.body);type="afterBody";}else if(type==="afterBody"||type==="needKey"){var last=i;while(str[last]===","||isBlankChar(str[last])){last++;}
if(str[last]==="}"&&last===str.length-1){while(result[result.length-1]===","){result=result.substr(0,result.length-1);}
result+="}";return result;}else if(last!==i&&result!=="{"){result+=",";type="needKey";i=last-1;}}}
throw new Error("Broken JSON object near "+result);}
if(str[0]==="["){var result="[";var type="needBody";for(var i=1;i<str.length;i++){if(" "===str[i]||"\n"===str[i]||"\t"===str[i]){continue;}else if(type==="needBody"){if(str[i]===","){result+="null,";continue;}
if(str[i]==="]"&&i===str.length-1){if(result[result.length-1]===",")result=result.substr(0,result.length-1);result+="]";return result;}
var body=getBody(str,i);i=i+body.originLength-1;result+=parse(body.body);type="afterBody";}else if(type==="afterBody"){if(str[i]===","){result+=",";type="needBody";while(str[i+1]===","||isBlankChar(str[i+1])){if(str[i+1]===",")result+="null,";i++;}}else if(str[i]==="]"&&i===str.length-1){result+="]";return result;}}}
throw new Error("Broken JSON array near "+result);}}
if($.oc===undefined)
$.oc={}
$.oc.JSON=function(json){var jsonString=parse(json);return JSON.parse(jsonString);};})();"use strict";!function(){function a(e,r,n){for(var t="",o=r;o<e.length;o++){if(n&&n===e[o])return t;if(!n&&(" "===e[o]||":"===e[o]))return t;t+=e[o],"\\"===e[o]&&o+1<e.length&&(t+=e[o+1],o++)}throw new Error("Broken JSON syntax near "+t)}function u(e,r){if('"'===e[r]||"'"===e[r]){for(var n=e[r],t=r+1;t<e.length;t++)if("\\"===e[t])n+=e[t],t+1<e.length&&(n+=e[t+1]),t++;else{if(e[t]===e[r])return{originLength:(n+=e[r]).length,body:n};n+=e[t]}throw new Error("Broken JSON string body near "+n)}if("t"===e[r]){if(e.indexOf("true",r)===r)return{originLength:"true".length,body:"true"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("f"===e[r]){if(e.indexOf("f",r)===r)return{originLength:"false".length,body:"false"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("n"===e[r]){if(e.indexOf("null",r)===r)return{originLength:"null".length,body:"null"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("-"===e[r]||"+"===e[r]||"."===e[r]||"0"<=e[r]&&e[r]<="9"){for(n="",t=r;t<e.length;t++){if(!("-"===e[t]||"+"===e[t]||"."===e[t]||"0"<=e[t]&&e[t]<="9"))return{originLength:n.length,body:n};n+=e[t]}throw new Error("Broken JSON number body near "+n)}if("{"!==e[r]&&"["!==e[r])throw new Error("Broken JSON body near "+e.substr(0<=r-5?r-5:0,50));var o=[e[r]];for(n=e[r],t=r+1;t<e.length;t++){if(n+=e[t],"\\"===e[t])t+1<e.length&&(n+=e[t+1]),t++;else if('"'===e[t])'"'===o[o.length-1]?o.pop():"'"!==o[o.length-1]&&o.push(e[t]);else if("'"===e[t])"'"===o[o.length-1]?o.pop():'"'!==o[o.length-1]&&o.push(e[t]);else if('"'!==o[o.length-1]&&"'"!==o[o.length-1])if("{"===e[t])o.push("{");else if("}"===e[t]){if("{"!==o[o.length-1])throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n);o.pop()}else if("["===e[t])o.push("[");else if("]"===e[t]){if("["!==o[o.length-1])throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n);o.pop()}if(!o.length)return{originLength:t-r,body:n}}throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n)}function s(e){return" "===e||"\n"===e||"\t"===e}void 0===$.oc&&($.oc={}),$.oc.JSON=function(e){var r=function e(r){if(!(r=r.trim()).length)throw new Error("Broken JSON object.");for(var n="";r&&","===r[0];)r=r.substr(1);if('"'===r[0]||"'"===r[0]){if(r[r.length-1]!==r[0])throw new Error("Invalid string JSON object.");for(var t='"',o=1;o<r.length;o++)if("\\"===r[o])"'"===r[o+1]||(t+=r[o]),t+=r[o+1],o++;else{if(r[o]===r[0])return t+='"';'"'===r[o]?t+='\\"':t+=r[o]}throw new Error("Invalid string JSON object.")}if("true"===r||"false"===r)return r;if("null"===r)return"null";var i,f=parseFloat(r);if(!isNaN(f))return f.toString();if("{"===r[0]){var l="needKey";for(n="{",o=1;o<r.length;o++)if(!s(r[o]))if("needKey"!==l||'"'!==r[o]&&"'"!==r[o]){if("needKey"===l&&"\\"!==(i=r[o])[0]&&("a"<=i[0]&&i[0]<="z"||"A"<=i[0]&&i[0]<="Z"||"_"===i[0]||"0"<=i[0]&&i[0]<="9"||"$"===i[0]||255<i.charCodeAt(0))){var h;n+='"',n+=h=a(r,o),n+='"',o+=h.length-1,l="afterKey"}else if("afterKey"===l&&":"===r[o])n+=":",l=":";else if(":"===l)o=o+(t=u(r,o)).originLength-1,n+=e(t.body),l="afterBody";else if("afterBody"===l||"needKey"===l){for(var g=o;","===r[g]||s(r[g]);)g++;if("}"===r[g]&&g===r.length-1){for(;","===n[n.length-1];)n=n.substr(0,n.length-1);return n+="}"}g!==o&&"{"!==n&&(n+=",",l="needKey",o=g-1)}}else n+='"'+(h=a(r,o+1,r[o]))+'"',o+=h.length,o+=1,l="afterKey";throw new Error("Broken JSON object near "+n)}if("["===r[0]){for(n="[",l="needBody",o=1;o<r.length;o++)if(" "!==r[o]&&"\n"!==r[o]&&"\t"!==r[o])if("needBody"===l){if(","===r[o]){n+="null,";continue}if("]"===r[o]&&o===r.length-1)return","===n[n.length-1]&&(n=n.substr(0,n.length-1)),n+="]";o=o+(t=u(r,o)).originLength-1,n+=e(t.body),l="afterBody"}else if("afterBody"===l)if(","===r[o])for(n+=",",l="needBody";","===r[o+1]||s(r[o+1]);)","===r[o+1]&&(n+="null,"),o++;else if("]"===r[o]&&o===r.length-1)return n+="]";throw new Error("Broken JSON array near "+n)}}(e);return JSON.parse(r)}}();if(window.jQuery===undefined){throw new Error('The jQuery library is not loaded. The OctoberCMS framework cannot be initialized.');}
if(window.jQuery===undefined){throw new Error('The jQuery library is not loaded. The OctoberCMS framework cannot be initialized.');}
if(window.jQuery.request!==undefined){throw new Error('The OctoberCMS framework is already loaded.');}
+function($){"use strict";var Request=function(element,handler,options){var $el=this.$el=$(element);this.options=options||{};if(handler===undefined){throw new Error('The request handler name is not specified.')}
if(!handler.match(/^(?:\w+\:{2})?on*/)){throw new Error('Invalid handler name. The correct handler name format is: "onEvent".')}
@ -146,7 +110,7 @@ $.fn.request.noConflict=function(){$.fn.request=old
return this}
function paramToObj(name,value){if(value===undefined)value=''
if(typeof value=='object')return value
try{return $.oc.JSON("{"+value+"}")}
try{return ocJSON("{"+value+"}")}
catch(e){throw new Error('Error parsing the '+name+' attribute value. '+e)}}
$(document).on('change','select[data-request], input[type=radio][data-request], input[type=checkbox][data-request], input[type=file][data-request]',function documentOnChange(){$(this).request()})
$(document).on('click','a[data-request], button[data-request], input[type=button][data-request], input[type=submit][data-request]',function documentOnClick(e){e.preventDefault()
@ -177,7 +141,42 @@ return false})
$(window).on('beforeunload',function documentOnBeforeUnload(){window.ocUnloading=true})
$(document).ready(function triggerRenderOnReady(){$(document).trigger('render')})
$(window).on('ajaxUpdateComplete',function triggerRenderOnAjaxUpdateComplete(){$(document).trigger('render')})
$.fn.render=function(callback){$(document).on('render',callback)}}(window.jQuery);"use strict";!function(){function a(e,r,n){for(var t="",o=r;o<e.length;o++){if(n&&n===e[o])return t;if(!n&&(" "===e[o]||":"===e[o]))return t;t+=e[o],"\\"===e[o]&&o+1<e.length&&(t+=e[o+1],o++)}throw new Error("Broken JSON syntax near "+t)}function u(e,r){if('"'===e[r]||"'"===e[r]){for(var n=e[r],t=r+1;t<e.length;t++)if("\\"===e[t])n+=e[t],t+1<e.length&&(n+=e[t+1]),t++;else{if(e[t]===e[r])return{originLength:(n+=e[r]).length,body:n};n+=e[t]}throw new Error("Broken JSON string body near "+n)}if("t"===e[r]){if(e.indexOf("true",r)===r)return{originLength:"true".length,body:"true"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("f"===e[r]){if(e.indexOf("f",r)===r)return{originLength:"false".length,body:"false"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("n"===e[r]){if(e.indexOf("null",r)===r)return{originLength:"null".length,body:"null"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("-"===e[r]||"+"===e[r]||"."===e[r]||"0"<=e[r]&&e[r]<="9"){for(n="",t=r;t<e.length;t++){if(!("-"===e[t]||"+"===e[t]||"."===e[t]||"0"<=e[t]&&e[t]<="9"))return{originLength:n.length,body:n};n+=e[t]}throw new Error("Broken JSON number body near "+n)}if("{"!==e[r]&&"["!==e[r])throw new Error("Broken JSON body near "+e.substr(0<=r-5?r-5:0,50));var o=[e[r]];for(n=e[r],t=r+1;t<e.length;t++){if(n+=e[t],"\\"===e[t])t+1<e.length&&(n+=e[t+1]),t++;else if('"'===e[t])'"'===o[o.length-1]?o.pop():"'"!==o[o.length-1]&&o.push(e[t]);else if("'"===e[t])"'"===o[o.length-1]?o.pop():'"'!==o[o.length-1]&&o.push(e[t]);else if('"'!==o[o.length-1]&&"'"!==o[o.length-1])if("{"===e[t])o.push("{");else if("}"===e[t]){if("{"!==o[o.length-1])throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n);o.pop()}else if("["===e[t])o.push("[");else if("]"===e[t]){if("["!==o[o.length-1])throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n);o.pop()}if(!o.length)return{originLength:t-r,body:n}}throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n)}function s(e){return" "===e||"\n"===e||"\t"===e}void 0===$.oc&&($.oc={}),$.oc.JSON=function(e){var r=function e(r){if(!(r=r.trim()).length)throw new Error("Broken JSON object.");for(var n="";r&&","===r[0];)r=r.substr(1);if('"'===r[0]||"'"===r[0]){if(r[r.length-1]!==r[0])throw new Error("Invalid string JSON object.");for(var t='"',o=1;o<r.length;o++)if("\\"===r[o])"'"===r[o+1]||(t+=r[o]),t+=r[o+1],o++;else{if(r[o]===r[0])return t+='"';'"'===r[o]?t+='\\"':t+=r[o]}throw new Error("Invalid string JSON object.")}if("true"===r||"false"===r)return r;if("null"===r)return"null";var i,f=parseFloat(r);if(!isNaN(f))return f.toString();if("{"===r[0]){var l="needKey";for(n="{",o=1;o<r.length;o++)if(!s(r[o]))if("needKey"!==l||'"'!==r[o]&&"'"!==r[o]){if("needKey"===l&&"\\"!==(i=r[o])[0]&&("a"<=i[0]&&i[0]<="z"||"A"<=i[0]&&i[0]<="Z"||"_"===i[0]||"0"<=i[0]&&i[0]<="9"||"$"===i[0]||255<i.charCodeAt(0))){var h;n+='"',n+=h=a(r,o),n+='"',o+=h.length-1,l="afterKey"}else if("afterKey"===l&&":"===r[o])n+=":",l=":";else if(":"===l)o=o+(t=u(r,o)).originLength-1,n+=e(t.body),l="afterBody";else if("afterBody"===l||"needKey"===l){for(var g=o;","===r[g]||s(r[g]);)g++;if("}"===r[g]&&g===r.length-1){for(;","===n[n.length-1];)n=n.substr(0,n.length-1);return n+="}"}g!==o&&"{"!==n&&(n+=",",l="needKey",o=g-1)}}else n+='"'+(h=a(r,o+1,r[o]))+'"',o+=h.length,o+=1,l="afterKey";throw new Error("Broken JSON object near "+n)}if("["===r[0]){for(n="[",l="needBody",o=1;o<r.length;o++)if(" "!==r[o]&&"\n"!==r[o]&&"\t"!==r[o])if("needBody"===l){if(","===r[o]){n+="null,";continue}if("]"===r[o]&&o===r.length-1)return","===n[n.length-1]&&(n=n.substr(0,n.length-1)),n+="]";o=o+(t=u(r,o)).originLength-1,n+=e(t.body),l="afterBody"}else if("afterBody"===l)if(","===r[o])for(n+=",",l="needBody";","===r[o+1]||s(r[o+1]);)","===r[o+1]&&(n+="null,"),o++;else if("]"===r[o]&&o===r.length-1)return n+="]";throw new Error("Broken JSON array near "+n)}}(e);return JSON.parse(r)}}();+function($){"use strict";if($.oc===undefined)
$.fn.render=function(callback){$(document).on('render',callback)}}(window.jQuery);+function(window){"use strict";function parseKey(str,pos,quote){var key="";for(var i=pos;i<str.length;i++){if(quote&&quote===str[i]){return key;}else if(!quote&&(str[i]===" "||str[i]===":")){return key;}
key+=str[i];if(str[i]==="\\"&&i+1<str.length){key+=str[i+1];i++;}}
throw new Error("Broken JSON syntax near "+key);}
function getBody(str,pos){if(str[pos]==="\""||str[pos]==="'"){var body=str[pos];for(var i=pos+1;i<str.length;i++){if(str[i]==="\\"){body+=str[i];if(i+1<str.length)body+=str[i+1];i++;}else if(str[i]===str[pos]){body+=str[pos];return{originLength:body.length,body:body};}else body+=str[i];}
throw new Error("Broken JSON string body near "+body);}
if(str[pos]==="t"){if(str.indexOf("true",pos)===pos){return{originLength:"true".length,body:"true"};}
throw new Error("Broken JSON boolean body near "+str.substr(0,pos+10));}
if(str[pos]==="f"){if(str.indexOf("f",pos)===pos){return{originLength:"false".length,body:"false"};}
throw new Error("Broken JSON boolean body near "+str.substr(0,pos+10));}
if(str[pos]==="n"){if(str.indexOf("null",pos)===pos){return{originLength:"null".length,body:"null"};}
throw new Error("Broken JSON boolean body near "+str.substr(0,pos+10));}
if(str[pos]==="-"||str[pos]==="+"||str[pos]==="."||(str[pos]>="0"&&str[pos]<="9")){var body="";for(var i=pos;i<str.length;i++){if(str[i]==="-"||str[i]==="+"||str[i]==="."||(str[i]>="0"&&str[i]<="9")){body+=str[i];}else{return{originLength:body.length,body:body};}}
throw new Error("Broken JSON number body near "+body);}
if(str[pos]==="{"||str[pos]==="["){var stack=[str[pos]];var body=str[pos];for(var i=pos+1;i<str.length;i++){body+=str[i];if(str[i]==="\\"){if(i+1<str.length)body+=str[i+1];i++;}else if(str[i]==="\""){if(stack[stack.length-1]==="\""){stack.pop();}else if(stack[stack.length-1]!=="'"){stack.push(str[i]);}}else if(str[i]==="'"){if(stack[stack.length-1]==="'"){stack.pop();}else if(stack[stack.length-1]!=="\""){stack.push(str[i]);}}else if(stack[stack.length-1]!=="\""&&stack[stack.length-1]!=="'"){if(str[i]==="{"){stack.push("{");}else if(str[i]==="}"){if(stack[stack.length-1]==="{"){stack.pop();}else{throw new Error("Broken JSON "+(str[pos]==="{"?"object":"array")+" body near "+body);}}else if(str[i]==="["){stack.push("[");}else if(str[i]==="]"){if(stack[stack.length-1]==="["){stack.pop();}else{throw new Error("Broken JSON "+(str[pos]==="{"?"object":"array")+" body near "+body);}}}
if(!stack.length){return{originLength:i-pos,body:body};}}
throw new Error("Broken JSON "+(str[pos]==="{"?"object":"array")+" body near "+body);}
throw new Error("Broken JSON body near "+str.substr((pos-5>=0)?pos-5:0,50));}
function canBeKeyHead(ch){if(ch[0]==="\\")return false;if((ch[0]>='a'&&ch[0]<='z')||(ch[0]>='A'&&ch[0]<='Z')||ch[0]==='_')return true;if(ch[0]>='0'&&ch[0]<='9')return true;if(ch[0]==='$')return true;if(ch.charCodeAt(0)>255)return true;return false;}
function isBlankChar(ch){return ch===" "||ch==="\n"||ch==="\t";}
function parse(str){str=str.trim();if(!str.length)throw new Error("Broken JSON object.");var result="";while(str&&str[0]===","){str=str.substr(1);}
if(str[0]==="\""||str[0]==="'"){if(str[str.length-1]!==str[0]){throw new Error("Invalid string JSON object.");}
var body="\"";for(var i=1;i<str.length;i++){if(str[i]==="\\"){if(str[i+1]==="'"){body+=str[i+1]}else{body+=str[i];body+=str[i+1];}
i++;}else if(str[i]===str[0]){body+="\"";return body}else if(str[i]==="\""){body+="\\\""}else body+=str[i];}
throw new Error("Invalid string JSON object.");}
if(str==="true"||str==="false"){return str;}
if(str==="null"){return"null";}
var num=parseFloat(str);if(!isNaN(num)){return num.toString();}
if(str[0]==="{"){var type="needKey";var result="{";for(var i=1;i<str.length;i++){if(isBlankChar(str[i])){continue;}else if(type==="needKey"&&(str[i]==="\""||str[i]==="'")){var key=parseKey(str,i+1,str[i]);result+="\""+key+"\"";i+=key.length;i+=1;type="afterKey";}else if(type==="needKey"&&canBeKeyHead(str[i])){var key=parseKey(str,i);result+="\"";result+=key;result+="\"";i+=key.length-1;type="afterKey";}else if(type==="afterKey"&&str[i]===":"){result+=":";type=":";}else if(type===":"){var body=getBody(str,i);i=i+body.originLength-1;result+=parse(body.body);type="afterBody";}else if(type==="afterBody"||type==="needKey"){var last=i;while(str[last]===","||isBlankChar(str[last])){last++;}
if(str[last]==="}"&&last===str.length-1){while(result[result.length-1]===","){result=result.substr(0,result.length-1);}
result+="}";return result;}else if(last!==i&&result!=="{"){result+=",";type="needKey";i=last-1;}}}
throw new Error("Broken JSON object near "+result);}
if(str[0]==="["){var result="[";var type="needBody";for(var i=1;i<str.length;i++){if(" "===str[i]||"\n"===str[i]||"\t"===str[i]){continue;}else if(type==="needBody"){if(str[i]===","){result+="null,";continue;}
if(str[i]==="]"&&i===str.length-1){if(result[result.length-1]===",")result=result.substr(0,result.length-1);result+="]";return result;}
var body=getBody(str,i);i=i+body.originLength-1;result+=parse(body.body);type="afterBody";}else if(type==="afterBody"){if(str[i]===","){result+=",";type="needBody";while(str[i+1]===","||isBlankChar(str[i+1])){if(str[i+1]===",")result+="null,";i++;}}else if(str[i]==="]"&&i===str.length-1){result+="]";return result;}}}
throw new Error("Broken JSON array near "+result);}}
window.ocJSON=function(json){var jsonString=parse(json);return JSON.parse(jsonString);};}(window);+function($){"use strict";if($.oc===undefined)
$.oc={}
var LOADER_CLASS='oc-loading';$(document).on('ajaxSetup','[data-request][data-request-flash]',function(event,context){context.options.handleErrorMessage=function(message){$.oc.flashMsg({text:message,class:'error'})}
context.options.handleFlashMessage=function(message,type){$.oc.flashMsg({text:message,class:type})}})

View File

@ -1,5 +1,4 @@
/*
=require october.parser.js
=require framework.js
=require framework.extras.js
*/
*/

View File

@ -2,12 +2,9 @@
* OctoberCMS: front-end JavaScript extras
* http://octobercms.com
* ========================================================================
* Copyright 2016 Alexey Bobkov, Samuel Georges
* Copyright 2016-2020 Alexey Bobkov, Samuel Georges
* ======================================================================== */
/* October CMS JSON Parser */
"use strict";!function(){function a(e,r,n){for(var t="",o=r;o<e.length;o++){if(n&&n===e[o])return t;if(!n&&(" "===e[o]||":"===e[o]))return t;t+=e[o],"\\"===e[o]&&o+1<e.length&&(t+=e[o+1],o++)}throw new Error("Broken JSON syntax near "+t)}function u(e,r){if('"'===e[r]||"'"===e[r]){for(var n=e[r],t=r+1;t<e.length;t++)if("\\"===e[t])n+=e[t],t+1<e.length&&(n+=e[t+1]),t++;else{if(e[t]===e[r])return{originLength:(n+=e[r]).length,body:n};n+=e[t]}throw new Error("Broken JSON string body near "+n)}if("t"===e[r]){if(e.indexOf("true",r)===r)return{originLength:"true".length,body:"true"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("f"===e[r]){if(e.indexOf("f",r)===r)return{originLength:"false".length,body:"false"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("n"===e[r]){if(e.indexOf("null",r)===r)return{originLength:"null".length,body:"null"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("-"===e[r]||"+"===e[r]||"."===e[r]||"0"<=e[r]&&e[r]<="9"){for(n="",t=r;t<e.length;t++){if(!("-"===e[t]||"+"===e[t]||"."===e[t]||"0"<=e[t]&&e[t]<="9"))return{originLength:n.length,body:n};n+=e[t]}throw new Error("Broken JSON number body near "+n)}if("{"!==e[r]&&"["!==e[r])throw new Error("Broken JSON body near "+e.substr(0<=r-5?r-5:0,50));var o=[e[r]];for(n=e[r],t=r+1;t<e.length;t++){if(n+=e[t],"\\"===e[t])t+1<e.length&&(n+=e[t+1]),t++;else if('"'===e[t])'"'===o[o.length-1]?o.pop():"'"!==o[o.length-1]&&o.push(e[t]);else if("'"===e[t])"'"===o[o.length-1]?o.pop():'"'!==o[o.length-1]&&o.push(e[t]);else if('"'!==o[o.length-1]&&"'"!==o[o.length-1])if("{"===e[t])o.push("{");else if("}"===e[t]){if("{"!==o[o.length-1])throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n);o.pop()}else if("["===e[t])o.push("[");else if("]"===e[t]){if("["!==o[o.length-1])throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n);o.pop()}if(!o.length)return{originLength:t-r,body:n}}throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n)}function s(e){return" "===e||"\n"===e||"\t"===e}void 0===$.oc&&($.oc={}),$.oc.JSON=function(e){var r=function e(r){if(!(r=r.trim()).length)throw new Error("Broken JSON object.");for(var n="";r&&","===r[0];)r=r.substr(1);if('"'===r[0]||"'"===r[0]){if(r[r.length-1]!==r[0])throw new Error("Invalid string JSON object.");for(var t='"',o=1;o<r.length;o++)if("\\"===r[o])"'"===r[o+1]||(t+=r[o]),t+=r[o+1],o++;else{if(r[o]===r[0])return t+='"';'"'===r[o]?t+='\\"':t+=r[o]}throw new Error("Invalid string JSON object.")}if("true"===r||"false"===r)return r;if("null"===r)return"null";var i,f=parseFloat(r);if(!isNaN(f))return f.toString();if("{"===r[0]){var l="needKey";for(n="{",o=1;o<r.length;o++)if(!s(r[o]))if("needKey"!==l||'"'!==r[o]&&"'"!==r[o]){if("needKey"===l&&"\\"!==(i=r[o])[0]&&("a"<=i[0]&&i[0]<="z"||"A"<=i[0]&&i[0]<="Z"||"_"===i[0]||"0"<=i[0]&&i[0]<="9"||"$"===i[0]||255<i.charCodeAt(0))){var h;n+='"',n+=h=a(r,o),n+='"',o+=h.length-1,l="afterKey"}else if("afterKey"===l&&":"===r[o])n+=":",l=":";else if(":"===l)o=o+(t=u(r,o)).originLength-1,n+=e(t.body),l="afterBody";else if("afterBody"===l||"needKey"===l){for(var g=o;","===r[g]||s(r[g]);)g++;if("}"===r[g]&&g===r.length-1){for(;","===n[n.length-1];)n=n.substr(0,n.length-1);return n+="}"}g!==o&&"{"!==n&&(n+=",",l="needKey",o=g-1)}}else n+='"'+(h=a(r,o+1,r[o]))+'"',o+=h.length,o+=1,l="afterKey";throw new Error("Broken JSON object near "+n)}if("["===r[0]){for(n="[",l="needBody",o=1;o<r.length;o++)if(" "!==r[o]&&"\n"!==r[o]&&"\t"!==r[o])if("needBody"===l){if(","===r[o]){n+="null,";continue}if("]"===r[o]&&o===r.length-1)return","===n[n.length-1]&&(n=n.substr(0,n.length-1)),n+="]";o=o+(t=u(r,o)).originLength-1,n+=e(t.body),l="afterBody"}else if("afterBody"===l)if(","===r[o])for(n+=",",l="needBody";","===r[o+1]||s(r[o+1]);)","===r[o+1]&&(n+="null,"),o++;else if("]"===r[o]&&o===r.length-1)return n+="]";throw new Error("Broken JSON array near "+n)}}(e);return JSON.parse(r)}}();
+function ($) { "use strict";
if ($.oc === undefined)
$.oc = {}

View File

@ -2,12 +2,9 @@
* OctoberCMS: front-end JavaScript framework
* http://octobercms.com
* ========================================================================
* Copyright 2017 Alexey Bobkov, Samuel Georges
* Copyright 2016-2020 Alexey Bobkov, Samuel Georges
* ======================================================================== */
/* October CMS JSON Parser */
"use strict";!function(){function a(e,r,n){for(var t="",o=r;o<e.length;o++){if(n&&n===e[o])return t;if(!n&&(" "===e[o]||":"===e[o]))return t;t+=e[o],"\\"===e[o]&&o+1<e.length&&(t+=e[o+1],o++)}throw new Error("Broken JSON syntax near "+t)}function u(e,r){if('"'===e[r]||"'"===e[r]){for(var n=e[r],t=r+1;t<e.length;t++)if("\\"===e[t])n+=e[t],t+1<e.length&&(n+=e[t+1]),t++;else{if(e[t]===e[r])return{originLength:(n+=e[r]).length,body:n};n+=e[t]}throw new Error("Broken JSON string body near "+n)}if("t"===e[r]){if(e.indexOf("true",r)===r)return{originLength:"true".length,body:"true"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("f"===e[r]){if(e.indexOf("f",r)===r)return{originLength:"false".length,body:"false"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("n"===e[r]){if(e.indexOf("null",r)===r)return{originLength:"null".length,body:"null"};throw new Error("Broken JSON boolean body near "+e.substr(0,r+10))}if("-"===e[r]||"+"===e[r]||"."===e[r]||"0"<=e[r]&&e[r]<="9"){for(n="",t=r;t<e.length;t++){if(!("-"===e[t]||"+"===e[t]||"."===e[t]||"0"<=e[t]&&e[t]<="9"))return{originLength:n.length,body:n};n+=e[t]}throw new Error("Broken JSON number body near "+n)}if("{"!==e[r]&&"["!==e[r])throw new Error("Broken JSON body near "+e.substr(0<=r-5?r-5:0,50));var o=[e[r]];for(n=e[r],t=r+1;t<e.length;t++){if(n+=e[t],"\\"===e[t])t+1<e.length&&(n+=e[t+1]),t++;else if('"'===e[t])'"'===o[o.length-1]?o.pop():"'"!==o[o.length-1]&&o.push(e[t]);else if("'"===e[t])"'"===o[o.length-1]?o.pop():'"'!==o[o.length-1]&&o.push(e[t]);else if('"'!==o[o.length-1]&&"'"!==o[o.length-1])if("{"===e[t])o.push("{");else if("}"===e[t]){if("{"!==o[o.length-1])throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n);o.pop()}else if("["===e[t])o.push("[");else if("]"===e[t]){if("["!==o[o.length-1])throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n);o.pop()}if(!o.length)return{originLength:t-r,body:n}}throw new Error("Broken JSON "+("{"===e[r]?"object":"array")+" body near "+n)}function s(e){return" "===e||"\n"===e||"\t"===e}void 0===$.oc&&($.oc={}),$.oc.JSON=function(e){var r=function e(r){if(!(r=r.trim()).length)throw new Error("Broken JSON object.");for(var n="";r&&","===r[0];)r=r.substr(1);if('"'===r[0]||"'"===r[0]){if(r[r.length-1]!==r[0])throw new Error("Invalid string JSON object.");for(var t='"',o=1;o<r.length;o++)if("\\"===r[o])"'"===r[o+1]||(t+=r[o]),t+=r[o+1],o++;else{if(r[o]===r[0])return t+='"';'"'===r[o]?t+='\\"':t+=r[o]}throw new Error("Invalid string JSON object.")}if("true"===r||"false"===r)return r;if("null"===r)return"null";var i,f=parseFloat(r);if(!isNaN(f))return f.toString();if("{"===r[0]){var l="needKey";for(n="{",o=1;o<r.length;o++)if(!s(r[o]))if("needKey"!==l||'"'!==r[o]&&"'"!==r[o]){if("needKey"===l&&"\\"!==(i=r[o])[0]&&("a"<=i[0]&&i[0]<="z"||"A"<=i[0]&&i[0]<="Z"||"_"===i[0]||"0"<=i[0]&&i[0]<="9"||"$"===i[0]||255<i.charCodeAt(0))){var h;n+='"',n+=h=a(r,o),n+='"',o+=h.length-1,l="afterKey"}else if("afterKey"===l&&":"===r[o])n+=":",l=":";else if(":"===l)o=o+(t=u(r,o)).originLength-1,n+=e(t.body),l="afterBody";else if("afterBody"===l||"needKey"===l){for(var g=o;","===r[g]||s(r[g]);)g++;if("}"===r[g]&&g===r.length-1){for(;","===n[n.length-1];)n=n.substr(0,n.length-1);return n+="}"}g!==o&&"{"!==n&&(n+=",",l="needKey",o=g-1)}}else n+='"'+(h=a(r,o+1,r[o]))+'"',o+=h.length,o+=1,l="afterKey";throw new Error("Broken JSON object near "+n)}if("["===r[0]){for(n="[",l="needBody",o=1;o<r.length;o++)if(" "!==r[o]&&"\n"!==r[o]&&"\t"!==r[o])if("needBody"===l){if(","===r[o]){n+="null,";continue}if("]"===r[o]&&o===r.length-1)return","===n[n.length-1]&&(n=n.substr(0,n.length-1)),n+="]";o=o+(t=u(r,o)).originLength-1,n+=e(t.body),l="afterBody"}else if("afterBody"===l)if(","===r[o])for(n+=",",l="needBody";","===r[o+1]||s(r[o+1]);)","===r[o+1]&&(n+="null,"),o++;else if("]"===r[o]&&o===r.length-1)return n+="]";throw new Error("Broken JSON array near "+n)}}(e);return JSON.parse(r)}}();
if (window.jQuery === undefined) {
throw new Error('The jQuery library is not loaded. The OctoberCMS framework cannot be initialized.');
}
@ -461,7 +458,7 @@ if (window.jQuery.request !== undefined) {
if (typeof value == 'object') return value
try {
return $.oc.JSON("{" + value + "}")
return ocJSON("{" + value + "}")
}
catch (e) {
throw new Error('Error parsing the '+name+' attribute value. '+e)
@ -549,3 +546,328 @@ if (window.jQuery.request !== undefined) {
}
}(window.jQuery);
/*
* October CMS JSON Parser
*/
+function(window) { "use strict";
function parseKey(str, pos, quote) {
var key = "";
for (var i = pos; i < str.length; i++) {
if (quote && quote === str[i]) {
return key;
} else if (!quote && (str[i] === " " || str[i] === ":")) {
return key;
}
key += str[i];
if (str[i] === "\\" && i + 1 < str.length) {
key += str[i + 1];
i++;
}
}
throw new Error("Broken JSON syntax near " + key);
}
function getBody(str, pos) {
// parse string body
if (str[pos] === "\"" || str[pos] === "'") {
var body = str[pos];
for (var i = pos + 1; i < str.length; i++) {
if (str[i] === "\\") {
body += str[i];
if (i + 1 < str.length) body += str[i + 1];
i++;
} else if (str[i] === str[pos]) {
body += str[pos];
return {
originLength: body.length,
body: body
};
} else body += str[i];
}
throw new Error("Broken JSON string body near " + body);
}
// parse true / false
if (str[pos] === "t") {
if (str.indexOf("true", pos) === pos) {
return {
originLength: "true".length,
body: "true"
};
}
throw new Error("Broken JSON boolean body near " + str.substr(0, pos + 10));
}
if (str[pos] === "f") {
if (str.indexOf("f", pos) === pos) {
return {
originLength: "false".length,
body: "false"
};
}
throw new Error("Broken JSON boolean body near " + str.substr(0, pos + 10));
}
// parse null
if (str[pos] === "n") {
if (str.indexOf("null", pos) === pos) {
return {
originLength: "null".length,
body: "null"
};
}
throw new Error("Broken JSON boolean body near " + str.substr(0, pos + 10));
}
// parse number
if (str[pos] === "-" || str[pos] === "+" || str[pos] === "." || (str[pos] >= "0" && str[pos] <= "9")) {
var body = "";
for (var i = pos; i < str.length; i++) {
if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) {
body += str[i];
} else {
return {
originLength: body.length,
body: body
};
}
}
throw new Error("Broken JSON number body near " + body);
}
// parse object
if (str[pos] === "{" || str[pos] === "[") {
var stack = [str[pos]];
var body = str[pos];
for (var i = pos + 1; i < str.length; i++) {
body += str[i];
if (str[i] === "\\") {
if (i + 1 < str.length) body += str[i + 1];
i++;
} else if (str[i] === "\"") {
if (stack[stack.length - 1] === "\"") {
stack.pop();
} else if (stack[stack.length - 1] !== "'") {
stack.push(str[i]);
}
} else if (str[i] === "'") {
if (stack[stack.length - 1] === "'") {
stack.pop();
} else if (stack[stack.length - 1] !== "\"") {
stack.push(str[i]);
}
} else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") {
if (str[i] === "{") {
stack.push("{");
} else if (str[i] === "}") {
if (stack[stack.length - 1] === "{") {
stack.pop();
} else {
throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body);
}
} else if (str[i] === "[") {
stack.push("[");
} else if (str[i] === "]") {
if (stack[stack.length - 1] === "[") {
stack.pop();
} else {
throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body);
}
}
}
if (!stack.length) {
return {
originLength: i - pos,
body: body
};
}
}
throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body);
}
throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50));
}
function canBeKeyHead(ch) {
if (ch[0] === "\\") return false;
if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true;
if (ch[0] >= '0' && ch[0] <= '9') return true;
if (ch[0] === '$') return true;
if (ch.charCodeAt(0) > 255) return true;
return false;
}
function isBlankChar(ch) {
return ch === " " || ch === "\n" || ch === "\t";
}
function parse(str) {
str = str.trim();
if (!str.length) throw new Error("Broken JSON object.");
var result = "";
/*
* the mistake ','
*/
while (str && str[0] === ",") {
str = str.substr(1);
}
/*
* string
*/
if (str[0] === "\"" || str[0] === "'") {
if (str[str.length - 1] !== str[0]) {
throw new Error("Invalid string JSON object.");
}
var body = "\"";
for (var i = 1; i < str.length; i++) {
if (str[i] === "\\") {
if (str[i + 1] === "'") {
body += str[i + 1]
} else {
body += str[i];
body += str[i + 1];
}
i++;
} else if (str[i] === str[0]) {
body += "\"";
return body
} else if (str[i] === "\"") {
body += "\\\""
} else body += str[i];
}
throw new Error("Invalid string JSON object.");
}
/*
* boolean
*/
if (str === "true" || str === "false") {
return str;
}
/*
* null
*/
if (str === "null") {
return "null";
}
/*
* number
*/
var num = parseFloat(str);
if (!isNaN(num)) {
return num.toString();
}
/*
* object
*/
if (str[0] === "{") {
var type = "needKey";
var result = "{";
for (var i = 1; i < str.length; i++) {
if (isBlankChar(str[i])) {
continue;
} else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) {
var key = parseKey(str, i + 1, str[i]);
result += "\"" + key + "\"";
i += key.length;
i += 1;
type = "afterKey";
} else if (type === "needKey" && canBeKeyHead(str[i])) {
var key = parseKey(str, i);
result += "\"";
result += key;
result += "\"";
i += key.length - 1;
type = "afterKey";
} else if (type === "afterKey" && str[i] === ":") {
result += ":";
type = ":";
} else if (type === ":") {
var body = getBody(str, i);
i = i + body.originLength - 1;
result += parse(body.body);
type = "afterBody";
} else if (type === "afterBody" || type === "needKey") {
var last = i;
while (str[last] === "," || isBlankChar(str[last])) {
last++;
}
if (str[last] === "}" && last === str.length - 1) {
while (result[result.length - 1] === ",") {
result = result.substr(0, result.length - 1);
}
result += "}";
return result;
} else if (last !== i && result !== "{") {
result += ",";
type = "needKey";
i = last - 1;
}
}
}
throw new Error("Broken JSON object near " + result);
}
/*
* array
*/
if (str[0] === "[") {
var result = "[";
var type = "needBody";
for (var i = 1; i < str.length; i++) {
if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) {
continue;
} else if (type === "needBody") {
if (str[i] === ",") {
result += "null,";
continue;
}
if (str[i] === "]" && i === str.length - 1) {
if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1);
result += "]";
return result;
}
var body = getBody(str, i);
i = i + body.originLength - 1;
result += parse(body.body);
type = "afterBody";
} else if (type === "afterBody") {
if (str[i] === ",") {
result += ",";
type = "needBody";
// deal with mistake ","
while (str[i + 1] === "," || isBlankChar(str[i + 1])) {
if (str[i + 1] === ",") result += "null,";
i++;
}
} else if (str[i] === "]" && i === str.length - 1) {
result += "]";
return result;
}
}
}
throw new Error("Broken JSON array near " + result);
}
}
// Global function
window.ocJSON = function(json) {
var jsonString = parse(json);
return JSON.parse(jsonString);
};
}(window);

View File

@ -1,16 +1,13 @@
/*
* October CMS JSON Parser
*/
"use strict";
/* ========================================================================
* OctoberCMS: front-end JavaScript parser
* http://octobercms.com
*
* (Note: This lib is included manually in the framework.js file)
* ========================================================================
* Copyright 2016-2020 Alexey Bobkov, Samuel Georges
* ======================================================================== */
(function() {
/**
* parse key
* @param str
* @param pos
* @param quote
* @returns {string}
*/
+function(window) { "use strict";
function parseKey(str, pos, quote) {
var key = "";
for (var i = pos; i < str.length; i++) {
@ -30,12 +27,6 @@
throw new Error("Broken JSON syntax near " + key);
}
/*
* get body
* @param str
* @param pos
* @returns {*}
*/
function getBody(str, pos) {
// parse string body
if (str[pos] === "\"" || str[pos] === "'") {
@ -155,11 +146,6 @@
throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50));
}
/*
* This is a char can be key head
* @param ch
* @returns {boolean}
*/
function canBeKeyHead(ch) {
if (ch[0] === "\\") return false;
if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true;
@ -173,10 +159,6 @@
return ch === " " || ch === "\n" || ch === "\t";
}
/*
* parse JSON
* @param str
*/
function parse(str) {
str = str.trim();
if (!str.length) throw new Error("Broken JSON object.");
@ -339,17 +321,10 @@
}
}
/*
* parse October JSON string into JSON object
* @param json
* @returns {*}
*/
if ($.oc === undefined)
$.oc = {}
$.oc.JSON = function(json) {
// Global function
window.ocJSON = function(json) {
var jsonString = parse(json);
return JSON.parse(jsonString);
};
})();
}(window);

View File

@ -1,6 +1,6 @@
/*
* The autcomplete plugin, a forked version of Bootstrap's original typeahead plugin.
*
*
* Data attributes:
* - data-control="autocomplete" - enables the autocomplete plugin
*
@ -378,7 +378,7 @@
if (typeof value == 'object') return value
try {
return $.oc.JSON("{" + value + "}")
return ocJSON("{" + value + "}")
}
catch (e) {
throw new Error('Error parsing the '+name+' attribute value. '+e)

View File

@ -39,7 +39,7 @@
tickLength: 5
},
selection: { mode: "x" },
grid: {
grid: {
markingsColor: "rgba(0,0,0, 0.02)",
backgroundColor: { colors: ["#fff", "#fff"] },
borderColor: "#7bafcc",
@ -80,7 +80,7 @@
var parsedOptions = {}
try {
parsedOptions = $.oc.JSON("{" + value + "}");
parsedOptions = ocJSON("{" + value + "}");
} catch (e) {
throw new Error('Error parsing the data-chart-options attribute value. '+e);
}
@ -102,15 +102,15 @@
if (this.options.zoomable) {
this.$el.on("plotselected", function (event, ranges) {
var newCoords = {
xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to }
var newCoords = {
xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to }
}
$.plot(self.$el, self.fullDataSet, $.extend(true, {}, self.chartOptions, newCoords))
self.resetZoomLink.show()
});
}
/*
* Markings Helper
*/
@ -121,14 +121,14 @@
function weekendAreas(axes) {
var markings = [],
d = new Date(axes.xaxis.min);
// Go to the first Saturday
d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 1) % 7))
d.setUTCSeconds(0)
d.setUTCMinutes(0)
d.setUTCHours(0)
var i = d.getTime()
do {
// When we don't set yaxis, the rectangle automatically
// extends to infinity upwards and downwards
@ -178,7 +178,7 @@
}
/*
* Adds a data set to the chart.
* Adds a data set to the chart.
* See https://github.com/flot/flot/blob/master/API.md#data-format for the list
* of supported data set options.
*/

View File

@ -395,7 +395,7 @@
if (typeof value == 'object') return value
try {
return $.oc.JSON("{" + value + "}")
return ocJSON("{" + value + "}")
}
catch (e) {
throw new Error('Error parsing the '+name+' attribute value. '+e)

View File

@ -2797,7 +2797,7 @@ $.fn.autocomplete.noConflict=function(){$.fn.autocomplete=old
return this}
function paramToObj(name,value){if(value===undefined)value=''
if(typeof value=='object')return value
try{return $.oc.JSON("{"+value+"}")}
try{return ocJSON("{"+value+"}")}
catch(e){throw new Error('Error parsing the '+name+' attribute value. '+e)}}
$(document).on('focus.autocomplete.data-api','[data-control="autocomplete"]',function(e){var $this=$(this)
if($this.data('autocomplete'))return
@ -3856,7 +3856,7 @@ $.fn.popup.noConflict=function(){$.fn.popup=old
return this}
function paramToObj(name,value){if(value===undefined)value=''
if(typeof value=='object')return value
try{return $.oc.JSON("{"+value+"}")}
try{return ocJSON("{"+value+"}")}
catch(e){throw new Error('Error parsing the '+name+' attribute value. '+e)}}
$(document).on('click.oc.popup','[data-control="popup"]',function(event){event.preventDefault()
$(this).popup()});$(document).on('ajaxPromise','[data-popup-load-indicator]',function(event,context){if($(this).data('request')!=context.handler)return
@ -3899,7 +3899,7 @@ $.oc.chartUtils=new ChartUtils();}(window.jQuery);+function($){"use strict";var
this.chartOptions={xaxis:{mode:"time",tickLength:5},selection:{mode:"x"},grid:{markingsColor:"rgba(0,0,0, 0.02)",backgroundColor:{colors:["#fff","#fff"]},borderColor:"#7bafcc",borderWidth:0,color:"#ddd",hoverable:true,clickable:true,labelMargin:10},series:{lines:{show:true,fill:true},points:{show:true}},tooltip:true,tooltipOpts:{defaultTheme:false,content:"%x: <strong>%y</strong>",dateFormat:"%y-%0m-%0d",shifts:{x:10,y:20}},legend:{show:true,noColumns:2}}
this.defaultDataSetOptions={shadowSize:0}
var parsedOptions={}
try{parsedOptions=$.oc.JSON("{"+value+"}");}catch(e){throw new Error('Error parsing the data-chart-options attribute value. '+e);}
try{parsedOptions=ocJSON("{"+value+"}");}catch(e){throw new Error('Error parsing the data-chart-options attribute value. '+e);}
this.chartOptions=$.extend({},this.chartOptions,parsedOptions)
this.options=options
this.$el=$(element)