diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-10-17 16:43:51 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-10-17 16:43:51 -0700 |
commit | 884d364476565b1f94b1bdf3e85f92d7d8081f6c (patch) | |
tree | 312b74027156559f0f1504e156709e57255d05a4 | |
parent | 36a5a1065f782355f7c95f7ae2cee2ee817afcc4 (diff) |
modifying form to support more browsers w/o input[type=time]
-rw-r--r-- | management/editor/editor.go | 38 | ||||
-rw-r--r-- | management/manager/manager.go | 27 | ||||
-rw-r--r-- | system/admin/static/common/js/util.js | 32 |
3 files changed, 73 insertions, 24 deletions
diff --git a/management/editor/editor.go b/management/editor/editor.go index c7500b6..8f8f4a2 100644 --- a/management/editor/editor.go +++ b/management/editor/editor.go @@ -45,13 +45,39 @@ func Form(post Editable, fields ...Field) ([]byte, error) { editor.ViewBuf.Write([]byte(`<tr class="col s4 default-fields"><td>`)) publishTime := ` -<div class="input-field col s12"> - <label class="active" for="Publish-Date">Publish Date</label> - <input value="" class="date __ponzu" label="Publish Date" type="date" name="date" /> +<div class="input-field col s3"> + <label class="active">MM</label> + <select class="month __ponzu"> + <option value="0">Jan - 01</option> + <option value="1">Feb - 02</option> + <option value="2">Mar - 03</option> + <option value="3">Apr - 04</option> + <option value="4">May - 05</option> + <option value="5">Jun - 06</option> + <option value="6">Jul - 07</option> + <option value="7">Aug - 08</option> + <option value="8">Sep - 09</option> + <option value="9">Oct - 10</option> + <option value="10">Nov - 11</option> + <option value="11">Dec - 12</option> + </select> </div> -<div class="input-field col s12"> - <label class="active" for="Publish-Time">Publish Time</label> - <input value="" class="time __ponzu" label="Publish Time" type="time" name="time" /> +<div class="input-field col s2"> + <label class="active">DD</label> + <input value="" class="day __ponzu" type="text" placeholder="DD" /> +</div> +<div class="input-field col s2"> + <label class="active">YYYY</label> + <input value="" class="year __ponzu" type="text" placeholder="YYYY" /> +</div> +<div class col s1>@</div> +<div class="input-field col s2"> + <label class="active">HH</label> + <input value="" class="hour __ponzu" type="text" placeholder="HH" /> +</div> +<div class="input-field col s2"> + <label class="active">MM</label> + <input value="" class="minute __ponzu" type="text" placeholder="MM" /> </div> ` diff --git a/management/manager/manager.go b/management/manager/manager.go index 9791749..62d7935 100644 --- a/management/manager/manager.go +++ b/management/manager/manager.go @@ -25,22 +25,37 @@ const managerHTML = ` e.target.value = replaceBadChars(val); }); - var setDefaultTimeAndDate = function($pt, $pd, $ts, $up, unix) { + var setDefaultTimeAndDate = function(dt, $ts, $up, unix) { var time = getPartialTime(unix), date = getPartialDate(unix); - $pt.val(time); - $pd.val(date); + dt.hour.val(time.hh); + dt.minute.val(time.mm); + dt.year.val(date.yyyy); + dt.month.val(date.mm); + dt.day.val(date.dd); $ts.val(unix); $up.val(unix); } // set time time and date inputs using the hidden timestamp input. // if it is empty, set it to now and use that value for time and date - var publish_time = $('input.__ponzu.time'), - publish_date = $('input.__ponzu.date'), + var publish_time_hh = $('input.__ponzu.hour'), + publish_time_mm = $('input.__ponzu.minute'), + publish_date_yyyy = $('input.__ponzu.year'), + publish_date_mm = $('input.__ponzu.month'), + publish_date_dd = $('input.__ponzu.day'), timestamp = $('input.__ponzu.timestamp'), updated = $('input.__ponzu.updated'), + getFields = function() { + return { + hour: publish_time_hh, + minute: publish_time_mm, + year: publish_time_yyyy, + month: publish_time_mm, + day: publish_time_dd + } + }, time; if (timestamp.val() !== "") { @@ -49,7 +64,7 @@ const managerHTML = ` time = (new Date()).getTime(); } - setDefaultTimeAndDate(publish_time, publish_date, timestamp, updated, time); + setDefaultTimeAndDate(getFields(), timestamp, updated, time); }); </script> diff --git a/system/admin/static/common/js/util.js b/system/admin/static/common/js/util.js index 40c9828..cf47af4 100644 --- a/system/admin/static/common/js/util.js +++ b/system/admin/static/common/js/util.js @@ -23,34 +23,42 @@ function replaceBadChars(text) { } -// Returns a local partial time based on unix timestamp (i.e. HH:MM:SS) +// Returns a local partial time object based on unix timestamp function getPartialTime(unix) { var date = new Date(unix); - var parts = []; - parts.push(date.getHours()); - parts.push(date.getMinutes()); - parts.push(date.getSeconds()); + var t = {}; + var hours = date.getHours(); + if (hours < 10) { + hours = "0" + String(hours); + } + t.hh = hours; + + var minutes = date.getMinutes(); + if (minutes < 10) { + minutes = "0" + String(minutes); + } + t.mm = minutes; - return parts.join(":"); + return t; } -// Returns a local partial date based on unix timestamp (YYYY-MM-DD) +// Returns a local partial date object based on unix timestamp function getPartialDate(unix) { var date = new Date(unix); - var parts = []; - parts.push(date.getFullYear()); + var d = {}; + d.yyyy = date.getFullYear(); var month = date.getMonth()+1; if (month < 10) { month = "0" + String(month); } - parts.push(month); + d.mm = month; var day = date.getDate(); if (day < 10) { day = "0" + String(day); } - parts.push(day); + d.dd = day; - return parts.join("-"); + return d; }
\ No newline at end of file |