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