Author: jmorliaguet Date: Sat Dec 31 00:06:52 2005 New Revision: 2100 Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_tooltip.html cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html Log:
- more readable / robust comments using: <!-- json-data: ... --> 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 Sat Dec 31 00:06:52 2005 @@ -137,6 +137,7 @@ getNodeData: function(element) { var node = $(element); + var regExp = new RegExp(/^\sjson-data:/); while(true) { node = node.previousSibling; if (!node) return null; @@ -144,9 +145,10 @@ if (type == 1) return null; if (type == 8 || type == 4) { var comment = node.nodeValue; - comment = comment.replace(/(^\[CDATA\[|\]\]$)/gm, ''); - if (!comment) return null; - return JSON.parse(comment); + if (comment && comment.match(regExp)) { + comment = comment.replace(regExp, ''); + return JSON.parse(comment); + } } } return null; Modified: cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html ============================================================================== --- cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html (original) +++ cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html Sat Dec 31 00:06:52 2005 @@ -8,6 +8,7 @@ <title>CPSSkins Unit test file</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <script src="../../prototype.js" type="text/javascript"></script> + <script src="../../json.js" type="text/javascript"></script> <script src="../../cpsskins.js" type="text/javascript"></script> <link rel="stylesheet" href="contextualmenus.css" type="text/css" /> </head> @@ -22,26 +23,37 @@ <h2>Menu 1</h2> <div id="testArea1"> - <![CDATA[{"copyable":true}]]> + <!-- Contextual menu widget --> + <cpsskins:contextmenu controller="controller" class="large"> + <item label="Edit" action="edit" visible="editable" /> + <item label="Copy" action="copy" /> + <item label="Paste" action="paste" visible="editable" /> + <submenu label="Format" visible="formattable"> + <items action="format" choices="formats" /> + </submenu> + <item label="Delete" action="delete" visible="editable" + confirm="Deleting, are you sure?" /> + </cpsskins:contextmenu> + + <!-- json-data: {"copyable":true} --> <div id="area1" class="pad">area1</div> - <![CDATA[{"formattable":true,"formats":[ - {"choice":"style","label":"Style"}, - {"choice":"widget","label":"Widget"}] - } ]]> <div id="area2" class="pad">area2</div> - <![CDATA[{"editable":true}]]> + <!-- json-data: {"editable":true} --> <div id="area3" class="pad">area3</div> - <![CDATA[{"formattable":true,"formats":[ - {"choice":"style","label":"Style"}, - {"choice":"widget","label":"Widget"} - {"choice":"effect","label":"Effect"}] - } ]]> + <!-- json-data: + {"formattable":true, + "formats":[ + {"choice":"style","label":"Style"}, + {"choice":"widget","label":"Widget"}, + {"choice":"effect","label":"Effect"} + ]} + --> <div id="area4" class="pad">area4 - <![CDATA[{"editable":true}]]> + <!-- json-data: {"editable":true} --> <div id="area5" class="pad">area5</div> </div> </div> @@ -51,37 +63,34 @@ <h2>Menu 2</h2> <div id="testArea2"> - <![CDATA[{"editable":true,"formattable":true,"formats":[ - {"choice":"style","label":"Style"}, - {"choice":"widget","label":"Widget"}],"targets":[ - {"choice":"here","label":"Paste here"}, - {"choice":"above","label":"Paste above"}] - } ]]> + <!-- Contextual menu widget --> + <cpsskins:contextmenu controller="controller" class="large"> + <item label="Edit" action="edit" visible="editable" /> + <item label="Copy" action="copy" /> + <item label="Paste" action="paste" visible="editable" /> + <submenu label="Format" visible="formattable"> + <items action="format" choices="formats" /> + </submenu> + <item label="Delete" action="delete" visible="editable" + confirm="Deleting, are you sure?" /> + </cpsskins:contextmenu> + + <!-- json-data: + {"editable":true,"formattable":true, + "formats":[ + {"choice":"style","label":"Style"}, + {"choice":"widget","label":"Widget"} + ], + "targets":[ + {"choice":"here","label":"Paste here"}, + {"choice":"above","label":"Paste above"} + ]} + --> <div id="area6" class="pad">area6</div> + </div> </div> - <!-- Contextual menu widget --> - <cpsskins:contextmenu controller="controller" class="large"> - - <item label="Edit" action="edit" visible="editable" /> - - <item label="Copy" action="copy" /> - - <item label="Paste" action="paste" visible="editable" /> - - <submenu label="Format" visible="formattable"> - - <items action="format" choices="formats" /> - - </submenu> - - <item label="Delete" action="delete" visible="editable" - confirm="Deleting, are you sure?" /> - - </cpsskins:contextmenu> - - <!-- Controller --> <script type="text/javascript"> function displayChoice(selected, choice) { Modified: cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_tooltip.html ============================================================================== --- cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_tooltip.html (original) +++ cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_tooltip.html Sat Dec 31 00:06:52 2005 @@ -18,13 +18,13 @@ <div id="area1"> - <![CDATA[{"hint":"Click here to open the document."}]]> + <!-- json-data: {"hint":"Click here to open the document."} --> <a href="#">Open</a> - <![CDATA[{"hint":"Click here to save the document."}]]> + <!-- json-data: {"hint":"Click here to save the document."} --> <a href="#">Save</a> - <![CDATA[{"hint":"Click here to close the document."}]]> + <!-- json-data: {"hint":"Click here to close the document."} --> <a href="#">Close</a> <cpsskins:tooltip showdelay="1000" hidedelay="500" /> @@ -35,13 +35,13 @@ <div id="area2"> - <![CDATA[{"hint":"Click here to open the file."}]]> + <!-- json-data: {"hint":"Click here to open the file."} --> <a href="#">Open</a> - <![CDATA[{"hint":"Click here to save the file."}]]> + <!-- json-data: {"hint":"Click here to save the file."} --> <a href="#">Save</a> - <![CDATA[{"hint":"Click here to close the file."}]]> + <!-- json-data: {"hint":"Click here to close the file."} --> <a href="#">Close</a> <cpsskins:tooltip showdelay="500" hidedelay="1000" /> 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 Sat Dec 31 00:06:52 2005 @@ -30,17 +30,17 @@ <div> <div id="e1"></div> <div> - <!-- {"a":"1","b":"2"} --> + <!-- json-data: {"a":"1","b":"2"} --> <div id="e2"></div> <div id="e3"></div> <div id="e4"> - <!-- {"a":"1"} --> + <!-- json-data: {"a":"1"} --> <div></div> <div id="e5"></div> </div> </div> <div></div> - <!-- + <!-- json-data: {"a":["1","2","3"], "b":{"c":1,"d":2}, "c":[[1],[2],[3]]} -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins