Skip to content

Commit

Permalink
corrected a few bugs and updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
frankabbruzzese committed May 17, 2016
1 parent 8bffc3a commit bba1d35
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 50 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,19 @@ fallback module is loaded and registered by calling the mvcct.enhancer method `a
then Html5 fallback is automatically turned on. and all Html5 inputs that are not supported are transformed
into text inputs and their content is converted into the current "locale" (this means, for instance, that dates are transformed
from the date input ISO format into a format like mm/dd/yy).
Available, also a more complete fallback based on bootstrap widgets: [bootstrap-html5-fallback](https://github.com/MvcControlsToolkit/bootstrap-html5-fallback).
When `bootstrap.html5.fallback.js` is loaded after `mvcct.enhancer.input.basic.js` the `addBasicInput(Globalize)`
is updated to load also all bootstrap widgets.

As a default the following [Globalize](https://github.com/jquery/globalize) "locale" formats are used:

```
{
dateFormat: { "date": "short" },
timeFormat: { "skeleton": "Hms" },
timeFormat1: { "skeleton": "Hm" },
datetimeFormat: { "skeleton": "yMdHms" },
datetimeFormat1": { "skeleton": "yMdHm" },
timeFormat1: { "skeleton": "Hms" },
datetimeFormat: { "datetime": "short" },
datetimeFormat1": { "datetime": "short" },
monthFormat: { "date": "short" },
weekFormat: { "date": "short" }
};
Expand Down Expand Up @@ -310,14 +313,17 @@ when reading/setting input fields. In order to simplify input field access, when
the Htm5 inputs support-detection and fallback module adds two helper methods to the enhancer object, namely:

```
.format(type, value)
.parse(type, stringValue)
.format(type, value, [invariant])
.parse(type, stringValue, [invariant])
```
Both methods takes the type of the original Html5 input as first argument("date", "time", etc.). `format`
takes a javascript object (date or number depending on the input time) and transforms it in a properly formatted
string, while `parse` performs the inverse transformation. I case of fallback the formats specified in
`editFormats`(or their defaults) are used.
`editFormats`(or their defaults) are used. If the third optional argument is true parsing/formatting are
done using the invariant culture (the one used by native Html5 inputs), otherwise the right culture is auto-detected.
Forcing the invariant culture may be useful for some custom processing of the original input field (for instance
processing min/max or step attributes to set some fallback widget options).

## Adding widgets to Htm5 input fallback
One may also add easily widgets(date, datetime, time pickers, siders, etc) to the basic input fallback,
Expand Down Expand Up @@ -395,7 +401,8 @@ dependency(name,//string
action: // invoked function function(targetNode, sourceNode) => void);
)
```
`name` identifies the type of dependency. When the value of an input is changed programmatically, dependency propagation
`name` identifies the type of dependency. If you want your dependencies interact globally with all others, please set **name="main"**.
When the value of an input is changed programmatically, dependency propagation
may be started by triggering the `"_enhancer.dependency."+name` event.

**IMPORTANT!**, since mvcct.enhancer doesnt depend on jQuery all above events are not defined with jQuery.
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mvcct-enhancer",
"version": "1.0.0-rc2",
"version": "1.0.0-rc3",
"homepage": "https://github.com/MvcControlsToolkit/mvcct-enhancer",
"description": "a javascript package to handle standard html enhancements",
"main": [
Expand Down
32 changes: 25 additions & 7 deletions enhancer-modules/mvcct.enhancer.input.basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
var defaults = {
"dateFormat": { "date": "short" },
"timeFormat": { "skeleton": "Hms" },
"timeFormat1": { "skeleton": "Hm" },
"datetimeFormat": { "skeleton": "yMdHms" },
"datetimeFormat1": { "skeleton": "yMdHm" },
"timeFormat1": { "skeleton": "Hms" },
"datetimeFormat": { "datetime": "short" },
"datetimeFormat1": { "datetime": "short" },
"monthFormat": { "date": "short" },
"weekFormat": { "date": "short" }
};
Expand Down Expand Up @@ -214,6 +214,15 @@
"date": support["date"]>2 ? neutralDateParser : localDateParser,
"month": support["month"]>2 ? neutralMonthParser : localMonthParser,
"week": support["week"]>2 ? getDateOfISOWeek : localWeekParser
};
var dictI = {
"range": parseFloat,
"number": parseFloat,
"time": gtimeParser,
"datetime": gDatetimeParser,
"date": neutralDateParser,
"month": neutralMonthParser,
"week": getDateOfISOWeek
};
var fdict = {
"range": support["range"]>2 ? function(x){return x+"";} : numberFormatter,
Expand All @@ -224,15 +233,24 @@
"month": support["month"]>2 ? neutralMonthFormatter : monthFormatter,
"week": support["week"]>2 ? getIsoWeek : weekFormatter
};
Enhancer["format"]=function(type, val){
var fdictI = {
"range": function(x){return x+"";},
"number": function(x){return x+"";},
"time": neutralTimeFormatter,
"datetime": neutralDateTimeFormatter,
"date": neutralDateFormatter,
"month": neutralMonthFormatter,
"week": getIsoWeek
};
Enhancer["format"]=function(type, val, invariant){
if(!val && val !== 0 ) return "";
var formatter = fdict[type];
var formatter = (invariant ? fdictI : fdict)[type];
if(formatter) return formatter(val);
else return val;
}
Enhancer["parse"]=function(type, val){
Enhancer["parse"]=function(type, val, invariant){
if(!val ) return null;
var parser = dict[type];
var parser = (invariant ? dictI : dict)[type];
if(parser) return parser(val);
else return parser;
}
Expand Down
19 changes: 10 additions & 9 deletions enhancer-modules/mvcct.enhancer.input.basic.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 29 additions & 14 deletions mvcct.enhancer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
}

export interface EnhancementProcessors{
number?: (node: HTMLHtmlElement) => void;
range?: (node: HTMLHtmlElement) => void;
date?: (node: HTMLHtmlElement) => void;
month?: (node: HTMLHtmlElement) => void;
week?: (node: HTMLHtmlElement) => void;
time?: (node: HTMLHtmlElement) => void;
datetime?: (node: HTMLHtmlElement) => void;
email?: (node: HTMLHtmlElement) => void;
search?: (node: HTMLHtmlElement) => void;
tel?: (node: HTMLHtmlElement) => void;
url?: (node: HTMLHtmlElement) => void;
color?: (node: HTMLHtmlElement) => void;
number?: (node: HTMLElement, originalNode: HTMLElement) => void;
range?: (node: HTMLElement, originalNode: HTMLElement) => void;
date?: (node: HTMLElement, originalNode: HTMLElement) => void;
month?: (node: HTMLElement, originalNode: HTMLElement) => void;
week?: (node: HTMLElement, originalNode: HTMLElement) => void;
time?: (node: HTMLElement, originalNode: HTMLElement) => void;
datetime?: (node: HTMLElement, originalNode: HTMLElement) => void;
email?: (node: HTMLElement, originalNode: HTMLElement) => void;
search?: (node: HTMLElement, originalNode: HTMLElement) => void;
tel?: (node: HTMLElement, originalNode: HTMLElement) => void;
url?: (node: HTMLElement, originalNode: HTMLElement) => void;
color?: (node: HTMLElement, originalNode: HTMLElement) => void;
}

export interface Html5FallbackHandler{
Expand Down Expand Up @@ -75,6 +75,20 @@
url: number;
color: number;
}
export interface Html5InputFallbackWidgetsOptions{
number?: any;
range?: any;
date?: any;
month?: any;
week?: any;
time?: any;
datetime?: any;
email?: any;
search?: any;
tel?: any;
url?: any;
color?: any;
}
export interface Formats{
dateFormat?: string;
timeFormat?: string;
Expand All @@ -86,6 +100,7 @@
}
export interface Options {
browserSupport?: BrowserSupportOptions;
html5FallbackWidgets?: Html5InputFallbackWidgetsOptions;
editFormats?: Formats;
runReady?: boolean;
[propName: string]: any;
Expand Down Expand Up @@ -113,8 +128,8 @@
export function removeDependency(handle: any): void;
export function getSupport(): Html5Infos;
export function addBasicInput(Globalize: any);
export function format(type: string, value: any): string;
export function parse(type: string, value: string): any;
export function format(type: string, value: any, invariant?: boolean): string;
export function parse(type: string, value: string, invariant?: boolean): any;
export function Globalize(): any;
}
}
Expand Down
Loading

0 comments on commit bba1d35

Please sign in to comment.