Commit bc80784c authored by Romain Courteaud's avatar Romain Courteaud

Revert usage of jquery mobile routing.

More flexibility is needed at this level.
parent 93dd89e3
# jQuery Slapos
API to use all your slapos stuff on a web application
## Getting Started
### Requirements
1. [NodeJs](http://nodejs.org/) is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications.
* [How to install NodeJs](https://github.com/joyent/node/wiki/Installation)
2. [npm](http://npmjs.org/) is a package manager for node. _Comes with nodejs._
3. [Grunt](https://github.com/cowboy/grunt) a task-based command line build tool for JavaScript projects.
* [How to install Grunt](https://github.com/cowboy/grunt#installing-grunt-%E2%9A%91)
## Documentation
_(Coming soon)_
## Examples
_(Coming soon)_
## Contributing
_please don't edit files in the "dist" subdirectory as they are generated via grunt. You'll find source code in the "src" subdirectory!_
## Release History
_(Nothing yet)_
## License
Copyright (c) 2012 NEXEDI
Licensed under the MIT, GPL licenses.
/*! jQuery Slapos - v0.1.0 - 2012-05-11
* Copyright (c) 2012 Nexedi; Licensed */
(function ($) {
"use strict";
var methods = {
init: function (options) {
var settings = $.extend({
'host': '',
'access_token': '',
'clientID': ''
}, options);
return this.each(function () {
var setting;
methods.store = Modernizr.localstorage ? methods.lStore : methods.cStore;
for (setting in settings) {
if (settings.hasOwnProperty(setting)) {
$(this).slapos('store', setting, settings[setting]);
}
}
});
},
/* Getters & Setters shortcuts */
access_token: function (value) {
return $(this).slapos('store', 'access_token', value);
},
host: function (value) {
return $(this).slapos('store', 'host', value);
},
clientID: function (value) {
return $(this).slapos('store', 'clientID', value);
},
/* Local storage method */
lStore: function (name, value) {
if (Modernizr.localstorage) {
return value === undefined ? window.localStorage[name] : window.localStorage[name] = value;
}
return false;
},
/* Cookie storage method */
cStore: function (name, value) {
if (value !== undefined) {
document.cookie = name + "=" + value + ";domain=" + window.location.hostname + ";path=" + window.location.pathname;
} else {
var i, x, y, cookies = document.cookie.split(';');
for (i = 0; i < cookies.length; i += 1) {
x = cookies[i].substr(0, cookies[i].indexOf('='));
y = cookies[i].substr(cookies[i].indexOf('=') + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x === name) {
return unescape(y);
}
}
}
},
statusDefault: function () {
return {
0: function () { console.error("status error code: 0"); },
404: function () { console.error("status error code: Not Found !"); }
};
},
request: function (type, url, callback, statusCode, data) {
data = data || '';
statusCode = statusCode || this.statusDefault;
return this.each(function () {
$.ajax({
url: $(this).slapos('host') + url,
type: type,
contentType: 'application/octet-stream',
data: JSON.stringify(data),
dataType: 'json',
context: $(this),
beforeSend: function (xhr) {
if ($(this).slapos("access_token")) {
xhr.setRequestHeader("Authorization", $(this).slapos("store", "token_type") + " " + $(this).slapos("access_token"));
xhr.setRequestHeader("Accept", "application/json");
}
},
statusCode: statusCode,
success: callback
});
});
},
newInstance: function (data, callback, statusEvent) {
return $(this).slapos('request', 'POST', '/request', callback, statusEvent, data);
},
deleteInstance: function (id, callback, statusEvent) {
return $(this).slapos('request', 'DELETE', '/instance/' + id, callback, statusEvent);
},
getInstance: function (id, callback, statusEvent) {
return $(this).slapos('request', 'GET', '/instance/' + id, callback, statusEvent);
},
getInstanceCert: function (id, callback, statusEvent) {
return $(this).slapos('request', 'GET', '/instance/' + id + '/certificate', callback, statusEvent);
},
bangInstance: function (id, log, callback, statusEvent) {
return $(this).slapos('request', 'POST', '/instance/' + id + '/bang', callback, statusEvent, log);
},
editInstance: function (id, data, callback, statusEvent) {
return $(this).slapos('request', 'PUT', '/instance/' + id, callback, statusEvent, data);
},
newComputer: function (data, callback, statusEvent) {
return $(this).slapos('request', 'POST', '/computer', callback, statusEvent, data);
},
getComputer: function (id, callback, statusEvent) {
return $(this).slapos('request', 'GET', '/computer/' + id, callback, statusEvent);
},
editComputer: function (id, data, callback, statusEvent) {
return $(this).slapos('request', 'PUT', '/computer/' + id, callback, statusEvent, data);
},
newSoftware: function (computerId, data, callback, statusEvent) {
return $(this).slapos('request', 'POST', '/computer/' + computerId + '/supply', callback, statusEvent, data);
},
bangComputer: function (id, log, callback, statusEvent) {
return $(this).slapos('request', 'POST', '/computer/' + id + '/bang', callback, statusEvent, log);
},
computerReport: function (id, data, callback, statusEvent) {
return $(this).slapos('request', 'POST', '/computer/' + id + '/report', callback, statusEvent, data);
}
};
$.fn.slapos = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.slapos');
}
};
}(jQuery));
/*! jQuery Slapos - v0.1.0 - 2012-05-11
* Copyright (c) 2012 Nexedi; Licensed */
(function(a){"use strict";var b={init:function(c){var d=a.extend({host:"",access_token:"",clientID:""},c);return this.each(function(){var c;b.store=Modernizr.localstorage?b.lStore:b.cStore;for(c in d)d.hasOwnProperty(c)&&a(this).slapos("store",c,d[c])})},access_token:function(b){return a(this).slapos("store","access_token",b)},host:function(b){return a(this).slapos("store","host",b)},clientID:function(b){return a(this).slapos("store","clientID",b)},lStore:function(a,b){return Modernizr.localstorage?b===undefined?window.localStorage[a]:window.localStorage[a]=b:!1},cStore:function(a,b){if(b!==undefined)document.cookie=a+"="+b+";domain="+window.location.hostname+";path="+window.location.pathname;else{var c,d,e,f=document.cookie.split(";");for(c=0;c<f.length;c+=1){d=f[c].substr(0,f[c].indexOf("=")),e=f[c].substr(f[c].indexOf("=")+1),d=d.replace(/^\s+|\s+$/g,"");if(d===a)return unescape(e)}}},statusDefault:function(){return{0:function(){console.error("status error code: 0")},404:function(){console.error("status error code: Not Found !")}}},request:function(b,c,d,e,f){return f=f||"",e=e||this.statusDefault,this.each(function(){a.ajax({url:a(this).slapos("host")+c,type:b,contentType:"application/octet-stream",data:JSON.stringify(f),dataType:"json",context:a(this),beforeSend:function(b){a(this).slapos("access_token")&&(b.setRequestHeader("Authorization",a(this).slapos("store","token_type")+" "+a(this).slapos("access_token")),b.setRequestHeader("Accept","application/json"))},statusCode:e,success:d})})},newInstance:function(b,c,d){return a(this).slapos("request","POST","/request",c,d,b)},deleteInstance:function(b,c,d){return a(this).slapos("request","DELETE","/instance/"+b,c,d)},getInstance:function(b,c,d){return a(this).slapos("request","GET","/instance/"+b,c,d)},getInstanceCert:function(b,c,d){return a(this).slapos("request","GET","/instance/"+b+"/certificate",c,d)},bangInstance:function(b,c,d,e){return a(this).slapos("request","POST","/instance/"+b+"/bang",d,e,c)},editInstance:function(b,c,d,e){return a(this).slapos("request","PUT","/instance/"+b,d,e,c)},newComputer:function(b,c,d){return a(this).slapos("request","POST","/computer",c,d,b)},getComputer:function(b,c,d){return a(this).slapos("request","GET","/computer/"+b,c,d)},editComputer:function(b,c,d,e){return a(this).slapos("request","PUT","/computer/"+b,d,e,c)},newSoftware:function(b,c,d,e){return a(this).slapos("request","POST","/computer/"+b+"/supply",d,e,c)},bangComputer:function(b,c,d,e){return a(this).slapos("request","POST","/computer/"+b+"/bang",d,e,c)},computerReport:function(b,c,d,e){return a(this).slapos("request","POST","/computer/"+b+"/report",d,e,c)}};a.fn.slapos=function(c){if(b[c])return b[c].apply(this,Array.prototype.slice.call(arguments,1));if(typeof c=="object"||!c)return b.init.apply(this,arguments);a.error("Method "+c+" does not exist on jQuery.slapos")}})(jQuery);
\ No newline at end of file
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: '<json:package.json>',
meta: {
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> Nexedi;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
},
concat: {
dist: {
src: ['<banner:meta.banner>', '<file_strip_banner:src/<%= pkg.name %>.js>'],
dest: 'dist/<%= pkg.name %>.js'
}
},
min: {
dist: {
src: ['<banner:meta.banner>', '<config:concat.dist.dest>'],
dest: 'dist/<%= pkg.name %>.min.js'
}
},
qunit: {
files: ['test/**/*.html']
},
lint: {
files: ['grunt.js', 'src/**/*.js', 'test/**/*.js']
},
watch: {
files: '<config:lint.files>',
tasks: 'lint qunit'
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true
},
globals: {
jQuery: true,
Modernizr: true,
console: true,
unescape: true,
// Needed to avoid "not defined error" with sinonJs
sinon: true,
module: true,
test: true,
ok: true,
expect: true,
stop: true,
start: true,
equal: true
}
},
uglify: {}
});
// Default task.
grunt.registerTask('default', 'lint qunit concat min');
};
...@@ -7420,6 +7420,7 @@ jQuery.extend({ ...@@ -7420,6 +7420,7 @@ jQuery.extend({
if ( state === 2 ) { if ( state === 2 ) {
if ( !responseHeaders ) { if ( !responseHeaders ) {
responseHeaders = {}; responseHeaders = {};
console.log(responseHeadersString);
while( ( match = rheaders.exec( responseHeadersString ) ) ) { while( ( match = rheaders.exec( responseHeadersString ) ) ) {
responseHeaders[ match[1].toLowerCase() ] = match[ 2 ]; responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
} }
...@@ -7483,7 +7484,6 @@ jQuery.extend({ ...@@ -7483,7 +7484,6 @@ jQuery.extend({
response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined, response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined,
lastModified, lastModified,
etag; etag;
// If successful, handle type chaining // If successful, handle type chaining
if ( status >= 200 && status < 300 || status === 304 ) { if ( status >= 200 && status < 300 || status === 304 ) {
......
This diff is collapsed.
This diff is collapsed.
/**
* sinon-qunit 1.0.0, 2010/12/09
*
* @author Christian Johansen (christian@cjohansen.no)
*
* (The BSD License)
*
* Copyright (c) 2010-2011, Christian Johansen, christian@cjohansen.no
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Christian Johansen nor the names of his contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*global sinon, QUnit, test*/
sinon.assert.fail = function (msg) {
QUnit.ok(false, msg);
};
sinon.assert.pass = function (assertion) {
QUnit.ok(true, assertion);
};
sinon.config = {
injectIntoThis: true,
injectInto: null,
properties: ["spy", "stub", "mock", "clock", "sandbox"],
useFakeTimers: true,
useFakeServer: false
};
(function (global) {
var qTest = QUnit.test;
QUnit.test = global.test = function (testName, expected, callback, async) {
if (arguments.length === 2) {
callback = expected;
expected = null;
}
return qTest(testName, expected, sinon.test(callback), async);
};
}(this));
This diff is collapsed.
{ {
"name": "jquery.mobile.vifib", "name": "jquery.slapos",
"title": "jQuery Mobile Vifib", "title": "jQuery Slapos",
"description": "The best jQuery plugin ever.", "description": "API to use slapos stuff in a web application",
"version": "0.1.0", "version": "0.1.0",
"homepage": "", "homepage": "",
"author": { "author": {
"name": "Thomas Lechauve", "name": "Thomas Lechauve",
"email": "gnon@tiolive.com" "email": "thomas.lechauve@gmail.com"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
...@@ -16,17 +16,11 @@ ...@@ -16,17 +16,11 @@
"url": "" "url": ""
}, },
"licenses": [ "licenses": [
{
"type": "MIT",
"url": "/blob/master/LICENSE-MIT"
},
{
"type": "GPL",
"url": "/blob/master/LICENSE-GPL"
}
], ],
"dependencies": { "dependencies": {
"jquery": "1.7.1" "jquery": "~1.7",
"sinon": "1.3.2",
"modernizr": "2.5.3"
}, },
"keywords": [] "keywords": []
} }
\ No newline at end of file
(function ($) {
'use strict';
var methods = {
init: function (options) {
var settings = $.extend({
}, options);
return this.each(function () {
var setting;
methods.store = Modernizr.localstorage ? methods.lStore : methods.cStore;
for (setting in settings) {
if (settings.hasOwnProperty(setting)) {
$(this).slapos('store', setting, settings[setting]);
}
}
});
},
/* Getters & Setters shortcuts */
access_token: function (value) {
return $(this).slapos('store', 'access_token', value);
},
host: function (value) {
return $(this).slapos('store', 'host', value);
},
clientID: function (value) {
return $(this).slapos('store', 'clientID', value);
},
deleteStore: function (name) {
delete window.localStorage[name];
},
/* Local storage method */
lStore: function (name, value) {
if (Modernizr.localstorage) {
return value === undefined ? window.localStorage[name] : window.localStorage[name] = value;
}
return false;
},
/* Cookie storage method */
cStore: function (name, value) {
if (value !== undefined) {
document.cookie = name + '=' + value + ';domain=' + window.location.hostname + ';path=' + window.location.pathname;
} else {
var i, x, y, cookies = document.cookie.split(';');
for (i = 0; i < cookies.length; i += 1) {
x = cookies[i].substr(0, cookies[i].indexOf('='));
y = cookies[i].substr(cookies[i].indexOf('=') + 1);
x = x.replace(/^\s+|\s+$/g, '');
if (x === name) {
return unescape(y);
}
}
}
},
statusDefault: function () {
return {
0: function () { console.error('status error code: 0'); },
404: function () { console.error('status error code: Not Found !'); },
500: function () { console.error('Server error !'); }
};
},
request: function (type, authentication, args) {
var statusCode, data;
if (args.hasOwnProperty('statusCode')) {
statusCode = args.statusCode || methods.statusDefault();
} else {
statusCode = methods.statusDefault();
}
if (args.hasOwnProperty('data')) {
data = args.data || undefined;
} else {
data = undefined;
}
delete args.data;
$.extend(args, {statusCode: statusCode});
return this.each(function () {
var ajaxOptions = {
type: type,
contentType: 'application/json',
cache: false,
data: JSON.stringify(data),
datatype: 'json',
context: $(this),
beforeSend: function (xhr) {
xhr.setRequestHeader('REMOTE_USER', 'test_vifib_customer');
xhr.setRequestHeader('Accept', 'application/json');
if ($(this).slapos('access_token') && authentication) {
//xhr.setRequestHeader('Authorization', $(this).slapos('store', 'token_type') + ' ' + $(this).slapos('access_token'));
}
}
};
$.extend(ajaxOptions, args);
$.ajax(ajaxOptions);
});
},
prepareRequest: function (methodName, args) {
var $this = $(this);
args = args || {};
return this.each(function () {
$(this).slapos('discovery', function (access) {
if (access.hasOwnProperty(methodName)) {
var url = access[methodName].url.replace(/{(\w+)}/, function (matchedText, $1) {
return "" + args[$1]
});
$.extend(args, {'url': url});
$this.slapos('request',
access[methodName].method,
access[methodName].authentication,
args);
}
});
});
},
discovery: function (callback) {
return this.each(function () {
$.ajax({
url: $(this).slapos("host"),
context: $(this),
dataType: 'json',
beforeSend: function (xhr) {
xhr.setRequestHeader('Accept', 'application/json');
},
success: callback,
});
});
},
instanceList: function (args) {
return $(this).slapos('prepareRequest', 'instance_list', args);
},
instanceInfo: function (url, args) {
$.extend(args, {'instance_url': decodeURIComponent(url)});
return $(this).slapos('prepareRequest', 'instance_info', args);
},
instanceRequest: function (args) {
return $(this).slapos('prepareRequest', 'request_instance', args);
},
instanceBang: function (url, args) {
$.extend(args, {'instance_url': decodeURIComponent(url)});
return $(this).slapos('prepareRequest', 'instance_bang', args);
},
instanceCertificate: function (url, args) {
$.extend(args, {'instance_url': decodeURIComponent(url)});
return $(this).slapos('prepareRequest', 'instance_certificate', args);
},
softwareList: function (args) {
return $(this).slapos('prepareRequest', 'software_list', args);
},
softwareInfo: function (url, args) {
$.extend(args, {'software_url': decodeURIComponent(url)});
return $(this).slapos('prepareRequest', 'software_info', args);
}
};
$.fn.slapos = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.slapos');
}
};
}(jQuery));
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Slapos Test Suite</title>
<!-- Load local jQuery, removing access to $ (use jQuery, not $). -->
<script src="../libs/jquery/jquery-1.7.2.js"></script>
<script>jQuery.noConflict()</script>
<!-- Load local Modernizr -->
<script type="text/javascript" src="../libs/modernizr/modernizr-2.5.3.js"></script>
<!-- Load local QUnit (grunt requires v1.0.0 or newer). -->
<link rel="stylesheet" href="../libs/qunit/qunit.css" media="screen">
<script src="../libs/qunit/qunit.js"></script>
<!-- Load local SinonJs -->
<script type="text/javascript" src="../libs/sinon/sinon-1.3.2.js"></script>
<script type="text/javascript" src="../libs/sinon/sinon-qunit-1.0.0.js"></script>
<!--<script type="text/javascript" src="../libs/sinon/sinon-server-1.3.2.js"></script>-->
<!-- Load local lib and tests. -->
<script src="../src/jquery.slapos.js"></script>
<script src="jquery.slapos_test.js"></script>
</head>
<body>
<h1 id="qunit-header">jQuery Slapos Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<span>lame test markup</span>
<span>normal test markup</span>
<span>awesome test markup</span>
</div>
</body>
</html>
jQuery(function(){
var response, responseBody, url, data;
module("Cross-domain Tests");
test("200 response", function(){
expect(1);
stop(1);
jQuery.ajax({
url: 'http://sheldy.com:5000/200',
complete: function() { start(); },
statusCode: {
200: function(){ ok(true, "should get 200 status");}
}
});
});
test("404 response", function(){
expect(1);
stop(1);
jQuery.ajax({
url: 'http://sheldy.com:5000/request',
complete: function() { start(); },
statusCode: {
404: function(xhr){
ok(true, "should get 404 error status status="+xhr.status);
},
0: function(){
ok(false, "should get 404 not but receive 0");
}
}});
});
module("Storage Test", {
setup: function() {
this.myhost = 'http://www.example.com/api';
jQuery(document).slapos({'host': this.myhost});
}
});
test("", function() {
expect(5);
var test = "testValue",
newToken = "newToken",
nnToken = "";
equal(this.myhost, jQuery(document).slapos('host'), "should contain the same host when initialized");
jQuery(document).slapos('store', 'test', test);
equal(test, window.localStorage.test, 'should add new key "test" in local storage');
jQuery(document).slapos('access_token', newToken);
equal(newToken, window.localStorage.access_token, 'should add new key "access_token" by using its shortcut method');
nnToken = jQuery(document).slapos('access_token');
equal(nnToken, newToken, 'should put "newToken" value in nnToken')
jQuery(document).slapos('deleteStore', 'access_token');
ok(window.localStorage.getItem('access_token') === null, 'should delete "access_token" from localStorage');
});
module("Callback Tests", {
setup: function(){
this.server = sinon.sandbox.useFakeServer();
this.header = {"Content-Type":"application/json"};
// Discovery response
var discoBody = {
"request_instance": {
"authentication": true,
"url": "/request_instance",
"method": "POST",
"required": {
"status": "unicode",
"slave": "bool",
"title": "unicode",
"software_release": "unicode",
"software_type": "unicode",
"parameter": "object",
"sla": "object"
},
"optional": {}
}
};
var discoResponse = [200, this.header, JSON.stringify(discoBody)];
this.server.respondWith("GET", '/api', discoResponse);
// Error responses
this.bad_request = [400, this.header, 'Bad Request'];
this.unauthorized = [401, this.header, 'Unauthorized'];
this.payment = [402, this.header, 'Payment required'];
this.not_found = [404, this.header, 'Not found'];
this.server_error = [500, this.header, 'Internal server error'];
jQuery(document).slapos({'host': '/api'});
},
teardown: function(){
this.server.restore();
}
});
test("Bad request", function(){
expect(1);
this.server.respondWith("POST", "/request_instance", this.bad_request);
var callback = function(){
ok(true, "should use 400 callback");
},
statusCode = {
400: callback
};
var i = jQuery(document).slapos('instanceRequest', {
url: "/request_instance",
statusCode: statusCode,
complete: function () { start() }
});
this.server.respond();
});
test("Unauthorized", function(){
expect(1);
this.server.respondWith("POST", "/request_instance", this.unauthorized);
var callback = function(){
ok(true, "should use 401 callback");
},
statusCode = {
401: callback
};
jQuery(document).slapos('instanceRequest', {
url: "/request_instance",
statusCode: statusCode,
complete: function () { start() }
});
this.server.respond();
});
test("Payment required", function(){
expect(1);
this.server.respondWith("POST", "/request_instance", this.payment);
var callback = function(){
ok(true, "should use 402 callback");
},
statusCode = {
402: callback
};
jQuery(document).slapos('instanceRequest', {
url: "/request_instance",
statusCode: statusCode,
complete: function () { start() }
});
this.server.respond();
});
test("Not found", function(){
expect(1);
this.server.respondWith("POST", "/request_instance", this.not_found);
var callback = function(){
ok(true, "should use 404 callback");
},
statusCode = {
404: callback
};
jQuery(document).slapos('instanceRequest', {
url: "/request_instance",
statusCode: statusCode,
complete: function () { start() }
});
this.server.respond();
});
test("Internal server error", function(){
expect(1);
this.server.respondWith("POST", "/request_instance", this.server_error);
var callback = function(){
ok(true, "should use 500 callback");
},
statusCode = {
500: callback
};
jQuery(document).slapos('instanceRequest', {
url: "/request_instance",
statusCode: statusCode,
complete: function () { start() }
});
this.server.respond();
});
});
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: '<json:package.json>',
meta: {
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
},
concat: {
dist: {
src: ['<banner:meta.banner>', '<file_strip_banner:src/<%= pkg.name %>.js>'],
dest: 'dist/<%= pkg.name %>.js'
}
},
min: {
dist: {
src: ['<banner:meta.banner>', '<config:concat.dist.dest>'],
dest: 'dist/<%= pkg.name %>.min.js'
}
},
qunit: {
files: ['test/**/*.html']
},
lint: {
files: ['grunt.js', 'src/**/*.js', 'test/**/*.js']
},
watch: {
files: '<config:lint.files>',
tasks: 'lint qunit'
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true
},
globals: {
jQuery: true
}
},
uglify: {}
});
// Default task.
grunt.registerTask('default', 'lint qunit concat min');
};
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* iscroll-wrapper for jQquery.
* http://sanraul.com/projects/jqloader/
*
* Copyright (c) 2011 Raul Sanchez (http://www.sanraul.com)
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($){
$.fn.iscroll = function(options){
if(this.data('iScrollReady') == null){
var that = this;
var options = $.extend({}, options);
options.onScrollEnd = function(){
that.triggerHandler('onScrollEnd', [this]);
};
arguments.callee.object = new iScroll(this.get(0), options);
// NOTE: for some reason in a complex page the plugin does not register
// the size of the element. This will fix that in the meantime.
setTimeout(function(scroller){
scroller.refresh();
}, 1000, arguments.callee.object);
this.data('iScrollReady', true);
}else{
arguments.callee.object.refresh();
}
return arguments.callee.object;
};
})(jQuery);
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* my addition to supply convertible grids based on www.cssgrid.net by Andy Taylor */
/* ==================================================================================================================== */
/* ! The 1140px Grid V2 by Andy Taylor \ http://cssgrid.net \ http://www.twitter.com/andytlr \ http://www.andytlr.com */
/* ==================================================================================================================== */
.row, .fixedrow {
width: 100%;
margin: 0 auto;
overflow: hidden;
}
.span1, .span2, .span3, .span4, .span5, .span6, .span7, .span8, .span9, .span10, .span11 {
margin-right: 3.8%;
float: left;
min-height: 1px;
}
.row .span1, .fixedrow .span1 {
width: 4.85%;
}
.row .span2, .fixedrow .span2 {
width: 13.45%;
}
.row .span3, .fixedrow .span3 {
width: 22.05%;
}
.row .span4, .fixedrow .span4 {
width: 30.75%;
}
.row .span5, .fixedrow .span5 {
width: 39.45%;
}
.row .span6, .fixedrow .span6 {
width: 48%;
}
.row .span7, .fixedrow .span7 {
width: 56.75%;
}
.row .span8, .fixedrow .span8 {
width: 65.4%;
}
.row .span9, .fixedrow .span9 {
width: 74.05%;
}
.row .span10, .fixedrow .span10 {
width: 82.7%;
}
.row .span11, .fixedrow .span11 {
width: 91.35%;
}
.row .span12, .fixedrow .span12 {
width: 100%;
float: left;
}
.row .prepend1, .fixedrow .prepend1 {
}
.last {
margin-right: 0px;
}
img, object, embed {
max-width: 100%;
}
img {
height: auto;
}
/* touchscreens */
@media (min-width:768px) {
.touch body {
font-size: 1em;
line-height: normal;
}
/* Smaller screens */
body {
font-size: 0.9em;
line-height: normal;
}
}
/* Mobile */
@media (max-width:480px) {
body {
font-size: 1em;
-webkit-text-size-adjust: none;
}
.row, body {
width: 100%;
min-width: 0;
margin-left: 0px;
margin-right: 0px;
padding-left: 0px;
padding-right: 0px;
}
.row .span1, .row .span2, .row .span3, .row .span4, .row .span5, .row .span6, .row .span7, .row .span8, .row .span9, .row .span10, .row .span11, .row .span12 {
width: auto;
float: none;
margin-left: 0px;
margin-right: 0px;
padding-left: 20px;
padding-right: 20px;
}
}
\ No newline at end of file
This diff is collapsed.
body {
visibility: hidden;
}
.ui-panel {
-moz-box-shadow: 0 0 12px rgba(0,0,0,.6);
-webkit-box-shadow: 0 0 12px rgba(0,0,0,.6);
box-shadow: 0 0 12px rgba(0,0,0,.6);
}
div[data-id="main"] {
z-index: 9999;
}
.ui-mobile body {
visibility: visible;
}
.ui-panel-left {
position:absolute;
left:0;
top:0;
bottom:0;
}
.ui-panel-right {
position:absolute;
right:0;
top:0;
bottom:0;
}
.ui-crumbs {
max-width: 25%;
}
.splitview .ui-splitview-hidden {
display:none;
}
@media (min-width:480px) {
.splitview body {
margin: 0;
}
.splitview .ui-page{
bottom: 0;
}
.splitview .ui-header {
position:absolute;
top:0;
bottom:auto;
left:0;
right:0;
z-index: 1000;
}
.splitview .ui-footer {
position:absolute;
top:auto;
bottom:0;
left:0;
right:0;
z-index:1000;
}
.splitview .ui-content {
position:absolute;
top:40px;
bottom:0;
left:0;
right:0;
overflow:auto;
-webkit-overflow-scrolling:touch;
z-index:1;
}
}
/************************************************************************************************************
popover css for portrait orientation, modified from
http://www.cagintranet.com/archive/create-an-ipad-like-dropdown-popover/
************************************************************************************************************/
.panel-popover .popover_triangle {left:7px;}
.panel-popover {
color: black;
display:none;
font-weight: normal;
line-height: 1;
cursor: auto;
position: absolute;
top:55px;
left:10px;
background-color: white;
z-index:5000000;
border: 3px solid black;
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
-webkit-transition: opacity 0.25s linear;
-moz-transition: opacity 0.25s linear;
transition: opacity 0.25s linear;
overflow-x:visible;
height:80%;
}
.panel-popover > .popover_triangle {
position: absolute;
top: -34px;
font-size: 0px;
line-height: 0%;
width: 0px;
border-top: 16px solid rgba(0,0,0,0);
border-left: 16px solid rgba(0,0,0,0);
border-right: 16px solid rgba(0,0,0,0);
border-bottom: 16px solid black;
}
.panel-popover div[data-role="page"] {
height: inherit;
overflow-y:auto;
}
/**********************************************************************************************************
CSS animations for panel resize using new data-width attribute.
**********************************************************************************************************/
This diff is collapsed.
/*
* jquery.mobile.vifib
*
*
* Copyright (c) 2012 Nexedi
* Author: Thomas Lechauve
*/
(function($) {
// Collection method.
$.fn.vifib = function() {
return this.each(function() {
});
};
}(jQuery));
This diff is collapsed.
(function(){var q=function(){function c(a){return(""+a).replace(/&(?!\w+;)|[<>"']/g,function(a){return k[a]||a})}var e=Object.prototype.toString;Array.isArray=Array.isArray||function(a){return"[object Array]"==e.call(a)};var i=String.prototype.trim,g;if(i)g=function(a){return null==a?"":i.call(a)};else{var h,m;/\S/.test("\u00a0")?(h=/^[\s\xA0]+/,m=/[\s\xA0]+$/):(h=/^\s+/,m=/\s+$/);g=function(a){return null==a?"":a.toString().replace(h,"").replace(m,"")}}var k={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;",
"'":"&#39;"},o={},p=function(){};p.prototype={otag:"{{",ctag:"}}",pragmas:{},buffer:[],pragmas_implemented:{"IMPLICIT-ITERATOR":!0},context:{},render:function(a,d,b,f){if(!f)this.context=d,this.buffer=[];if(this.includes("",a)){var a=this.render_pragmas(a),j=this.render_section(a,d,b);!1===j&&(j=this.render_tags(a,d,b,f));if(f)return j;this.sendLines(j)}else{if(f)return a;this.send(a)}},send:function(a){""!==a&&this.buffer.push(a)},sendLines:function(a){if(a)for(var a=a.split("\n"),d=0;d<a.length;d++)this.send(a[d])},
render_pragmas:function(a){if(!this.includes("%",a))return a;var d=this,b=this.getCachedRegex("render_pragmas",function(a,d){return RegExp(a+"%([\\w-]+) ?([\\w]+=[\\w]+)?"+d,"g")});return a.replace(b,function(a,b,e){if(!d.pragmas_implemented[b])throw{message:"This implementation of mustache doesn't understand the '"+b+"' pragma"};d.pragmas[b]={};e&&(a=e.split("="),d.pragmas[b][a[0]]=a[1]);return""})},render_partial:function(a,d,b){a=g(a);if(!b||void 0===b[a])throw{message:"unknown_partial '"+a+"'"};
return!d||"object"!=typeof d[a]?this.render(b[a],d,b,!0):this.render(b[a],d[a],b,!0)},render_section:function(a,d,b){if(!this.includes("#",a)&&!this.includes("^",a))return!1;var f=this,j=this.getCachedRegex("render_section",function(a,b){return RegExp("^([\\s\\S]*?)"+a+"(\\^|\\#)\\s*(.+)\\s*"+b+"\n*([\\s\\S]*?)"+a+"\\/\\s*\\3\\s*"+b+"\\s*([\\s\\S]*)$","g")});return a.replace(j,function(a,j,e,c,g,h){var a=j?f.render_tags(j,d,b,!0):"",h=h?f.render(h,d,b,!0):"",n,c=f.find(c,d);"^"===e?n=!c||Array.isArray(c)&&
0===c.length?f.render(g,d,b,!0):"":"#"===e&&(n=Array.isArray(c)?f.map(c,function(a){return f.render(g,f.create_context(a),b,!0)}).join(""):f.is_object(c)?f.render(g,f.create_context(c),b,!0):"function"==typeof c?c.call(d,g,function(a){return f.render(a,d,b,!0)}):c?f.render(g,d,b,!0):"");return a+n+h})},render_tags:function(a,d,b,f){for(var j=this,e=function(){return j.getCachedRegex("render_tags",function(a,b){return RegExp(a+"(=|!|>|&|\\{|%)?([^#\\^]+?)\\1?"+b+"+","g")})},g=e(),h=function(a,f,h){switch(f){case "!":return"";
case "=":return j.set_delimiters(h),g=e(),"";case ">":return j.render_partial(h,d,b);case "{":case "&":return j.find(h,d);default:return c(j.find(h,d))}},a=a.split("\n"),i=0;i<a.length;i++)a[i]=a[i].replace(g,h,this),f||this.send(a[i]);if(f)return a.join("\n")},set_delimiters:function(a){a=a.split(" ");this.otag=this.escape_regex(a[0]);this.ctag=this.escape_regex(a[1])},escape_regex:function(a){if(!arguments.callee.sRE)arguments.callee.sRE=RegExp("(\\/|\\.|\\*|\\+|\\?|\\||\\(|\\)|\\[|\\]|\\{|\\}|\\\\)",
"g");return a.replace(arguments.callee.sRE,"\\$1")},find:function(a,d){function b(a){return!1===a||0===a||a}var a=g(a),f;if(a.match(/([a-z_]+)\./ig)){var c=this.walk_context(a,d);b(c)&&(f=c)}else b(d[a])?f=d[a]:b(this.context[a])&&(f=this.context[a]);return"function"==typeof f?f.apply(d):void 0!==f?f:""},walk_context:function(a,d){for(var b=a.split("."),f=void 0!=d[b[0]]?d:this.context,c=f[b.shift()];void 0!=c&&0<b.length;)f=c,c=c[b.shift()];return"function"==typeof c?c.apply(f):c},includes:function(a,
d){return-1!=d.indexOf(this.otag+a)},create_context:function(a){if(this.is_object(a))return a;var d=".";if(this.pragmas["IMPLICIT-ITERATOR"])d=this.pragmas["IMPLICIT-ITERATOR"].iterator;var b={};b[d]=a;return b},is_object:function(a){return a&&"object"==typeof a},map:function(a,d){if("function"==typeof a.map)return a.map(d);for(var b=[],c=a.length,e=0;e<c;e++)b.push(d(a[e]));return b},getCachedRegex:function(a,d){var b=o[this.otag];b||(b=o[this.otag]={});var c=b[this.ctag];c||(c=b[this.ctag]={});
(b=c[a])||(b=c[a]=d(this.otag,this.ctag));return b}};return{name:"mustache.js",version:"0.4.0",to_html:function(a,c,b,f){var e=new p;if(f)e.send=f;e.render(a,c||{},b);if(!f)return e.buffer.join("\n")}}}();(function(){var c={VERSION:"0.10",templates:{},$:"undefined"!==typeof window?window.jQuery||window.Zepto||null:null,addTemplate:function(e,i){if("object"===typeof e)for(var g in e)this.addTemplate(g,e[g]);else c[e]?console.error("Invalid name: "+e+"."):c.templates[e]?console.error('Template "'+e+
' " exists'):(c.templates[e]=i,c[e]=function(g,i){var g=g||{},k=q.to_html(c.templates[e],g,c.templates);return c.$&&!i?c.$(k):k})},clearAll:function(){for(var e in c.templates)delete c[e];c.templates={}},refresh:function(){c.clearAll();c.grabTemplates()},grabTemplates:function(){var e,i=document.getElementsByTagName("script"),g,h=[];for(e=0,l=i.length;e<l;e++)if((g=i[e])&&g.innerHTML&&g.id&&("text/html"===g.type||"text/x-icanhaz"===g.type))c.addTemplate(g.id,"".trim?g.innerHTML.trim():g.innerHTML.replace(/^\s+/,
"").replace(/\s+$/,"")),h.unshift(g);for(e=0,l=h.length;e<l;e++)h[e].parentNode.removeChild(h[e])}};"undefined"!==typeof require?module.exports=c:window.ich=c;"undefined"!==typeof document&&(c.$?c.$(function(){c.grabTemplates()}):document.addEventListener("DOMContentLoaded",function(){c.grabTemplates()},!0))})()})();
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* Swipe 1.0
*
* Brad Birdsall, Prime
* Copyright 2011, Licensed GPL & MIT
*
*/
window.Swipe=function(a,b){if(!a)return null;var c=this;this.options=b||{},this.index=this.options.startSlide||0,this.speed=this.options.speed||300,this.callback=this.options.callback||function(){},this.delay=this.options.auto||0,this.container=a,this.element=this.container.children[0],this.container.style.overflow="hidden",this.element.style.listStyle="none",this.setup(),this.begin(),this.element.addEventListener&&(this.element.addEventListener("touchstart",this,!1),this.element.addEventListener("touchmove",this,!1),this.element.addEventListener("touchend",this,!1),this.element.addEventListener("webkitTransitionEnd",this,!1),this.element.addEventListener("msTransitionEnd",this,!1),this.element.addEventListener("oTransitionEnd",this,!1),this.element.addEventListener("transitionend",this,!1),window.addEventListener("resize",this,!1))},Swipe.prototype={setup:function(){this.slides=this.element.children,this.length=this.slides.length;if(this.length<2)return null;this.width=this.container.getBoundingClientRect().width;if(!this.width)return null;this.container.style.visibility="hidden",this.element.style.width=this.slides.length*this.width+"px";var a=this.slides.length;while(a--){var b=this.slides[a];b.style.width=this.width+"px",b.style.display="table-cell",b.style.verticalAlign="top"}this.slide(this.index,0),this.container.style.visibility="visible"},slide:function(a,b){var c=this.element.style;if(b==undefined){b=this.speed;}c.webkitTransitionDuration=c.MozTransitionDuration=c.msTransitionDuration=c.OTransitionDuration=c.transitionDuration=b+"ms",c.webkitTransform="translate3d("+ -(a*this.width)+"px,0,0)",c.msTransform=c.MozTransform=c.OTransform="translateX("+ -(a*this.width)+"px)",this.index=a},getPos:function(){return this.index},prev:function(a){this.delay=a||0,clearTimeout(this.interval),this.index&&this.slide(this.index-1,this.speed)},next:function(a){this.delay=a||0,clearTimeout(this.interval),this.index<this.length-1?this.slide(this.index+1,this.speed):this.slide(0,this.speed)},begin:function(){var a=this;this.interval=this.delay?setTimeout(function(){a.next(a.delay)},this.delay):0},stop:function(){this.delay=0,clearTimeout(this.interval)},resume:function(){this.delay=this.options.auto||0,this.begin()},handleEvent:function(a){switch(a.type){case"touchstart":this.onTouchStart(a);break;case"touchmove":this.onTouchMove(a);break;case"touchend":this.onTouchEnd(a);break;case"webkitTransitionEnd":case"msTransitionEnd":case"oTransitionEnd":case"transitionend":this.transitionEnd(a);break;case"resize":this.setup()}},transitionEnd:function(a){this.delay&&this.begin(),this.callback(a,this.index,this.slides[this.index])},onTouchStart:function(a){this.start={pageX:a.touches[0].pageX,pageY:a.touches[0].pageY,time:Number(new Date)},this.isScrolling=undefined,this.deltaX=0,this.element.style.webkitTransitionDuration=0},onTouchMove:function(a){if(a.touches.length>1||a.scale&&a.scale!==1)return;this.deltaX=a.touches[0].pageX-this.start.pageX,typeof this.isScrolling=="undefined"&&(this.isScrolling=!!(this.isScrolling||Math.abs(this.deltaX)<Math.abs(a.touches[0].pageY-this.start.pageY))),this.isScrolling||(a.preventDefault(),clearTimeout(this.interval),this.deltaX=this.deltaX/(!this.index&&this.deltaX>0||this.index==this.length-1&&this.deltaX<0?Math.abs(this.deltaX)/this.width+1:1),this.element.style.webkitTransform="translate3d("+(this.deltaX-this.index*this.width)+"px,0,0)")},onTouchEnd:function(a){var b=Number(new Date)-this.start.time<250&&Math.abs(this.deltaX)>20||Math.abs(this.deltaX)>this.width/2,c=!this.index&&this.deltaX>0||this.index==this.length-1&&this.deltaX<0;this.isScrolling||this.slide(this.index+(b&&!c?this.deltaX<0?1:-1:0),this.speed)}}
\ No newline at end of file
This diff is collapsed.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Mobile Vifib Test Suite</title>
<!-- Load local jQuery, removing access to $ (use jQuery, not $). -->
<script src="../libs/jquery/jquery.js"></script>
<script>jQuery.noConflict()</script>
<!-- Load local QUnit (grunt requires v1.0.0 or newer). -->
<link rel="stylesheet" href="../libs/qunit/qunit.css" media="screen">
<script src="../libs/qunit/qunit.js"></script>
<!-- Load local lib and tests. -->
<script src="../src/jquery.mobile.vifib.js"></script>
<script src="jquery.mobile.vifib_test.js"></script>
</head>
<body>
<h1 id="qunit-header">jQuery Mobile Vifib Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<span>lame test markup</span>
<span>normal test markup</span>
<span>awesome test markup</span>
</div>
</body>
</html>
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment