Change to use Module

This commit is contained in:
Demis Bellot
2016-01-29 06:36:02 -05:00
parent c3dd962e94
commit 861d4f8846
2 changed files with 143 additions and 97 deletions
+44 -4
View File
@@ -20,10 +20,10 @@ function test_ssutils() {
var source = new EventSource("/event-stream?channels=home,work");
$(source).handleServerEvents({
handlers: {
onConnect: function(connect:SSUtilsSSEConnect) {},
onHeartbeat: function(msg:SSUtilsSSEHeartbeat, e:MessageEvent){},
onJoin: function(msg:SSUtilsSSEJoin) {},
onLeave: function(msg:SSUtilsSSELeave) {}
onConnect: function(connect:ssutils.SSEConnect) {},
onHeartbeat: function(msg:ssutils.SSEHeartbeat, e:MessageEvent){},
onJoin: function(msg:ssutils.SSEJoin) {},
onLeave: function(msg:ssutils.SSELeave) {}
},
receivers: {
tv: {
@@ -37,5 +37,45 @@ function test_ssutils() {
})
.on('customEvent', function (e, msg, msgEvent) { });
$.ss.handlers["changeChannel"]("home");
}
function test_jQuery_functions(){
$("document").setFieldError("name","message");
var map = $("form").serializeMap();
$("form").applyErrors({errorCode:"",message:"",stackTrace:"",errors:[]});
$("form").clearErrors();
$("form").bindForm({
overrideMessages: true,
messages: {"NotFound": "Not Found"},
errorFilter: function(errorMsg, errorCode, type){}
});
$("form").applyValues({
"Key": "Value"
});
$("form").bindHandlers({
"test": function() {}
});
}
function test_ssutils_Static(){
$.ss.handlers["key"] = () => 0;
$.ss.onSubmitDisable = "class";
$.ss.validation.messages["Code"] = "Message";
$.ss.clearAdjacentError();
var date:Date = $.ss.todate("2001-01-01");
var dateFmt:String = $.ss.todfmt("2001-01-01");
dateFmt = $.ss.dfmt(new Date(2001,1,1));
dateFmt = $.ss.dfmthm(new Date(2001,1,1));
dateFmt = $.ss.tfmt12(new Date(2001,1,1));
var parts:string[] = $.ss.splitOnFirst("A,B,C");
parts = $.ss.splitOnLast("A,B,C");
var selectedText = $.ss.getSelection();
var qs:{ [index: string]: string } = $.ss.queryString("http://google.com?a=b&c=d");
var relativePath = $.ss.createUrl("/path/to/{File}", {File:"file.js"});
var readableText = $.ss.humanize("TheVariableName");
$.ss.listenOn = "click onmousedown";
$.ss.eventReceivers = { "document": document };
$.ss.handlers["changeChannel"]("home");
}
+99 -93
View File
@@ -8,106 +8,112 @@
interface JQuery {
setFieldError: (name: string, msg: string) => void;
serializeMap: () => { [index: string]: any };
applyErrors: (status: ResponseStatus, opt?: SSUtilsApplyErrorsOptions) => JQuery;
applyErrors: (status: ssutils.ResponseStatus, opt?: ssutils.ApplyErrorsOptions) => JQuery;
clearErrors: () => JQuery;
bindForm: (opt?: SSUtilsApplyErrorsOptions) => JQuery;
bindForm: (opt?: ssutils.ApplyErrorsOptions) => JQuery;
applyValues: (values: { [index: string]: string }) => JQuery;
bindHandlers: (handlers: { [index: string]: Function }) => JQuery;
setActiveLinks: () => JQuery;
handleServerEvents: (opt?: SSUtilsHandleServerEventsOptions) => void;
}
interface SSUtilsValidation {
overrideMessages: boolean;
messages: { [index: string]: string };
errorFilter: (errorMsg: string, errorCode: string, type: string) => void;
}
interface SSUtilsValidationOptional {
overrideMessages?: boolean;
messages?: { [index: string]: string };
errorFilter?: (errorMsg: string, errorCode: string, type: string) => void;
}
interface SSUtilsApplyErrorsOptions extends SSUtilsValidationOptional {
}
interface SSUtilsBindFormOptions {
validation?: SSUtilsValidationOptional;
validate?: (form: HTMLFormElement) => boolean;
onSubmitDisable?: string;
complete?: (...args: any[]) => void;
error?: (...args: any[]) => void;
}
interface SSUtilsHandleServerEventsOptions {
handlers?: { [index: string]: Function };
validate?: (op?: string, target?: string, msg?: string, json?: string) => boolean;
heartbeatUrl?: string;
heartbeatIntervalMs?: number;
unRegisterUrl?: string;
receivers?: { [index: string]: any };
success?: (selector: string, msg: string, e: any) => void;
}
interface ResponseStatus {
errorCode: string;
message: string;
stackTrace: string;
errors: ResponseError[];
}
interface ResponseError {
errorCode: string;
fieldName: string;
message: string;
}
interface SSUtilsStatic {
handlers: { [index: string]: Function };
onSubmitDisable: string;
validation: SSUtilsValidation;
clearAdjacentError: () => void;
todate: (s: string) => Date;
todfmt: (s: string) => string;
dfmt: (d: Date) => string;
dfmthm: (d: Date) => string;
tfmt12: (d: Date) => string;
splitOnFirst: (s: string) => string[];
splitOnLast: (s: string) => string[];
getSelection: () => string;
queryString: (url: string) => { [index: string]: string };
createUrl: (route: string, args?: any) => string;
humanize: (s: string) => string;
listenOn: string;
eventReceivers: any;
reconnectServerEvents: (opt: SSUtilsReconnectServerEventsOptions) => any;
}
interface SSUtilsReconnectServerEventsOptions {
url?: string;
onerror?: (...args: any[]) => void;
onmessage?: (...args: any[]) => void;
errorArgs: any[];
handleServerEvents: (opt?: ssutils.HandleServerEventsOptions) => void;
}
interface JQueryStatic {
ss: SSUtilsStatic;
ss: ssutils.Static;
}
interface SSUtilsSSECommand {
userId: string;
displayName: string;
channels: string;
profileUrl: string;
}
interface SSUtilsSSEHeartbeat extends SSUtilsSSECommand {}
interface SSUtilsSSEJoin extends SSUtilsSSECommand {}
interface SSUtilsSSELeave extends SSUtilsSSECommand {}
interface SSUtilsSSEConnect extends SSUtilsSSECommand {
id: string;
unRegisterUrl: string;
heartbeatUrl: string;
heartbeatIntervalMs: number;
idleTimeoutMs: number;
declare module ssutils
{
interface Static {
handlers: { [index: string]: Function };
onSubmitDisable: string;
validation: Validation;
clearAdjacentError: () => void;
todate: (s: string) => Date;
todfmt: (s: string) => string;
dfmt: (d: Date) => string;
dfmthm: (d: Date) => string;
tfmt12: (d: Date) => string;
splitOnFirst: (s: string) => string[];
splitOnLast: (s: string) => string[];
getSelection: () => string;
queryString: (url: string) => { [index: string]: string };
createUrl: (route: string, args?: any) => string;
humanize: (s: string) => string;
listenOn: string;
eventReceivers: any;
reconnectServerEvents: (opt: ReconnectServerEventsOptions) => any;
}
interface Validation {
overrideMessages: boolean;
messages: { [index: string]: string };
errorFilter: (errorMsg: string, errorCode: string, type: string) => void;
}
interface ValidationOptional {
overrideMessages?: boolean;
messages?: { [index: string]: string };
errorFilter?: (errorMsg: string, errorCode: string, type: string) => void;
}
interface ApplyErrorsOptions extends ValidationOptional {
}
interface BindFormOptions {
validation?: ValidationOptional;
validate?: (form: HTMLFormElement) => boolean;
onSubmitDisable?: string;
complete?: (...args: any[]) => void;
error?: (...args: any[]) => void;
}
interface HandleServerEventsOptions {
handlers?: { [index: string]: Function };
validate?: (op?: string, target?: string, msg?: string, json?: string) => boolean;
heartbeatUrl?: string;
heartbeatIntervalMs?: number;
unRegisterUrl?: string;
receivers?: { [index: string]: any };
success?: (selector: string, msg: string, e: any) => void;
}
interface ResponseStatus {
errorCode: string;
message: string;
stackTrace: string;
errors: ResponseError[];
}
interface ResponseError {
errorCode: string;
fieldName: string;
message: string;
}
interface SSECommand {
userId: string;
displayName: string;
channels: string;
profileUrl: string;
}
interface SSEHeartbeat extends SSECommand { }
interface SSEJoin extends SSECommand { }
interface SSELeave extends SSECommand { }
interface SSEConnect extends SSECommand {
id: string;
unRegisterUrl: string;
heartbeatUrl: string;
heartbeatIntervalMs: number;
idleTimeoutMs: number;
}
interface ReconnectServerEventsOptions {
url?: string;
onerror?: (...args: any[]) => void;
onmessage?: (...args: any[]) => void;
errorArgs: any[];
}
}