Commit 0e8ab6e4 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

JIO is now compatible with require.js.

parent b233a99c
......@@ -8,14 +8,13 @@
<body>
<div id="qunit"></div>
<script type="text/javascript" src="qunit/qunit-1.5.0.js"></script>
<script type="text/javascript" src="js/jquery/jquery.js"></script>
<script type="text/javascript" src="unhosted/localorcookiestorage.js"></script>
<script type="text/javascript" src="unhosted/jio.js"></script>
<script type="text/javascript" src="unhosted/base64.js"></script>
<script type="text/javascript" src="jio.dummystorages.js"></script>
<script type="text/javascript" src="unhosted/jio.storage.js"></script>
<script type="text/javascript" src="sinon/sinon-1.3.4.js"></script>
<script type="text/javascript" src="sinon/sinon-qunit-1.0.0.js"></script>
<script type="text/javascript" src="jiotests.js"></script>
<script type="text/javascript">
<!--
var require = {}; // IE compatibility
//-->
</script>
<script data-main="jiotests" src="require/require.js"></script>
</body>
</html>
......@@ -2,51 +2,21 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
<title>JIO QUnit/Sinon Test</title>
<link rel="stylesheet" href="qunit/qunit-1.5.0.css" />
</head>
<body>
<div id="qunit"></div>
<script type="text/javascript" src="qunit/qunit-1.5.0.js"></script>
<script type="text/javascript" src="sinon/sinon-1.3.4.js"></script>
<script type="text/javascript" src="sinon/sinon-qunit-1.0.0.js"></script>
<script type="text/javascript" src="js/jquery/jquery.js"></script>
<script type="text/javascript" src="unhosted/localorcookiestorage.js">
</script>
<script type="text/javascript" src="unhosted/jio.js"></script>
<script type="text/javascript" src="unhosted/base64.js"></script>
<script type="text/javascript" src="jio.dummystorages.js"></script>
<script type="text/javascript" src="unhosted/jio.storage.js"></script>
<script type="text/javascript">
<!--
var maClassPasProtegee = function () {
this.monAttributPasProtegee = 0;
};
maClassPasProtegee.prototype = {
getMonAttribut: function () {
return this.monAttributPasProtegee;
},
logMonAttribut: function () {
console.log (this.monAttributPasProtegee);
}
};
var maclass1 = new maClassPasProtegee();
maclass1.logMonAttribut();
maclass1.monAttributPasProtegee ++;
maclass1.logMonAttribut();
var maClassProtegee = function () {
var publ = {}, priv = {};
priv.monAttributProtegee = 0;
publ.getMonAttribut = function () {
return priv.monAttributProtegee;
};
publ.logMonAttribut = function () {
console.log (priv.monAttributProtegee);
};
return publ;
};
var maclass2 = new maClassProtegee();
maclass2.logMonAttribut();
maclass2.monAttributProtegee ++;
maclass2.logMonAttribut();
//-->
</script>
<script type="text/javascript" src="jiotests.js"></script>
</body>
</html>
// Adds 3 dummy storages for Jio
// Adds 3 dummy storages to JIO
// type:
// - dummyallok
// - dummyallfail
// - dummyallnotfound
// - dummyall3tries
;(function ( Jio ) {
// check dependencies
var errorDependencies=function(){$.error('Cannot find Jio');};
try{if (!Jio){
errorDependencies();return;
}} catch (e){
errorDependencies();return;}
////////////////////////////////////////////////////////////////////////////
// globals
var jioGlobalObj = Jio.getGlobalObject(),
// end globals
////////////////////////////////////////////////////////////////////////////
(function () { var jio_dummy_storage_loader = function ( Jio ) {
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 1 : all ok
......@@ -287,4 +274,12 @@
return DummyStorageAll3Tries(options);
});
})( JIO );
};
if (window.requirejs) {
define ('JIODummyStorages',['JIO'], jio_dummy_storage_loader);
} else {
jio_dummy_storage_loader ( JIO );
}
})();
\ No newline at end of file
(function () { var thisfun = function(loader) {
var JIO = loader.JIO,
LocalOrCookieStorage = loader.LocalOrCookieStorage,
Base64 = loader.Base64;
(function(){
//// clear jio localstorage
for (var k in LocalOrCookieStorage.getAll()) {
var splitk = k.split('/');
......@@ -271,7 +274,7 @@ test ('Document save', function () {
// We launch a saving to localstorage and we check if the file is
// realy saved. Then save again and check if
var o = {}, clock = this.sandbox.useFakeTimers(), t = this, tmp,
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value,lmcd){
o.f = function (result) {
deepEqual(result.isSaved,value,message);};
......@@ -284,11 +287,12 @@ test ('Document save', function () {
ok(false, 'no response / too much results');
else {
// check content
tmp = LocalOrCookieStorage.getItem ('jio/local/MrSaveName/jiotests/file');
tmp.lmcd = lmcd(tmp.creationDate,tmp.lastModified);
delete tmp.lastModified;
delete tmp.creationDate;
deepEqual (tmp,{'fileName':'file','fileContent':'content',
o.tmp = LocalOrCookieStorage.getItem (
'jio/local/MrSaveName/jiotests/file');
o.tmp.lmcd = lmcd(o.tmp.creationDate,o.tmp.lastModified);
delete o.tmp.lastModified;
delete o.tmp.creationDate;
deepEqual (o.tmp,{'fileName':'file','fileContent':'content',
'lmcd':true},'check content');
}
};
......@@ -397,8 +401,9 @@ test ('Document remove', function () {
ok(false, 'no response / too much results');
else {
// check if the file is still there
var tmp = LocalOrCookieStorage.getItem ('jio/local/MrRemoveName/jiotests/file');
ok (!tmp, 'check no content');
o.tmp = LocalOrCookieStorage.getItem (
'jio/local/MrRemoveName/jiotests/file');
ok (!o.tmp, 'check no content');
}
};
o.jio = JIO.createNew({'type':'local','userName':'MrRemoveName'},
......@@ -502,7 +507,8 @@ test ('Document save', function () {
"PROPFIND","https://ca-davstorage:8080/dav/davsave/jiotests/file",
[errnoprop,{'Content-Type':'text/xml; charset="utf-8"'},
davsave]);
server.respondWith ("PUT",
server.respondWith (
"PUT",
"https://ca-davstorage:8080/dav/davsave/jiotests/file",
[errnoput, {'Content-Type':'x-www-form-urlencoded'},
'content']);
......@@ -681,7 +687,8 @@ test ('Check name availability', function () {
{'type':'dummyall3tries','userName':'3'}]},
{'type':'dummyall3tries','userName':'4'}]},
{'ID':'jiotests'});
mytest('DummyStorageAll{3tries,{3tries,3tries},3tries} : name available',true);
mytest('DummyStorageAll{3tries,{3tries,3tries},3tries} : name available'
,true);
o.jio.stop();
});
......@@ -804,5 +811,31 @@ test ('Remove document', function () {
mytest('DummyStorageAllOK,3tries: remove document .',true);
o.jio.stop();
});
// end require
}; // end thisfun
if (window.requirejs) {
require.config ({
paths: {
jiotestsloader: 'jiotests.loader',
LocalOrCookieStorage: 'unhosted/localorcookiestorage',
jQuery: 'js/jquery/jquery',
JIO: 'unhosted/jio',
Base64: 'unhosted/base64',
JIODummyStorages: 'jio.dummystorages',
JIOStorages: 'unhosted/jio.storage',
QUnit: 'qunit/qunit-1.5.0',
Sinon: 'sinon/sinon-1.3.4',
SinonQUnit: 'sinon/sinon-qunit-1.0.0'
}
});
require(['jiotestsloader'],thisfun);
} else {
thisfun ({LocalOrCookieStorage:LocalOrCookieStorage,
JIO:JIO,
Base64:Base64});
}
})();
define ('jiotestsloader',[
'LocalOrCookieStorage','JIO','Base64',
'JIODummyStorages','JIOStorages','jQuery'],
function (LocalOrCookieStorage,JIO,Base64) {
return {
LocalOrCookieStorage: LocalOrCookieStorage,
JIO: JIO,
Base64: Base64
};
});
This diff is collapsed.
;var JIO =
(function () {
(function () { var jio_loader_function = function ( LocalOrCookieStorage ) {
////////////////////////////////////////////////////////////////////////////
// constants
......@@ -181,20 +181,7 @@
////////////////////////////////////////////////////////////////////////////
// Tools
checkJioDependencies = function() {
var retval = true,
err = function (name) {
console.error ('Fail to load ' + name);
retval = false;
};
try { if (!JSON) { err('JSON'); } }
catch (e) { err('JSON'); }
try { if (!jQuery) { err('jQuery'); } }
catch (e) { err('jQuery'); }
try { if (!LocalOrCookieStorage) { err('LocalOrCookieStorage'); } }
catch (e) { err('LocalOrCookieStorage'); }
return retval;
},
// end Tools
////////////////////////////////////////////////////////////////////////////
......@@ -204,9 +191,6 @@
// end Classes
////////////////////////////////////////////////////////////////////////////
// check dependencies
if (!checkJioDependencies()) { return; }
////////////////////////////////////////////////////////////////////////////
// Publisher Subcriber
PubSub = function () {
......@@ -1206,4 +1190,13 @@
return new JioCreator();
// end Jio Creator
////////////////////////////////////////////////////////////////////////////
};
if (window.requirejs) {
define ('JIO',['LocalOrCookieStorage','jQuery'],jio_loader_function);
return undefined;
} else {
return jio_loader_function ( LocalOrCookieStorage, jQuery );
}
})();
\ No newline at end of file
// Adds 3 storages for Jio
// Adds 3 storages to JIO
// type:
// - local
// - dav
// - replicate
;(function ( Jio ) {
////////////////////////////////////////////////////////////////////////////
// globals
var jioGlobalObj = Jio.getGlobalObject(),
// end globals
////////////////////////////////////////////////////////////////////////////
(function () { var jio_storage_loader = function ( LocalOrCookieStorage, Jio ) {
////////////////////////////////////////////////////////////////////////////
// Tools
checkJioDependencies = function() {
var checkJioDependencies = function() {
var retval = true,
err = function (name) {
console.error ('Fail to load ' + name);
......@@ -51,7 +45,7 @@
setTimeout(function () {
var localStorageObject = null;
localStorageObject = jioGlobalObj.localStorage.getAll();
localStorageObject = LocalOrCookieStorage.getAll();
for (var k in localStorageObject) {
var splitk = k.split('/');
if (splitk[0] === 'jio' &&
......@@ -77,7 +71,7 @@
var doc = null;
// reading
doc = jioGlobalObj.localStorage.getItem(
doc = LocalOrCookieStorage.getItem(
'jio/local/'+that.getStorageUserName()+'/'+
that.getApplicantID()+'/'+
that.getFileName());
......@@ -94,7 +88,7 @@
doc.lastModified = Date.now();
doc.fileContent = that.getFileContent();
}
jioGlobalObj.localStorage.setItem(
LocalOrCookieStorage.setItem(
'jio/local/'+that.getStorageUserName()+'/'+
that.getApplicantID()+'/'+
that.getFileName(), doc);
......@@ -116,7 +110,7 @@
var doc = null, settings = $.extend(
{'getContent':true},that.cloneOptionObject());
doc = jioGlobalObj.localStorage.getItem(
doc = LocalOrCookieStorage.getItem(
'jio/local/'+that.getStorageUserName()+'/'+
that.getApplicantID()+'/'+that.getFileName());
if (!doc) {
......@@ -144,7 +138,7 @@
var list = [], localStorageObject = null, k = 'key',
splitk = ['splitedkey'], fileObject = {};
localStorageObject = jioGlobalObj.localStorage.getAll();
localStorageObject = LocalOrCookieStorage.getAll();
for (k in localStorageObject) {
splitk = k.split('/');
if (splitk[0] === 'jio' &&
......@@ -170,7 +164,7 @@
setTimeout (function () {
// deleting
jioGlobalObj.localStorage.deleteItem(
LocalOrCookieStorage.deleteItem(
'jio/local/'+
that.getStorageUserName()+'/'+
that.getApplicantID()+'/'+
......@@ -729,4 +723,14 @@
return new ReplicateStorage(options);
});
})( JIO );
};
if (window.requirejs) {
define ('JIOStorages',
['LocalOrCookieStorage','JIO','jQuery'],
jio_storage_loader);
} else {
jio_storage_loader ( LocalOrCookieStorage, JIO, jQuery );
}
})();
\ No newline at end of file
;var LocalOrCookieStorage =
(function () {
(function () { var local_cookie_loader_function = function () {
// localorcookiestorage.js
// Creates an object that can store persistent information in localStorage.
// If it is not supported by the browser, it will store in cookies.
......@@ -89,4 +88,13 @@
// end cookies & localStorages
////////////////////////////////////////////////////////////////////////////
};
if (window.requirejs) {
define ('LocalOrCookieStorage',[], local_cookie_loader_function);
return undefined;
} else {
return local_cookie_loader_function ();
}
})();
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