From 73c16442404c6141a4ea3aa53b82a9c760773d51 Mon Sep 17 00:00:00 2001 From: pklauzinski Date: Fri, 26 May 2017 21:06:01 -0500 Subject: [PATCH] Release version 0.5.2 --- .eslintrc | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++ Gruntfile.js | 27 +++-------- package.json | 5 +- payload.js | 42 +++++++++++------ 4 files changed, 163 insertions(+), 38 deletions(-) create mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..372af04 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,127 @@ +{ + "env": { + "browser": true + }, + "globals": { + "jQuery": true + }, + "rules": { + "curly": [ + 2, + "all" + ], + "eqeqeq": 2, + "no-eq-null": 2, + "guard-for-in": 2, + "no-unused-vars": [ + 2, + { + "args": "none" + } + ], + "strict": [ + 2, + "safe" + ], + "no-use-before-define": [ + 2, + { + "functions": false + } + ], + "operator-linebreak": [ + 2, + "after" + ], + "max-len": [ + 2, + { + "code": 200, + "tabWidth": 4, + "ignoreComments": true + } + ], + "indent": [ + 2, + 4, + { + "SwitchCase": 1 + } + ], + "quotes": [ + 2, + "single" + ], + "no-multi-str": 2, + "no-mixed-spaces-and-tabs": 2, + "no-trailing-spaces": 2, + "space-unary-ops": [ + 2, + { + "nonwords": false, + "overrides": {} + } + ], + "brace-style": [ + 2, + "1tbs", + { + "allowSingleLine": true + } + ], + "comma-spacing": [ + 2, + { + "before": false, + "after": true + } + ], + "comma-dangle": [ + 2, + "never" + ], + "comma-style": [ + "error", + "last" + ], + "keyword-spacing": [ + 2, + {} + ], + "space-infix-ops": 2, + "space-before-blocks": [ + 2, + "always" + ], + "space-before-function-paren": [ + 2, + { + "anonymous": "ignore", + "named": "never" + } + ], + "array-bracket-spacing": [ + 2, + "never" + ], + "space-in-parens": [ + 2, + "never" + ], + "no-multiple-empty-lines": 2, + "no-with": 2, + "no-spaced-func": 2, + "key-spacing": [ + 2, + { + "beforeColon": false, + "afterColon": true + } + ], + "dot-notation": 2, + "semi": [ + 2, + "always" + ] + } +} \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 7d6167e..9da998f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -7,25 +7,13 @@ module.exports = function(grunt) { pkg: grunt.file.readJSON('package.json'), /** - * https://github.com/gruntjs/grunt-contrib-jshint + * https://github.com/gyandeeps/gruntify-eslint */ - jshint: { + eslint: { options: { - jshintrc: true + configFile: '.eslintrc' }, - files: { - src: ['Gruntfile.js', 'payload.js'] - } - }, - - /** - * https://github.com/jscs-dev/grunt-jscs - */ - jscs: { - src: ['Gruntfile.js', 'payload.js'], - options: { - config: '.jscsrc' - } + src: ['Gruntfile.js', 'payload.js'] }, /** @@ -53,10 +41,9 @@ module.exports = function(grunt) { }); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-jscs'); + grunt.loadNpmTasks('gruntify-eslint'); grunt.loadNpmTasks('grunt-bump'); - grunt.registerTask('default', ['jshint', 'jscs']); - grunt.registerTask('test', ['jshint', 'jscs']); + grunt.registerTask('default', ['eslint']); + grunt.registerTask('test', ['eslint']); }; \ No newline at end of file diff --git a/package.json b/package.json index 1409306..7e83243 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "payloadjs", - "version": "0.5.1", + "version": "0.5.2", "description": "Payload.js is a javascript single page application (SPA) driver designed to interact intuitively with REST APIs from within web and mobile apps.", "main": "payload.js", "scripts": { @@ -35,7 +35,6 @@ "devDependencies": { "grunt": "^1.0.1", "grunt-bump": "^0.8.0", - "grunt-contrib-jshint": "^1.0.0", - "grunt-jscs": "^3.0.1" + "gruntify-eslint": "3.1.0" } } diff --git a/payload.js b/payload.js index eacfa05..ebb16d2 100644 --- a/payload.js +++ b/payload.js @@ -5,7 +5,7 @@ * @copyright 2015-2017, Philip Klauzinski * @license Released under the MIT license (http://www.opensource.org/licenses/mit-license.php) * @author Philip Klauzinski (http://webtopian.com) - * @version 0.5.1 + * @version 0.5.2 * @requires jQuery v1.7+ * @preserve */ @@ -179,6 +179,26 @@ _$payloadEvents.off.apply(_$payloadEvents, arguments); }, + /** + * Test if browser storage API is both supported and available + * + * @param type + * @returns {boolean} + * @private + */ + _storageAvailable = function(type) { + try { + var storage = window[type], + name = '__storage_test__'; + + storage.set(name, 1); + storage.removeItem(name); + return true; + } catch (e) { + return false; + } + }, + /** * Internal JSON API for localStorage * @@ -196,12 +216,8 @@ */ set: function(id, obj, _type) { var type = _type === 'session' ? 'sessionStorage' : 'localStorage'; - if (window[type] && window[type].setItem) { - try { - window[type].setItem(id, JSON.stringify(obj)); - } catch(err) { - _this.debug('warn', err); - } + if (_storageAvailable(type)) { + window[type].setItem(id, JSON.stringify(obj)); } else { _this.debug('warn', type + ' not available'); } @@ -219,12 +235,8 @@ var type = _type === 'session' ? 'sessionStorage' : 'localStorage', storage = {}; - if (window[type] && window[type].getItem) { - try { - storage = JSON.parse(window[type].getItem(id)); - } catch(err) { - _this.debug(err); - } + if (_storageAvailable(type)) { + storage = JSON.parse(window[type].getItem(id)); } else { _this.debug('warn', type + ' not available'); } @@ -241,7 +253,7 @@ */ remove: function(id, _type) { var type = _type === 'session' ? 'sessionStorage' : 'localStorage'; - if (window[type] && window[type].removeItem) { + if (_storageAvailable(type)) { window[type].removeItem(id); return true; } else { @@ -337,7 +349,7 @@ if (namespace) { event_name += '.' + namespace; } - _this.publish(event_name, [params] || []); + _this.publish(event_name, [params]); } }