diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..d749072 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,34 @@ +{ + "env": { + "browser": true, + "commonjs": true, + "es6": true + }, + "extends": "wordpress", + "parser": "babel-eslint", + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + "rules": { + "no-unused-vars": [ + "warn", + { + "args": "after-used", + "ignoreRestSiblings": false, + "vars": "all" + } + ], + "prefer-const": [ + "warn", + { + "destructuring": "any", + "ignoreReadBeforeAssign": false + } + ], + "yoda": [ + 2, + "never" + ] + } +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c49ebb..a1a0fd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [3.0.5] - 2019-01-30 + ### Added - webpack compiling for dustpress.js - js sourcemaps +- .eslintrc.json + +### Changed +- Changed the format of dustpress.js to a class ## [3.0.4] - 2018-08-09 diff --git a/js/DPRequest.js b/js/DPRequest.js new file mode 100644 index 0000000..cded2de --- /dev/null +++ b/js/DPRequest.js @@ -0,0 +1,180 @@ +export default class DPRequest { + + /** + * Request path + * + * @type {String} + */ + path = ''; + + /** + * Default instance params + * + * @type {Object} + */ + params = { + get: '', + type: 'post', + tidy: false, + render: false, + partial: null, + upload: false, + data: false, + url: null, + bypassMainQuery: true, + contentType: 'application/json', + token: '', + success: () => {}, + error: () => {}, + uploadProgress: () => {}, + downloadProgress: () => {}, + start: () => {}, + complete: () => {} + }; + + /** + * Construct the dustpress request + * + * @param {Object} params Params to use in request + */ + constructor( path, params = {}) { + this.path = path; + + // Override default params with given ones + this.params = Object.assign( this.params, params ); + } + + send() { + if ( this.params.get.length && ! this.params.get.startsWith( '?' ) ) { + this.params.get = '?' + this.params.get; + } + + const date = new Date(); + date.setTime( date.getTime() + ( 24 * 60 * 60 * 1000 ) ); + + // Set the cookie for the token + document.cookie = 'dpjs_token=' + this.params.token + '; expires=' + date.toGMTString() + '; path=/'; + + const options = { + url: ( this.params.url || dustpressjs_endpoint || ( window.location + this.params.get ) ), + method: this.params.type, + contentType: this.params.contentType, + data: { + dustpress_data: { + path: this.path, + args: this.params.args, + render: this.params.render, + tidy: this.params.tidy, + partial: this.params.partial, + data: this.params.data, + token: this.params.token, + bypassMainQuery: this.params.bypassMainQuery + } + } + }; + + // Stringify data so it can be sent + options.data = JSON.stringify( options.data ); + + if ( this.params.upload ) { + options.xhr = () => this.xhrUpload(); + } + + this.params.start(); + + this.params.successHandler = ( data, textStatus, jqXHR ) => this.successHandler( data, textStatus, jqXHR ); + this.params.errorHandler = ( jqXHR, textStatus, errorThrown ) => this.errorHandler( jqXHR, textStatus, errorThrown ); + this.params.uploadProgressHandler = ( event ) => this.uploadDownloadProgressHandler( event ); + this.params.downloadProgressHandler = ( event ) => this.uploadDownloadProgressHandler( event ); + + return $.ajax( options ) + .done( ( data, textStatus, jqXHR ) => this.params.successHandler( data, textStatus, jqXHR ) ) + .fail( ( jqXHR, textStatus, errorThrown ) => this.params.errorHandler( jqXHR, textStatus, errorThrown ) ) + .always( ( dataOrXhr, textStatus, xhrOrError ) => this.params.complete( dataOrXhr, textStatus, xhrOrError ) ); + } + + /** + * Handle ajax success + * + * @param {string|mixed} data Data retrieved by ajax call. + * @param {string} textStatus Response status. + * @param {jqXHR} jqXHR Superset of the browser's native XMLHttpRequest object. + */ + successHandler( data, textStatus, jqXHR ) { + let parsed; + + if ( typeof data === 'string' ) { + parsed = $.parseJSON( data ); + } else { + parsed = data; + } + + // Expire CSRF cookie + document.cookie = 'dpjs_token=; expires=-1; path=/'; + + // Add to debugger data if it exists + if ( window.DustPressDebugger ) { + this.addToDebugger( parsed ); + } + + if ( parsed && ! parsed.error ) { + this.params.success( parsed.success, parsed.data, textStatus, jqXHR ); + } else { + this.params.error( parsed, textStatus, jqXHR ); + } + } + + /** + * Handle file uploads + */ + xhrUpload() { + const xhr = new window.XMLHttpRequest(); + + xhr.upload.addEventListener( 'progress', ( event ) => this.params.uploadProgressHandler( event ), false ); + xhr.addEventListener( 'progress', ( event ) => this.params.uploadDownloadProgressHandler( event ), false ); + } + + /** + * Handle errors. + * + * @param {jqXHR} jqXHR Superset of the browser's native XMLHttpRequest object. + * @param {string} textStatus Response status. + * @param {mixed} errorThrown Ajax call error. + */ + errorHandler( jqXHR, textStatus, errorThrown ) { + + // Expire CSRF cookie + document.cookie = 'dpjs_token=; expires=-1; path=/'; + + this.params.error({error: errorThrown}, textStatus, jqXHR ); + } + + /** + * Handle uploar or download progress. + * + * @param {object} event Event data. + */ + uploadDownloadProgressHandler( event ) { + if ( event.lengthComputable ) { + const complete = ( event.loaded / event.total ); + + this.params.downloadProgress( complete ); + } + } + + /** + * Add called data to dustpress debugger + * + * @param {object} parsed Parsed data. + */ + addToDebugger( parsed ) { + delete this.params.params.success; + delete this.params.params.error; + + const debug = { + params: this.params.params, + data: parsed.debug ? parsed.debug : parsed + }; + window.DustPressDebugger.extend( debug, this.params.path ); + } +} diff --git a/js/dustpress-min.js b/js/dustpress-min.js index 4bd8045..ebfd466 100644 --- a/js/dustpress-min.js +++ b/js/dustpress-min.js @@ -1,2 +1,2 @@ -!function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){(function(e){window.DustPress=function(e,r,t){var n={defaults:{type:"post",tidy:!1,render:!1,partial:null,upload:!1,data:!1,url:null,bypassMainQuery:!0,success:function(){},error:function(){},uploadProgress:function(){},downloadProgress:function(){},contentType:"application/json"},start:function(){},complete:function(){}};if(void 0!==e.crypto&&"function"==typeof e.crypto.getRandomValues){n.token="";for(var o=0;o<4;o++)n.token+=e.crypto.getRandomValues(new Uint32Array(1))}else n.token=Math.random()+""+Math.random();return n.ajax=function(o,a){var s=t.extend({},n.defaults,a),d={};d.type=s.type,d.success=s.success,d.error=s.error,d.url=s.url,d.uploadProgress=s.uploadProgress,d.downloadProgress=s.downloadProgress,d.get=s.get?a.get:"",d.path=o,d.args=s.args,d.data=s.data,d.partial=s.partial,d.render=s.render,d.tidy=s.tidy,d.upload=s.upload,d.contentType=s.contentType,d.bypassMainQuery=s.bypassMainQuery,d.params=a,d.start=n.start,d.complete=n.complete,d.get.length&&!d.get.startsWith("?")&&(d.get="?"+d.get);var u=new Date;u.setTime(u.getTime()+864e5),r.cookie="dpjs_token="+n.token+"; expires="+u.toGMTString()+"; path=/";var l={url:d.url||dustpressjs_endpoint||e.location+d.get,method:d.type,contentType:d.contentType,data:{dustpress_data:{path:o,args:d.args,render:d.render,tidy:d.tidy,partial:d.partial,data:d.data,token:n.token,bypassMainQuery:d.bypassMainQuery}}};return l.data=JSON.stringify(l.data),d.upload&&(l.xhr=function(){var r=new e.XMLHttpRequest;r.upload.addEventListener("progress",d.uploadProgressHandler,!1),r.addEventListener("progress",d.downloadProgressHandler,!1)}),d.start(),d.successHandler=function(n,o,a){var s;if(s="string"==typeof n?t.parseJSON(n):n,r.cookie="dpjs_token=; expires=-1; path=/",e.DustPressDebugger){delete d.params.success,delete d.params.error;var u={params:d.params,data:s.debug?s.debug:s};e.DustPressDebugger.extend(u,d.path)}s&&!s.error?d.success(s.success,s.data,o,a):d.error(s,o,a)},d.errorHandler=function(e,t,n){r.cookie="dpjs_token=; expires=-1; path=/",d.error({error:n},t,e)},d.uploadProgressHandler=function(e){if(e.lengthComputable){var r=e.loaded/e.total;d.uploadProgress(r)}},d.downloadProgressHandler=function(e){if(e.lengthComputable){var r=e.loaded/e.total;d.downloadProgress(r)}},t.ajax(l).done(d.successHandler).fail(d.errorHandler).always(d.complete)},n}(window,document,e),window.dp=window.DustPress.ajax}).call(this,t(1))},function(e,r){e.exports=jQuery}]); +!function(e){var r={};function t(a){if(r[a])return r[a].exports;var n=r[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,t),n.l=!0,n.exports}t.m=e,t.c=r,t.d=function(e,r,a){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:a})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(t.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(a,n,function(r){return e[r]}.bind(null,n));return a},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=1)}([function(e,r,t){"use strict";(function(e){function a(e,r){for(var t=0;t1&&void 0!==arguments[1]?arguments[1]:{};!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r),n(this,"path",""),n(this,"params",{get:"",type:"post",tidy:!1,render:!1,partial:null,upload:!1,data:!1,url:null,bypassMainQuery:!0,contentType:"application/json",token:"",success:function(){},error:function(){},uploadProgress:function(){},downloadProgress:function(){},start:function(){},complete:function(){}}),this.path=e,this.params=Object.assign(this.params,t)}var t,s,o;return t=r,(s=[{key:"send",value:function(){var r=this;this.params.get.length&&!this.params.get.startsWith("?")&&(this.params.get="?"+this.params.get);var t=new Date;t.setTime(t.getTime()+864e5),document.cookie="dpjs_token="+this.params.token+"; expires="+t.toGMTString()+"; path=/";var a={url:this.params.url||dustpressjs_endpoint||window.location+this.params.get,method:this.params.type,contentType:this.params.contentType,data:{dustpress_data:{path:this.path,args:this.params.args,render:this.params.render,tidy:this.params.tidy,partial:this.params.partial,data:this.params.data,token:this.params.token,bypassMainQuery:this.params.bypassMainQuery}}};return a.data=JSON.stringify(a.data),this.params.upload&&(a.xhr=function(){return r.xhrUpload()}),this.params.start(),this.params.successHandler=function(e,t,a){return r.successHandler(e,t,a)},this.params.errorHandler=function(e,t,a){return r.errorHandler(e,t,a)},this.params.uploadProgressHandler=function(e){return r.uploadDownloadProgressHandler(e)},this.params.downloadProgressHandler=function(e){return r.uploadDownloadProgressHandler(e)},e.ajax(a).done(function(e,t,a){return r.params.successHandler(e,t,a)}).fail(function(e,t,a){return r.params.errorHandler(e,t,a)}).always(function(e,t,a){return r.params.complete(e,t,a)})}},{key:"successHandler",value:function(r,t,a){var n;n="string"==typeof r?e.parseJSON(r):r,document.cookie="dpjs_token=; expires=-1; path=/",window.DustPressDebugger&&this.addToDebugger(n),n&&!n.error?this.params.success(n.success,n.data,t,a):this.params.error(n,t,a)}},{key:"xhrUpload",value:function(){var e=this,r=new window.XMLHttpRequest;r.upload.addEventListener("progress",function(r){return e.params.uploadProgressHandler(r)},!1),r.addEventListener("progress",function(r){return e.params.uploadDownloadProgressHandler(r)},!1)}},{key:"errorHandler",value:function(e,r,t){document.cookie="dpjs_token=; expires=-1; path=/",this.params.error({error:t},r,e)}},{key:"uploadDownloadProgressHandler",value:function(e){if(e.lengthComputable){var r=e.loaded/e.total;this.params.downloadProgress(r)}}},{key:"addToDebugger",value:function(e){delete this.params.params.success,delete this.params.params.error;var r={params:this.params.params,data:e.debug?e.debug:e};window.DustPressDebugger.extend(r,this.params.path)}}])&&a(t.prototype,s),o&&a(t,o),r}()}).call(this,t(2))},function(e,r,t){"use strict";t.r(r),t.d(r,"default",function(){return s});var a=t(0);function n(e,r){for(var t=0;t1&&void 0!==arguments[1]?arguments[1]:{};return r.token=this.token,new a.a(e,r).send()}}])&&n(r.prototype,t),s&&n(r,s),e}();void 0===window.DustPress&&(window.DustPress=new s,window.dp=function(e,r){return window.DustPress.ajax(e,r)})},function(e,r){e.exports=jQuery}]); //# sourceMappingURL=dustpress-min.js.map \ No newline at end of file diff --git a/js/dustpress-min.js.map b/js/dustpress-min.js.map index d1ca09c..fb12422 100644 --- a/js/dustpress-min.js.map +++ b/js/dustpress-min.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./js/dustpress.js","webpack:///external \"jQuery\""],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","window","DustPress","document","$","dp","type","tidy","render","partial","upload","data","url","bypassMainQuery","success","error","uploadProgress","downloadProgress","contentType","crypto","getRandomValues","token","Uint32Array","Math","random","ajax","path","params","post","extend","defaults","instance","args","start","complete","length","startsWith","date","Date","setTime","getTime","cookie","toGMTString","options","dustpressjs_endpoint","location","method","dustpress_data","JSON","stringify","xhr","XMLHttpRequest","addEventListener","uploadProgressHandler","downloadProgressHandler","successHandler","textStatus","jqXHR","parsed","parseJSON","DustPressDebugger","debug","errorHandler","errorThrown","event","lengthComputable","loaded","total","done","fail","always","jQuery"],"mappings":"aACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI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EAAQF,EAAYC,IAIrC1B,EAAS+B,aAAe,SAAUL,EAAOD,EAAYO,GAEpD5D,EAASsC,OAAS,kCAElBV,EAAShB,MAAM,CAACA,MAAOgD,GAAcP,EAAYC,IAGlD1B,EAASsB,sBAAwB,SAAUW,GAC1C,GAAKA,EAAMC,iBAAmB,CAC7B,IAAI/B,EAAa8B,EAAME,OAASF,EAAMG,MAEtCpC,EAASf,eAAgBkB,KAI3BH,EAASuB,wBAA0B,SAAUU,GAC5C,GAAKA,EAAMC,iBAAmB,CAC7B,IAAI/B,EAAa8B,EAAME,OAASF,EAAMG,MAEtCpC,EAASd,iBAAkBiB,KAItB9B,EAAEqB,KAAMkB,GACdyB,KAAMrC,EAASwB,gBACfc,KAAMtC,EAAS+B,cACfQ,OAAQvC,EAASG,WAGZ7B,EAxKa,CA0KjBJ,OAAQE,SAAUoE,GAEtBtE,OAAOI,GAAKJ,OAAOC,UAAUuB,sCC5K7BzD,EAAAD,QAAAwG","file":"dustpress-min.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","window.DustPress = ( function( window, document, $ ) {\n\tvar dp = {};\n\t\n\tdp.defaults = {\n\t\t\"type\"\t \t\t : \"post\",\n\t\t\"tidy\" \t\t : false,\n\t\t\"render\" \t\t : false,\n\t\t\"partial\" \t\t : null,\n\t\t\"upload\" \t\t : false,\n\t\t\"data\" : false,\n\t\t\"url\" : null,\n\t\t\"bypassMainQuery\" : true,\n\t\t\"success\" \t\t : function() {},\n\t\t\"error\" \t\t : function() {},\n\t\t\"uploadProgress\" : function() {},\n\t\t\"downloadProgress\" : function() {},\n\t\t\"contentType\" : \"application/json\"\n\t};\n\n\tdp.start = function() {};\n\tdp.complete = function() {};\n\n\t// Create token for CSRF protection\n\tif ( typeof window.crypto !== 'undefined' && typeof window.crypto.getRandomValues === 'function' ) { \n\t\tdp.token = '';\n\n\t\tfor ( var i = 0; i < 4; i++ ) {\n\t\t\tdp.token += window.crypto.getRandomValues( new Uint32Array(1) );\n\t\t}\n\t}\n\telse {\n\t\tdp.token = Math.random() + '' + Math.random();\n\t}\n\n\tdp.ajax = function( path, params ) {\n\n\t\tvar post = $.extend( {}, dp.defaults, params );\n\n\t\t// Create a new instance of the default object so that simultaneous\tcalls wouldn't clash.\n\t\tvar instance = {};\n\n\t\t// Assign the variables\n\t\tinstance.type = post.type;\n\t\tinstance.success \t = post.success;\n\t\tinstance.error \t = post.error;\n\t\tinstance.url = post.url;\n\t\tinstance.uploadProgress = post.uploadProgress;\n\t\tinstance.downloadProgress = post.downloadProgress;\n\t\tinstance.get \t\t = post.get ? params.get : '';\n\t\tinstance.path\t\t = path;\n\t\tinstance.args = post.args;\n\t\tinstance.data = post.data;\n\t\tinstance.partial = post.partial;\n\t\tinstance.render = post.render;\n\t\tinstance.tidy = post.tidy;\n\t\tinstance.upload = post.upload;\n\t\tinstance.contentType = post.contentType;\n\t\tinstance.bypassMainQuery = post.bypassMainQuery;\n\t\tinstance.params \t = params;\n\t\tinstance.start = dp.start;\n\t\tinstance.complete = dp.complete;\n\n\t\tif ( instance.get.length && ! instance.get.startsWith('?') ) {\n\t\t\tinstance.get = '?' + instance.get;\n\t\t}\n\n\t\t\n\n\t\tvar date = new Date();\n date.setTime( date.getTime() + ( 24*60*60*1000 ) );\n\t \n\t // Set the cookie for the token\n\t document.cookie = 'dpjs_token=' + dp.token + '; expires=' + date.toGMTString() + '; path=/';\n\n\t\tvar options = {\n\t\t\turl: ( instance.url || dustpressjs_endpoint || ( window.location + instance.get ) ),\n\t\t\tmethod: instance.type,\n\t\t\tcontentType: instance.contentType,\n\t\t\tdata: {\n\t\t\t\tdustpress_data: {\n\t\t\t\t\tpath : path,\n\t\t\t\t\targs : instance.args,\n\t\t\t\t\trender : instance.render,\n\t\t\t\t\ttidy : instance.tidy,\n\t\t\t\t\tpartial : instance.partial,\n\t\t\t\t\tdata : instance.data,\n\t\t\t\t\ttoken : dp.token,\n\t\t\t\t\tbypassMainQuery : instance.bypassMainQuery\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t// Stringify data so it can be sent\n\t\toptions.data = JSON.stringify( options.data );\n\n\t\tif ( instance.upload ) {\n\t\t\toptions.xhr = function() {\n\t\t\t\tvar xhr = new window.XMLHttpRequest();\n\n\t\t\t\txhr.upload.addEventListener( 'progress', instance.uploadProgressHandler, false );\n\t\t\t\txhr.addEventListener( 'progress', instance.downloadProgressHandler, false );\n\t\t\t};\n\t\t}\n\n\t\tinstance.start();\n\n\t\tinstance.successHandler = function( data, textStatus, jqXHR ) {\n\t\t\tvar parsed;\n\n\t\t\tif ( typeof data === 'string' ) {\n\t\t\t\tparsed = $.parseJSON( data );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tparsed = data;\n\t\t\t}\n\t\t\t\n\t\t\t// Expire CSRF cookie\n\t\t\tdocument.cookie = 'dpjs_token=; expires=-1; path=/';\n\t\n\t\t\t// Add to debugger data if it exists\n\t\t\tif ( window.DustPressDebugger ) {\n\t\t\t\tdelete instance.params.success;\n\t\t\t\tdelete instance.params.error;\n\t\n\t\t\t\tvar debug = {\n\t\t\t\t\tparams: instance.params,\n\t\t\t\t\tdata: parsed.debug ? parsed.debug : parsed\n\t\t\t\t};\n\t\t\t\twindow.DustPressDebugger.extend(debug, instance.path);\n\t\t\t}\n\t\n\t\t\tif ( parsed && ! parsed.error ) {\n\t\t\t\tinstance.success(parsed.success, parsed.data, textStatus, jqXHR);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tinstance.error(parsed, textStatus, jqXHR);\n\t\t\t}\n\t\t};\n\t\n\t\tinstance.errorHandler = function( jqXHR, textStatus, errorThrown ) {\n\t\t\t// Expire CSRF cookie\n\t\t\tdocument.cookie = 'dpjs_token=; expires=-1; path=/';\n\t\n\t\t\tinstance.error({error: errorThrown}, textStatus, jqXHR);\n\t\t};\n\t\n\t\tinstance.uploadProgressHandler = function( event ) {\n\t\t\tif ( event.lengthComputable ) {\n\t\t\t\tvar complete = ( event.loaded / event.total );\n\t\n\t\t\t\tinstance.uploadProgress( complete );\t\n\t\t\t}\n\t\t};\n\t\n\t\tinstance.downloadProgressHandler = function( event ) {\n\t\t\tif ( event.lengthComputable ) {\n\t\t\t\tvar complete = ( event.loaded / event.total );\n\t\n\t\t\t\tinstance.downloadProgress( complete );\n\t\t\t}\n\t\t};\n\n\t\treturn $.ajax( options )\n\t\t.done( instance.successHandler )\n\t\t.fail( instance.errorHandler )\n\t\t.always( instance.complete );\n\t};\n\n\treturn dp;\n\n})( window, document, jQuery );\n\nwindow.dp = window.DustPress.ajax;\n","module.exports = jQuery;"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./js/DPRequest.js","webpack:///./js/dustpress.js","webpack:///external \"jQuery\""],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","DPRequest","path","params","arguments","length","undefined","_classCallCheck","this","_defineProperty","type","tidy","render","partial","upload","data","url","bypassMainQuery","contentType","token","success","error","uploadProgress","downloadProgress","start","complete","assign","_this","startsWith","date","Date","setTime","getTime","document","cookie","toGMTString","options","dustpressjs_endpoint","window","location","method","dustpress_data","args","JSON","stringify","xhr","xhrUpload","successHandler","textStatus","jqXHR","errorHandler","errorThrown","uploadProgressHandler","event","uploadDownloadProgressHandler","downloadProgressHandler","$","ajax","done","fail","always","dataOrXhr","xhrOrError","parsed","parseJSON","DustPressDebugger","addToDebugger","_this2","XMLHttpRequest","addEventListener","lengthComputable","loaded","total","debug","extend","DustPress","setupCrypto","crypto","getRandomValues","Uint32Array","Math","random","send","dp","jQuery"],"mappings":"aACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,GAAA,EAGAF,EAAAD,QAKAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SAAAR,EAAAS,EAAAC,GACAZ,EAAAa,EAAAX,EAAAS,IACAG,OAAAC,eAAAb,EAAAS,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CZ,EAAAkB,EAAA,SAAAhB,GACA,oBAAAiB,eAAAC,aACAN,OAAAC,eAAAb,EAAAiB,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAAb,EAAA,cAAiDmB,OAAA,KAQjDrB,EAAAsB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAArB,EAAAqB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,GAAA,iBAAAF,QAAAG,WAAA,OAAAH,EACA,IAAAI,EAAAX,OAAAY,OAAA,MAGA,GAFA1B,EAAAkB,EAAAO,GACAX,OAAAC,eAAAU,EAAA,WAAyCT,YAAA,EAAAK,UACzC,EAAAE,GAAA,iBAAAF,EAAA,QAAAM,KAAAN,EAAArB,EAAAU,EAAAe,EAAAE,EAAA,SAAAA,GAAgH,OAAAN,EAAAM,IAAqBC,KAAA,KAAAD,IACrI,OAAAF,GAIAzB,EAAA6B,EAAA,SAAA1B,GACA,IAAAS,EAAAT,KAAAqB,WACA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tB+E,iDAKU,IAArB5C,OAAOqC,YACfrC,OAAOqC,UAAY,IAAIA,EACvBrC,OAAO6C,GAAK,SAAEjF,EAAMC,GAChB,OAAOmC,OAAOqC,UAAUlB,KAAMvD,EAAMC,oBCrD5CnC,EAAAD,QAAAqH","file":"dustpress-min.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n","export default class DPRequest {\n\n /**\n * Request path\n *\n * @type {String}\n */\n path = '';\n\n /**\n * Default instance params\n *\n * @type {Object}\n */\n params = {\n get: '',\n type: 'post',\n tidy: false,\n render: false,\n partial: null,\n upload: false,\n data: false,\n url: null,\n bypassMainQuery: true,\n contentType: 'application/json',\n token: '',\n success: () => {},\n error: () => {},\n uploadProgress: () => {},\n downloadProgress: () => {},\n start: () => {},\n complete: () => {}\n };\n\n /**\n * Construct the dustpress request\n *\n * @param {Object} params Params to use in request\n */\n constructor( path, params = {}) {\n this.path = path;\n\n // Override default params with given ones\n this.params = Object.assign( this.params, params );\n }\n\n send() {\n if ( this.params.get.length && ! this.params.get.startsWith( '?' ) ) {\n this.params.get = '?' + this.params.get;\n }\n\n const date = new Date();\n date.setTime( date.getTime() + ( 24 * 60 * 60 * 1000 ) );\n\n // Set the cookie for the token\n document.cookie = 'dpjs_token=' + this.params.token + '; expires=' + date.toGMTString() + '; path=/';\n\n const options = {\n url: ( this.params.url || dustpressjs_endpoint || ( window.location + this.params.get ) ),\n method: this.params.type,\n contentType: this.params.contentType,\n data: {\n dustpress_data: {\n path: this.path,\n args: this.params.args,\n render: this.params.render,\n tidy: this.params.tidy,\n partial: this.params.partial,\n data: this.params.data,\n token: this.params.token,\n bypassMainQuery: this.params.bypassMainQuery\n }\n }\n };\n\n // Stringify data so it can be sent\n options.data = JSON.stringify( options.data );\n\n if ( this.params.upload ) {\n options.xhr = () => this.xhrUpload();\n }\n\n this.params.start();\n\n this.params.successHandler = ( data, textStatus, jqXHR ) => this.successHandler( data, textStatus, jqXHR );\n this.params.errorHandler = ( jqXHR, textStatus, errorThrown ) => this.errorHandler( jqXHR, textStatus, errorThrown );\n this.params.uploadProgressHandler = ( event ) => this.uploadDownloadProgressHandler( event );\n this.params.downloadProgressHandler = ( event ) => this.uploadDownloadProgressHandler( event );\n\n return $.ajax( options )\n .done( ( data, textStatus, jqXHR ) => this.params.successHandler( data, textStatus, jqXHR ) )\n .fail( ( jqXHR, textStatus, errorThrown ) => this.params.errorHandler( jqXHR, textStatus, errorThrown ) )\n .always( ( dataOrXhr, textStatus, xhrOrError ) => this.params.complete( dataOrXhr, textStatus, xhrOrError ) );\n }\n\n /**\n * Handle ajax success\n *\n * @param {string|mixed} data Data retrieved by ajax call.\n * @param {string} textStatus Response status.\n * @param {jqXHR} jqXHR Superset of the browser's native XMLHttpRequest object.\n */\n successHandler( data, textStatus, jqXHR ) {\n let parsed;\n\n if ( typeof data === 'string' ) {\n parsed = $.parseJSON( data );\n } else {\n parsed = data;\n }\n\n // Expire CSRF cookie\n document.cookie = 'dpjs_token=; expires=-1; path=/';\n\n // Add to debugger data if it exists\n if ( window.DustPressDebugger ) {\n this.addToDebugger( parsed );\n }\n\n if ( parsed && ! parsed.error ) {\n this.params.success( parsed.success, parsed.data, textStatus, jqXHR );\n } else {\n this.params.error( parsed, textStatus, jqXHR );\n }\n }\n\n /**\n * Handle file uploads\n */\n xhrUpload() {\n const xhr = new window.XMLHttpRequest();\n\n xhr.upload.addEventListener( 'progress', ( event ) => this.params.uploadProgressHandler( event ), false );\n xhr.addEventListener( 'progress', ( event ) => this.params.uploadDownloadProgressHandler( event ), false );\n }\n\n /**\n * Handle errors.\n *\n * @param {jqXHR} jqXHR Superset of the browser's native XMLHttpRequest object.\n * @param {string} textStatus Response status.\n * @param {mixed} errorThrown Ajax call error.\n */\n errorHandler( jqXHR, textStatus, errorThrown ) {\n\n // Expire CSRF cookie\n document.cookie = 'dpjs_token=; expires=-1; path=/';\n\n this.params.error({error: errorThrown}, textStatus, jqXHR );\n }\n\n /**\n * Handle uploar or download progress.\n *\n * @param {object} event Event data.\n */\n uploadDownloadProgressHandler( event ) {\n if ( event.lengthComputable ) {\n const complete = ( event.loaded / event.total );\n\n this.params.downloadProgress( complete );\n }\n }\n\n /**\n * Add called data to dustpress debugger\n *\n * @param {object} parsed Parsed data.\n */\n addToDebugger( parsed ) {\n delete this.params.params.success;\n delete this.params.params.error;\n\n const debug = {\n params: this.params.params,\n data: parsed.debug ? parsed.debug : parsed\n };\n window.DustPressDebugger.extend( debug, this.params.path );\n }\n}\n","import DPRequest from './DPRequest';\n\nexport default class DustPress {\n\n /**\n * Constains the crypt token\n *\n * @type {String}\n */\n token = '';\n\n /**\n * Construct class, setup crypt token\n */\n constructor() {\n this.setupCrypto();\n }\n\n /**\n * Setup token\n */\n setupCrypto() {\n\n // Create token for CSRF protection\n if ( typeof window.crypto !== 'undefined' && typeof window.crypto.getRandomValues === 'function' ) {\n this.token = '';\n\n for ( let i = 0; i < 4; i++ ) {\n this.token += window.crypto.getRandomValues( new Uint32Array( 1 ) );\n }\n } else {\n this.token = Math.random() + '' + Math.random();\n }\n }\n\n /**\n * Make the ajax call.\n *\n * @param {string} path Dustpress call path.\n * @param {object|null} params Ajax call params.\n * @return {jqXHR} Superset of the browser's native XMLHttpRequest object.\n */\n ajax( path, params = {}) {\n params.token = this.token;\n const request = new DPRequest( path, params );\n return request.send();\n }\n}\n\n// Register legacy functionality\nif ( typeof window.DustPress === 'undefined' ) {\n window.DustPress = new DustPress();\n window.dp = ( path, params ) => {\n return window.DustPress.ajax( path, params );\n };\n}\n","module.exports = jQuery;"],"sourceRoot":""} \ No newline at end of file diff --git a/js/dustpress.js b/js/dustpress.js index dd04e03..f1896f8 100755 --- a/js/dustpress.js +++ b/js/dustpress.js @@ -1,173 +1,56 @@ -window.DustPress = ( function( window, document, $ ) { - var dp = {}; - - dp.defaults = { - "type" : "post", - "tidy" : false, - "render" : false, - "partial" : null, - "upload" : false, - "data" : false, - "url" : null, - "bypassMainQuery" : true, - "success" : function() {}, - "error" : function() {}, - "uploadProgress" : function() {}, - "downloadProgress" : function() {}, - "contentType" : "application/json" - }; - - dp.start = function() {}; - dp.complete = function() {}; - - // Create token for CSRF protection - if ( typeof window.crypto !== 'undefined' && typeof window.crypto.getRandomValues === 'function' ) { - dp.token = ''; - - for ( var i = 0; i < 4; i++ ) { - dp.token += window.crypto.getRandomValues( new Uint32Array(1) ); - } - } - else { - dp.token = Math.random() + '' + Math.random(); - } - - dp.ajax = function( path, params ) { - - var post = $.extend( {}, dp.defaults, params ); - - // Create a new instance of the default object so that simultaneous calls wouldn't clash. - var instance = {}; - - // Assign the variables - instance.type = post.type; - instance.success = post.success; - instance.error = post.error; - instance.url = post.url; - instance.uploadProgress = post.uploadProgress; - instance.downloadProgress = post.downloadProgress; - instance.get = post.get ? params.get : ''; - instance.path = path; - instance.args = post.args; - instance.data = post.data; - instance.partial = post.partial; - instance.render = post.render; - instance.tidy = post.tidy; - instance.upload = post.upload; - instance.contentType = post.contentType; - instance.bypassMainQuery = post.bypassMainQuery; - instance.params = params; - instance.start = dp.start; - instance.complete = dp.complete; - - if ( instance.get.length && ! instance.get.startsWith('?') ) { - instance.get = '?' + instance.get; - } - - - - var date = new Date(); - date.setTime( date.getTime() + ( 24*60*60*1000 ) ); - - // Set the cookie for the token - document.cookie = 'dpjs_token=' + dp.token + '; expires=' + date.toGMTString() + '; path=/'; - - var options = { - url: ( instance.url || dustpressjs_endpoint || ( window.location + instance.get ) ), - method: instance.type, - contentType: instance.contentType, - data: { - dustpress_data: { - path : path, - args : instance.args, - render : instance.render, - tidy : instance.tidy, - partial : instance.partial, - data : instance.data, - token : dp.token, - bypassMainQuery : instance.bypassMainQuery - } - } - }; - - // Stringify data so it can be sent - options.data = JSON.stringify( options.data ); - - if ( instance.upload ) { - options.xhr = function() { - var xhr = new window.XMLHttpRequest(); - - xhr.upload.addEventListener( 'progress', instance.uploadProgressHandler, false ); - xhr.addEventListener( 'progress', instance.downloadProgressHandler, false ); - }; - } - - instance.start(); - - instance.successHandler = function( data, textStatus, jqXHR ) { - var parsed; - - if ( typeof data === 'string' ) { - parsed = $.parseJSON( data ); - } - else { - parsed = data; - } - - // Expire CSRF cookie - document.cookie = 'dpjs_token=; expires=-1; path=/'; - - // Add to debugger data if it exists - if ( window.DustPressDebugger ) { - delete instance.params.success; - delete instance.params.error; - - var debug = { - params: instance.params, - data: parsed.debug ? parsed.debug : parsed - }; - window.DustPressDebugger.extend(debug, instance.path); - } - - if ( parsed && ! parsed.error ) { - instance.success(parsed.success, parsed.data, textStatus, jqXHR); - } - else { - instance.error(parsed, textStatus, jqXHR); - } - }; - - instance.errorHandler = function( jqXHR, textStatus, errorThrown ) { - // Expire CSRF cookie - document.cookie = 'dpjs_token=; expires=-1; path=/'; - - instance.error({error: errorThrown}, textStatus, jqXHR); - }; - - instance.uploadProgressHandler = function( event ) { - if ( event.lengthComputable ) { - var complete = ( event.loaded / event.total ); - - instance.uploadProgress( complete ); - } - }; - - instance.downloadProgressHandler = function( event ) { - if ( event.lengthComputable ) { - var complete = ( event.loaded / event.total ); - - instance.downloadProgress( complete ); - } - }; - - return $.ajax( options ) - .done( instance.successHandler ) - .fail( instance.errorHandler ) - .always( instance.complete ); - }; - - return dp; - -})( window, document, jQuery ); - -window.dp = window.DustPress.ajax; +import DPRequest from './DPRequest'; + +export default class DustPress { + + /** + * Constains the crypt token + * + * @type {String} + */ + token = ''; + + /** + * Construct class, setup crypt token + */ + constructor() { + this.setupCrypto(); + } + + /** + * Setup token + */ + setupCrypto() { + + // Create token for CSRF protection + if ( typeof window.crypto !== 'undefined' && typeof window.crypto.getRandomValues === 'function' ) { + this.token = ''; + + for ( let i = 0; i < 4; i++ ) { + this.token += window.crypto.getRandomValues( new Uint32Array( 1 ) ); + } + } else { + this.token = Math.random() + '' + Math.random(); + } + } + + /** + * Make the ajax call. + * + * @param {string} path Dustpress call path. + * @param {object|null} params Ajax call params. + * @return {jqXHR} Superset of the browser's native XMLHttpRequest object. + */ + ajax( path, params = {}) { + params.token = this.token; + const request = new DPRequest( path, params ); + return request.send(); + } +} + +// Register legacy functionality +if ( typeof window.DustPress === 'undefined' ) { + window.DustPress = new DustPress(); + window.dp = ( path, params ) => { + return window.DustPress.ajax( path, params ); + }; +} diff --git a/package-lock.json b/package-lock.json index 5abfa23..838751c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "dustpress-js", - "version": "3.0.4", + "version": "3.0.5", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -104,6 +104,19 @@ "@babel/types": "^7.0.0" } }, + "@babel/helper-create-class-features-plugin": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.3.0.tgz", + "integrity": "sha512-DUsQNS2CGLZZ7I3W3fvh0YpPDd6BuWJlDl+qmZZpABZHza2ErE3LxtEzLJFHFC1ZwtlAXvHhbFYbtM5o5B0WBw==", + "dev": true, + "requires": { + "@babel/helper-function-name": "^7.1.0", + "@babel/helper-member-expression-to-functions": "^7.0.0", + "@babel/helper-optimise-call-expression": "^7.0.0", + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/helper-replace-supers": "^7.2.3" + } + }, "@babel/helper-define-map": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/@babel/helper-define-map/-/helper-define-map-7.1.0.tgz", @@ -305,6 +318,16 @@ "@babel/plugin-syntax-async-generators": "^7.2.0" } }, + "@babel/plugin-proposal-class-properties": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.3.0.tgz", + "integrity": "sha512-wNHxLkEKTQ2ay0tnsam2z7fGZUi+05ziDJflEt3AZTP3oXLKHJp9HqhfroB/vdMvt3sda9fAbq7FsG8QPDrZBg==", + "dev": true, + "requires": { + "@babel/helper-create-class-features-plugin": "^7.3.0", + "@babel/helper-plugin-utils": "^7.0.0" + } + }, "@babel/plugin-proposal-json-strings": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-json-strings/-/plugin-proposal-json-strings-7.2.0.tgz", @@ -1097,6 +1120,32 @@ "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==", "dev": true }, + "babel-eslint": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-10.0.1.tgz", + "integrity": "sha512-z7OT1iNV+TjOwHNLLyJk+HN+YVWX+CLE6fPD2SymJZOZQBs+QIexFjhm4keGTm8MW9xr4EC9Q0PbaLB24V5GoQ==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@babel/parser": "^7.0.0", + "@babel/traverse": "^7.0.0", + "@babel/types": "^7.0.0", + "eslint-scope": "3.7.1", + "eslint-visitor-keys": "^1.0.0" + }, + "dependencies": { + "eslint-scope": { + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz", + "integrity": "sha1-PWPD7f2gLgbgGkUq2IyqzHzctug=", + "dev": true, + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + } + } + } + }, "babel-loader": { "version": "8.0.5", "resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-8.0.5.tgz", @@ -1926,6 +1975,12 @@ "estraverse": "^4.1.1" } }, + "eslint-visitor-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", + "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==", + "dev": true + }, "esrecurse": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", @@ -2286,12 +2341,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2306,17 +2363,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2433,7 +2493,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2445,6 +2506,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2459,6 +2521,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2466,12 +2529,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2490,6 +2555,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2570,8 +2636,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -2583,6 +2648,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2704,6 +2770,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/package.json b/package.json index 4a733fa..ff5dfa4 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "devDependencies": { "@babel/core": "^7.2.2", "@babel/preset-env": "^7.3.1", + "@babel/plugin-proposal-class-properties": "^7.3.0", + "babel-eslint": "^10.0.1", "babel-loader": "^8.0.5", "webpack": "^4.29.0", "webpack-cli": "^3.2.1" @@ -19,5 +21,5 @@ "build": "webpack -p", "watch": "webpack -w" }, - "version": "3.0.4" + "version": "3.0.5" } diff --git a/plugin.php b/plugin.php index 8abbbd2..8060764 100755 --- a/plugin.php +++ b/plugin.php @@ -3,7 +3,7 @@ * Plugin Name: DustPress.JS * Plugin URI: https://github.com/devgeniem/dustpress-js * Description: DustPress JavaScript library. Provides a front-end interface for interacting with the backend functions. - * Version: 3.0.4 + * Version: 3.0.5 * Author: Geniem Oy / Miika Arponen & Ville Siltala * Author URI: http://www.geniem.com */ diff --git a/webpack.config.js b/webpack.config.js index f4b6425..6084b8a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -30,7 +30,8 @@ module.exports = { use: { loader: 'babel-loader', options: { - presets: [ '@babel/preset-env' ] + presets: [ '@babel/preset-env' ], + plugins: [ '@babel/plugin-proposal-class-properties' ] } } }