Author: jmorliaguet Date: Tue Dec 27 23:39:15 2005 New Revision: 2090 Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html Log:
- implementation of Identiable.getData() / test fix Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js ============================================================================== --- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original) +++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Tue Dec 27 23:39:15 2005 @@ -128,6 +128,23 @@ if (this.isIdentifiable(nodes[i])) { return false; } } return true; + }, + + getData: function(element) { + var node = $(element); + while(true) { + node = node.previousSibling; + if (!node) return null; + var type = node.nodeType; + if (type == 1) return null; + if (type == 8) { + var comment = node.nodeValue; + comment = comment.replace(/(^\[CDATA\[|\]\]$)/gm, ''); + if (!comment) return null; + return JSON.parse(comment); + } + } + return null; } }); Modified: cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html ============================================================================== --- cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html (original) +++ cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html Tue Dec 27 23:39:15 2005 @@ -4,6 +4,7 @@ <head> <title>CPSSkins Unit test file</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> + <script src="../../json.js" type="text/javascript"></script> <script src="../../prototype.js" type="text/javascript"></script> <script src="../../cpsskins.js" type="text/javascript"></script> <script src="../unittest.js" type="text/javascript"></script> @@ -37,7 +38,7 @@ <![CDATA[{ "a":"1", "b":{"c":1,"d":2} - }]] + }]]> <div id="e6"></div> </div> </div> @@ -116,9 +117,11 @@ testGetData: function() { with(this) { assertEqual(Identifiable.getData(e1), null); - assertEqual(Identifiable.getData(e2), {"a":"1","b":"2"}); + assertEqual($H(Identifiable.getData(e2)).inspect(), + $H({a:"1", b:"2"}).inspect()); assertEqual(Identifiable.getData(e5), null); - assertEqual(Identifiable.getData(e6), {"a":"1","b":{"c":1,"d":2}}); + assertEqual($H(Identifiable.getData(e6)).inspect(), + $H({"a":"1","b":{"c":1,"d":2}}).inspect()); }} }); -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins