Commit f7c8406d authored by Thomas Lechauve's avatar Thomas Lechauve

Clean entire vifib project

parent fd80c674
# 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');
};
This diff is collapsed.
This diff is collapsed.
/**
* QUnit v1.4.0 - A JavaScript Unit Testing Framework
*
* http://docs.jquery.com/QUnit
*
* Copyright (c) 2012 John Resig, Jörn Zaefferer
* Dual licensed under the MIT (MIT-LICENSE.txt)
* or GPL (GPL-LICENSE.txt) licenses.
*/
/** Font Family and Sizes */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
}
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-tests { font-size: smaller; }
/** Resets */
#qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult {
margin: 0;
padding: 0;
}
/** Header */
#qunit-header {
padding: 0.5em 0 0.5em 1em;
color: #8699a4;
background-color: #0d3349;
font-size: 1.5em;
line-height: 1em;
font-weight: normal;
border-radius: 15px 15px 0 0;
-moz-border-radius: 15px 15px 0 0;
-webkit-border-top-right-radius: 15px;
-webkit-border-top-left-radius: 15px;
}
#qunit-header a {
text-decoration: none;
color: #c2ccd1;
}
#qunit-header a:hover,
#qunit-header a:focus {
color: #fff;
}
#qunit-header label {
display: inline-block;
}
#qunit-banner {
height: 5px;
}
#qunit-testrunner-toolbar {
padding: 0.5em 0 0.5em 2em;
color: #5E740B;
background-color: #eee;
}
#qunit-userAgent {
padding: 0.5em 0 0.5em 2.5em;
background-color: #2b81af;
color: #fff;
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
}
/** Tests: Pass/Fail */
#qunit-tests {
list-style-position: inside;
}
#qunit-tests li {
padding: 0.4em 0.5em 0.4em 2.5em;
border-bottom: 1px solid #fff;
list-style-position: inside;
}
#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
display: none;
}
#qunit-tests li strong {
cursor: pointer;
}
#qunit-tests li a {
padding: 0.5em;
color: #c2ccd1;
text-decoration: none;
}
#qunit-tests li a:hover,
#qunit-tests li a:focus {
color: #000;
}
#qunit-tests ol {
margin-top: 0.5em;
padding: 0.5em;
background-color: #fff;
border-radius: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
box-shadow: inset 0px 2px 13px #999;
-moz-box-shadow: inset 0px 2px 13px #999;
-webkit-box-shadow: inset 0px 2px 13px #999;
}
#qunit-tests table {
border-collapse: collapse;
margin-top: .2em;
}
#qunit-tests th {
text-align: right;
vertical-align: top;
padding: 0 .5em 0 0;
}
#qunit-tests td {
vertical-align: top;
}
#qunit-tests pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
#qunit-tests del {
background-color: #e0f2be;
color: #374e0c;
text-decoration: none;
}
#qunit-tests ins {
background-color: #ffcaca;
color: #500;
text-decoration: none;
}
/*** Test Counts */
#qunit-tests b.counts { color: black; }
#qunit-tests b.passed { color: #5E740B; }
#qunit-tests b.failed { color: #710909; }
#qunit-tests li li {
margin: 0.5em;
padding: 0.4em 0.5em 0.4em 0.5em;
background-color: #fff;
border-bottom: none;
list-style-position: inside;
}
/*** Passing Styles */
#qunit-tests li li.pass {
color: #5E740B;
background-color: #fff;
border-left: 26px solid #C6E746;
}
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
#qunit-tests .pass .test-name { color: #366097; }
#qunit-tests .pass .test-actual,
#qunit-tests .pass .test-expected { color: #999999; }
#qunit-banner.qunit-pass { background-color: #C6E746; }
/*** Failing Styles */
#qunit-tests li li.fail {
color: #710909;
background-color: #fff;
border-left: 26px solid #EE5757;
white-space: pre;
}
#qunit-tests > li:last-child {
border-radius: 0 0 15px 15px;
-moz-border-radius: 0 0 15px 15px;
-webkit-border-bottom-right-radius: 15px;
-webkit-border-bottom-left-radius: 15px;
}
#qunit-tests .fail { color: #000000; background-color: #EE5757; }
#qunit-tests .fail .test-name,
#qunit-tests .fail .module-name { color: #000000; }
#qunit-tests .fail .test-actual { color: #EE5757; }
#qunit-tests .fail .test-expected { color: green; }
#qunit-banner.qunit-fail { background-color: #EE5757; }
/** Result */
#qunit-testresult {
padding: 0.5em 0.5em 0.5em 2.5em;
color: #2b81af;
background-color: #D2E0E6;
border-bottom: 1px solid white;
}
/** Fixture */
#qunit-fixture {
position: absolute;
top: -10000px;
left: -10000px;
width: 1000px;
height: 1000px;
}
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.slapos",
"title": "jQuery Slapos",
"description": "API to use slapos stuff in a web application",
"version": "0.1.0",
"homepage": "",
"author": {
"name": "Thomas Lechauve",
"email": "thomas.lechauve@gmail.com"
},
"repository": {
"type": "git",
"url": "http://git.erp5.org/repos/slapos.core.git"
},
"bugs": {
"url": ""
},
"licenses": [
],
"dependencies": {
"jquery": "~1.7",
"sinon": "1.3.2",
"modernizr": "2.5.3"
},
"keywords": []
}
(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>
This diff is collapsed.
This diff is collapsed.
/*! 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');
};
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.
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.
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.
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.
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