diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8cf6605 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2014 Robert van Kempen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..bec6189 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# jquery-feyenoord + +Asynchronous JS requests for Feyenoord supporters. + +## Purpose + +If you're a supporter of Feyenoord, or if you think ancient Greek heroes are pricks, you're probably tired of calling `$.ajax()` all the time. Well, here's the solution. This piece of code takes each Ajax-related function and wraps it inside a better Feyenoord function. + +## Usage + +Install using bower: + + $ bower install jquery-feyenoord + +Then, when using the [jQuery Ajax API](http://api.jquery.com/category/ajax/) just replace 'ajax' with 'feyenoord' in your code, e.g. `$.feyenoord(url, options);`. + +## Colophon + +Made with ♥ in Rotterdam. \ No newline at end of file diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..3b28bd6 --- /dev/null +++ b/bower.json @@ -0,0 +1,34 @@ +{ + "name": "jquery-feyenoord", + "version": "0.1", + "main": [ + "src/jquery-feyenoord.js" + ], + "dependencies": { + "jquery": ">=1.5" + }, + "license": "MIT", + "ignore": [ + "**/.*", + "build", + "test", + "*.md", + "AUTHORS.txt", + "Gruntfile.js", + "package.json", + "node_modules", + "bower_components", + "tests" + ], + "keywords": [ + "jquery", + "javascript", + "feyenoord", + "ajax", + "football" + ], + "description": "Asynchronous requests for Feyenoord supporters.", + "authors": [ + "Robert van Kempen" + ] +} diff --git a/src/jquery.feyenoord.js b/src/jquery.feyenoord.js new file mode 100644 index 0000000..0a3e305 --- /dev/null +++ b/src/jquery.feyenoord.js @@ -0,0 +1,38 @@ +((function ($) { + + /* Wrap low level functions */ + $.extend({ + + feyenoord: function (url, options) { + return $.ajax(url, options); + }, + + feyenoordSetup: function (target, settings) { + return $.ajaxSetup(target, settings); + }, + + feyenoordPrefilter: function (prefilters) { + return $.ajaxPrefilter(prefilters); + }, + + feyenoordTransport: function (transport) { + return $.ajaxTransport(transport); + } + + }); + + /* Wrap global event handlers */ + $.each([ + 'Start', + 'Stop', + 'Complete', + 'Error', + 'Success', + 'Send' + ], function (i, type) { + jQuery.fn['feyenoord' + type] = function (fn) { + return this.on( 'ajax' + type, fn); + }; + }); + +})(jQuery)); \ No newline at end of file diff --git a/test/data/name.html b/test/data/name.html new file mode 100644 index 0000000..9eaad80 --- /dev/null +++ b/test/data/name.html @@ -0,0 +1 @@ +ERROR \ No newline at end of file diff --git a/test/data/setup.json b/test/data/setup.json new file mode 100644 index 0000000..3c216f7 --- /dev/null +++ b/test/data/setup.json @@ -0,0 +1,3 @@ +{ + "result": "ok" +} \ No newline at end of file diff --git a/test/data/setup.txt b/test/data/setup.txt new file mode 100644 index 0000000..348ebd9 --- /dev/null +++ b/test/data/setup.txt @@ -0,0 +1 @@ +done \ No newline at end of file diff --git a/test/index.html b/test/index.html new file mode 100644 index 0000000..e162ffd --- /dev/null +++ b/test/index.html @@ -0,0 +1,16 @@ + + + + + jQuery.feyenoordTest Suite + + + + + + + +
+
+ + \ No newline at end of file diff --git a/test/tests.js b/test/tests.js new file mode 100644 index 0000000..1f024c1 --- /dev/null +++ b/test/tests.js @@ -0,0 +1,52 @@ +// TODO Add tests for all methods. + +var lifecycle = { + setup: function () { + this.options = { + cache: false, + url: 'data/setup.json', + text: 'json' + }; + }, + teardown: function() { + jQuery(document).off('ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess'); + jQuery.ajaxSetup({}); + } +}; + + +module('Low level', lifecycle); + +test('Simple call', function () { + var url = 'data/name.html'; + + var feyenoord = $.feyenoord(url, this.options); + var expected = $.ajax(url, this.options); + + propEqual(feyenoord, expected); +}); + +test('Setup', function () { + $.feyenoordSetup({ + cache: false, + url: 'data/setup.json', + text: 'json' + }); + + var feyenoord = $.feyenoord(); + var ajax = $.ajax(); + + strictEqual(feyenoord.responseJSON, ajax.responseJSON); +}); + +test('Pre-filter', function () { + $.feyenoordPrefilter(function (options) { + options.text = 'json'; + options.url = 'data/setup.json'; + }); + + var feyenoord = $.feyenoord(this.options); + var ajax = $.ajax(this.options); + + strictEqual(feyenoord.responseJSON, ajax.responseJSON); +}); \ No newline at end of file