Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "ss-utils", | ||
"title": "ServiceStack JavaScript Utils", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "ServiceStack's JavaScript library providing a number of convenience utilities in developing javascript web apps. Integrates with ServiceStack's Server features including Error Handling, Validation and Server Events", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/ServiceStack/ss-utils", |
;(function (root, f) { | ||
if (typeof define === "function" && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define(["jquery"], f); | ||
@@ -90,3 +89,2 @@ } else if (typeof exports === "object") { | ||
}; | ||
function splitCase(t) { | ||
@@ -100,3 +98,2 @@ return typeof t != 'string' ? t : t.replace(/([A-Z]|[0-9]+)/g, ' $1').replace(/_/g, ' '); | ||
} | ||
function sanitize(status) { | ||
@@ -129,2 +126,9 @@ if (status["errors"]) | ||
}; | ||
$.ss.postJSON = function (url, data, success, error) { | ||
return $.ajax({ | ||
type: "POST", url: url, dataType: "json", contentType: "application/json", | ||
data: typeof data == "string" ? data : JSON.stringify(data), | ||
success: success, error: error | ||
}); | ||
}; | ||
@@ -139,3 +143,2 @@ $.fn.setFieldError = function (name, msg) { | ||
}; | ||
$.fn.serializeMap = function () { | ||
@@ -148,3 +151,2 @@ var o = {}; | ||
}; | ||
$.fn.applyErrors = function (status, opt) { | ||
@@ -209,3 +211,2 @@ this.clearErrors(); | ||
}; | ||
$.fn.clearErrors = function () { | ||
@@ -224,3 +225,2 @@ this.removeClass("has-errors"); | ||
}; | ||
$.fn.bindForm = function (orig) { | ||
@@ -235,3 +235,2 @@ return this.each(function () { | ||
}; | ||
$.fn.ajaxSubmit = function (orig) { | ||
@@ -300,3 +299,2 @@ orig = orig || {}; | ||
}; | ||
$.fn.applyValues = function (map) { | ||
@@ -368,6 +366,41 @@ return this.each(function () { | ||
$.ss.eventReceivers = {}; | ||
$.ss.eventChannels = []; | ||
$.ss.eventSourceUrl = null; | ||
$.ss.updateSubscriberUrl = null; | ||
$.ss.updateChannels = function(channels) { | ||
$.ss.eventChannels = channels; | ||
if (!$.ss.eventSource) return; | ||
var url = $.ss.eventSource.url; | ||
$.ss.eventSourceUrl = url.substring(0, Math.min(url.indexOf('?'), url.length)) + "?channels=" + channels.join(','); | ||
}; | ||
$.ss.subscribeToChannels = function (channels, cb, cbError) { | ||
return $.ss.updateSubscriber({ SubscribeChannels: channels.join(',') }, cb, cbError); | ||
}; | ||
$.ss.unsubscribeFromChannels = function (channels, cb, cbError) { | ||
return $.ss.updateSubscriber({ UnsubscribeChannels: channels.join(',') }, cb, cbError); | ||
}; | ||
$.ss.updateSubscriber = function (data, cb, cbError) { | ||
if (!$.ss.updateSubscriberUrl) | ||
throw new Error("updateSubscriberUrl was not populated"); | ||
return $.ajax({ | ||
type: "POST", | ||
url: $.ss.updateSubscriberUrl, | ||
data: data, | ||
dataType: "json", | ||
success: function(r) { | ||
$.ss.updateChannels((r.channels || '').split(',')); | ||
if (cb != null) | ||
cb(r); | ||
}, | ||
error: function(e) { | ||
$.ss.reconnectServerEvents({ errorArgs: arguments }); | ||
if (cbError != null) | ||
cbError(e); | ||
} | ||
}); | ||
}; | ||
$.ss.reconnectServerEvents = function (opt) { | ||
opt = opt || {}; | ||
var hold = $.ss.eventSource; | ||
var es = new EventSource(opt.url || hold.url); | ||
var es = new EventSource(opt.url || $.ss.eventSourceUrl || hold.url); | ||
es.onerror = opt.onerror || hold.onerror; | ||
@@ -453,2 +486,4 @@ es.onmessage = opt.onmessage || hold.onmessage; | ||
} | ||
$.ss.updateSubscriberUrl = opt.updateSubscriberUrl; | ||
$.ss.updateChannels((opt.channels || "").split(',')); | ||
} | ||
@@ -455,0 +490,0 @@ var fn = $.ss.handlers[cmd]; |
26858
5
625