Skip to content

Commit

Permalink
Release version 0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
pklauzinski committed May 27, 2017
1 parent caa63ad commit 73c1644
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 38 deletions.
127 changes: 127 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
27 changes: 7 additions & 20 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
},

/**
Expand Down Expand Up @@ -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']);
};
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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"
}
}
42 changes: 27 additions & 15 deletions payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*
Expand All @@ -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');
}
Expand All @@ -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');
}
Expand All @@ -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 {
Expand Down Expand Up @@ -337,7 +349,7 @@
if (namespace) {
event_name += '.' + namespace;
}
_this.publish(event_name, [params] || []);
_this.publish(event_name, [params]);
}
}

Expand Down

0 comments on commit 73c1644

Please sign in to comment.