Revision: 5388
Author:   [email protected]
Date:     Wed May  1 10:22:42 2013
Log:      Add support for HTML5 <input> types.
https://codereview.appspot.com/9023047

* Whitelist input type={search,tel,url,email,datetime,date,month,week,
  time,datetime-local,number,range,color}.
* Add properties/methods for numeric field types: stepUp, stepDown,
  step, min, max, valueAsNumber.
* Export assertNaN to guest tests.

Does not work in ES5/3 mode because the cajoler is not allowing the new
types despite the schema change, but we can debug that later.

Fixes <https://code.google.com/p/google-caja/issues/detail?id=1609>.

[email protected]

http://code.google.com/p/google-caja/source/detail?r=5388

Modified:
 /trunk/src/com/google/caja/lang/html/html4-attributes-defs.json
 /trunk/src/com/google/caja/plugin/domado.js
 /trunk/tests/com/google/caja/plugin/browser-test-case.js
 /trunk/tests/com/google/caja/plugin/es53-test-domado-forms-guest.html

=======================================
--- /trunk/src/com/google/caja/lang/html/html4-attributes-defs.json Mon Oct 15 11:33:58 2012 +++ /trunk/src/com/google/caja/lang/html/html4-attributes-defs.json Wed May 1 10:22:42 2013
@@ -598,8 +598,9 @@
         "optional": false, "default": "text/javascript" },
{ "key": "STYLE::TYPE", "description": "content type of style language",
         "optional": false, "default": "text/css" },
- { "key": "INPUT::TYPE", "description": "what kind of widget is needed",
-        "values": 
"text,password,checkbox,radio,submit,reset,file,hidden,image,button",
+      { "key": "INPUT::TYPE", "description": "Type of form control",
+        "values": 
"hidden,text,search,tel,url,email,password,datetime,date,month,week,time,datetime-local,number,range,color,checkbox,radio,file,submit,image,reset,button",
+        "comment": "Values include HTML5 features",
         "default": "TEXT", "optional": true },
       { "key": "LI::TYPE", "description": "list item style",
         "optional": true },
=======================================
--- /trunk/src/com/google/caja/plugin/domado.js Tue Apr 30 11:03:00 2013
+++ /trunk/src/com/google/caja/plugin/domado.js Wed May  1 10:22:42 2013
@@ -5326,15 +5326,25 @@
           defaultValue: NP.filter(
             false, function (x) { return x == null ? null : String(x); },
             false, function (x) { return x == null ? '' : '' + x; }),
+          min: NP.rw,
+          max: NP.rw,
           readOnly: NP.rw,
           selectedIndex: NP.filterProp(identity, toInt),
           size: NP.rw,
-          type: NP.rw
+          step: NP.rw,
+          type: NP.rw,
+          valueAsNumber: NP.rw
         }
       });
       TameInputElement.prototype.select = nodeAmp(function(privates) {
         privates.feral.select();
       });
+      TameInputElement.prototype.stepDown = nodeAmp(function(privates) {
+        privates.feral.stepDown();
+      });
+      TameInputElement.prototype.stepUp = nodeAmp(function(privates) {
+        privates.feral.stepUp();
+      });

       defineElement({
         superclass: TameFormField,
=======================================
--- /trunk/tests/com/google/caja/plugin/browser-test-case.js Tue Apr 30 10:16:11 2013 +++ /trunk/tests/com/google/caja/plugin/browser-test-case.js Wed May 1 10:22:42 2013
@@ -638,7 +638,7 @@
   var jsunitFns = [
       'assert', 'assertContains', 'assertEquals', 'assertEvaluatesToFalse',
       'assertEvaluatesToTrue', 'assertFalse', 'assertHTMLEquals',
-      'assertHashEquals', 'assertNotEquals', 'assertNotNull',
+      'assertHashEquals', 'assertNaN', 'assertNotEquals', 'assertNotNull',
       'assertNotUndefined', 'assertNull', 'assertRoughlyEquals',
       'assertThrows', 'assertTrue', 'assertObjectEquals', 'assertUndefined',
       'assertThrowsMsg', 'error', 'fail', 'setUp', 'tearDown'];
=======================================
--- /trunk/tests/com/google/caja/plugin/es53-test-domado-forms-guest.html Tue Apr 30 11:03:00 2013 +++ /trunk/tests/com/google/caja/plugin/es53-test-domado-forms-guest.html Wed May 1 10:22:42 2013
@@ -220,3 +220,33 @@
     pass('testDynamicForm');
   });
 </script>
+
+<form class="testcontainer" id="testFancyInputs">testFancyInputs
+  <!-- HTML5 input types and related interface -->
+  <input type="text" id="testFancyInputs-plain" value="7">
+  <input type="number" id="testFancyInputs-num" value="7">
+</form>
+<script type="text/javascript">
+  // TODO(kpreid): Marked ES5 only because the cajoler is not allowing
+ // type=number through despite it being in the schema; I don't know why yet. + jsunitRegisterIf(inES5Mode, 'testFancyInputs', function testFancyInputs() {
+    // TODO(kpreid): test other HTML5 input types.
+
+    // basics/comparison
+    assertEquals('text', $('testFancyInputs-plain').type);
+    assertNaN($('testFancyInputs-plain').valueAsNumber);
+
+    assertEquals('number', $('testFancyInputs-num').getAttribute('type'));
+    if ($('testFancyInputs-num').type === 'number') {  // browser support
+      assertEquals('number', $('testFancyInputs-num').type);
+      assertEquals(7, $('testFancyInputs-num').valueAsNumber);
+
+      $('testFancyInputs-num').stepDown();
+      assertEquals(6, $('testFancyInputs-num').valueAsNumber);
+      $('testFancyInputs-num').stepUp();
+      assertEquals(7, $('testFancyInputs-num').valueAsNumber);
+    }
+
+    pass('testFancyInputs');
+  });
+</script>

--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to