Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
DoNormal committed Feb 18, 2015
1 parent 43a6a1d commit 8b4f1c3
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
34 changes: 34 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
38 changes: 38 additions & 0 deletions src/jquery.feyenoord.js
Original file line number Diff line number Diff line change
@@ -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));
1 change: 1 addition & 0 deletions test/data/name.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR <script type="text/javascript">ok(true, "name.html retrieved");</script>
3 changes: 3 additions & 0 deletions test/data/setup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"result": "ok"
}
1 change: 1 addition & 0 deletions test/data/setup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
done
16 changes: 16 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery.feyenoordTest Suite</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.15.0.css">
<script src="http://code.jquery.com/qunit/qunit-1.15.0.js"></script>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="../src/jquery.feyenoord.js"></script>
<script src="tests.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>
52 changes: 52 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 8b4f1c3

Please sign in to comment.