(function(DOM, undefined) {
    "use strict";

    var AMPM = DOM.find("html").get("lang") === "en-US",
        TIME_KEY = "time-input",
        AMPM_KEY = "time-median",
        COMPONENT_CLASS = "better-timeinput",
        timeparts = function(str) {
            str = str.split(":");

            if (str.length === 2) {
                str[0] = parseFloat(str[0]);
                str[1] = parseFloat(str[1]);
            } else {
                str = [];
            }

            return str;
        },
        zeropad = function(value) { return ("00" + value).slice(-2) };

    DOM.extend("input[type=time]", "orientation" in window ? function() { this.addClass(COMPONENT_CLASS) } : {
        // polyfill timeinput for desktop browsers
        constructor: function() {
            var timeinput = DOM.create("input[type=hidden]", {name: this.get("name"), value: this.get() }),
                ampmspan = AMPM ? DOM.create("span." + COMPONENT_CLASS + "-meridian>(select>option>{AM}^option>{PM})+span>{AM}") : DOM.mock(),
                ampmselect = ampmspan.child(0);

            this
                // drop native implementation and clear name attribute
                .set({type: "text", maxlength: 5, name: null})
                .addClass(COMPONENT_CLASS)
                .after(ampmspan, timeinput)
                .data(TIME_KEY, timeinput)
                .data(AMPM_KEY, ampmselect)
                .on("keydown", ["which", "shiftKey"], this.handleTimeInputKeydown)
                .on("change", this.handleTimeInputChange)
                .handleTimeInputChange();

            ampmselect.on("change", this, "handleTimeMeridianChange");
            // update value correctly on form reset
            this.parent("form").on("reset", this, function() {
                setTimeout((function(el) {
                    return function() {
                        timeinput.set(el.get());
                        el.handleTimeInputChange();
                    };
                }(this)), 0);
            });

            if (this.matches(":focus")) timeinput.fire("focus");
        },
        handleTimeInputKeydown: function(which, shiftKey) {
            return which === 186 && shiftKey || which < 58;
        },
        handleTimeInputChange: function() {
            var ampmselect = this.data(AMPM_KEY),
                timeinput = this.data(TIME_KEY),
                parts = timeparts(this.get()),
                hours = parts[0],
                minutes = parts[1];

            if (!parts.length) return timeinput.set("");

            if (hours < (ampmselect.length ? 13 : 24) && minutes < 60) {
                timeinput.set(zeropad(ampmselect.get() === "PM" ? hours + 12 : hours) + ":" + zeropad(minutes));
            } else {
                // restore previous valid
                parts = timeparts(timeinput.get());
                hours = parts[0];
                minutes = parts[1];
                // select appropriate AM/PM
                ampmselect.child((hours -= 12) > 0 ? 1 : Math.min(hours += 12, 0)).set("selected", true);
                // update displayed AM/PM
                ampmselect.next().set(ampmselect.get());
            }

            this.set(hours + ":" + zeropad(minutes));
        },
        handleTimeMeridianChange: function(ampmselect) {
            // update displayed AM/PM
            ampmselect.next().set(ampmselect.get());
            // adjust time in hidden input
            this.data(TIME_KEY).set(function(value) {
                var parts = timeparts(value),
                    hours = parts[0],
                    minutes = parts[1];

                return zeropad(ampmselect.get() === "PM" ? hours + 12 : hours - 12) + ":" + zeropad(minutes);
            });
        }
    });
}(window.DOM));

@@ -834,16 +834,17 @@
 den%5D%22, %7B
+ 
 name: th
@@ -861,27 +861,8 @@
 me%22)
-, value: this.get()
  %7D),
@@ -1523,51 +1523,10 @@
 nge)
-%0A                .handleTimeInputChange()
 ;%0A
+
 %0A   
@@ -1699,106 +1699,106 @@
 is, 
-function() %7B%0A                setTimeout((function(el) %7B%0A                    return function() %7B%0A  
+%22handleFormReset%22);%0A            // dunno why defaultValue syncs with value for input%5Btype=hidden%5D%0A
     
@@ -1801,34 +1801,24 @@
             
-          
 timeinput.se
@@ -1819,18 +1819,53 @@
 put.set(
-el
+this.get()).data(%22defaultValue%22, this
 .get());
@@ -1857,32 +1857,33 @@
 %22, this.get());%0A
+%0A
                 
@@ -1870,33 +1870,50 @@
 );%0A%0A            
- 
+if (this.get()) %7B%0A
            el.ha
@@ -1907,18 +1907,25 @@
         
-el
+     this
 .handleT
@@ -1962,42 +1962,168 @@
     
-    %7D;%0A                %7D(this)), 0
+// update defaultValue with formatted time%0A                this.set(%22defaultValue%22, this.get());%0A                ampmselect.set(%22defaultValue%22, ampmselect.get()
 );%0A 
@@ -2134,18 +2134,16 @@
        %7D
-);
 %0A%0A      
@@ -3858,16 +3858,245 @@
     %7D);%0A
+        %7D,%0A        handleFormReset: function() %7B%0A            this.data(TIME_KEY).set(function() %7B return this.data(%22defaultValue%22) %7D);%0A            this.data(AMPM_KEY).each(function(el) %7B el.next().set(el.get(%22defaultValue%22)) %7D);%0A
         

handle form reset without setTimeout