summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/vendor/view
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/platforms/ios/www/js/vendor/view')
-rw-r--r--StoneIsland/platforms/ios/www/js/vendor/view/formview.js146
-rw-r--r--StoneIsland/platforms/ios/www/js/vendor/view/router.js8
-rw-r--r--StoneIsland/platforms/ios/www/js/vendor/view/scrollable.js20
-rw-r--r--StoneIsland/platforms/ios/www/js/vendor/view/serializable.js129
-rw-r--r--StoneIsland/platforms/ios/www/js/vendor/view/view.js11
5 files changed, 162 insertions, 152 deletions
diff --git a/StoneIsland/platforms/ios/www/js/vendor/view/formview.js b/StoneIsland/platforms/ios/www/js/vendor/view/formview.js
deleted file mode 100644
index 8cd222e3..00000000
--- a/StoneIsland/platforms/ios/www/js/vendor/view/formview.js
+++ /dev/null
@@ -1,146 +0,0 @@
-var FormView = View.extend({
-
- method: "post",
- useMinotaur: false,
-
- events: {
- "submit form": "save"
- },
-
- initialize: function(opt){
- if (opt && opt.parent) {
- this.parent = opt.parent
- }
- this.$form = this.$("form")
- this.$errors = this.$(".errors")
- this.$errorList = this.$(".errorList")
- },
-
- reset: function(){
- this.$("input,textarea").not("[type='submit']").not("[type='hidden']").val("")
- },
-
- showErrors: function(errors){
- if (errors && errors.length) {
- this.$errorList.empty();
- for (var i in errors) {
- this.$errorList.append('<div>' + errors[i] + '</div>');
- }
- this.$errors.css("opacity", 1.0);
- setTimeout(function(){
- this.$errors.show().css("opacity", 1.0);
- }.bind(this), 200)
- }
- },
-
- serialize: function(){
- var fd = new FormData(), hasCSRF = false
-
- this.$("input[name], select[name], textarea[name]").each( function(){
- if (this.type == "file") {
- if (this.files.length > 0) {
- fd.append(this.name, this.files[0]);
- }
- }
-// else if (this.type == "password") {
-// if (this.value.length > 0) {
-// fd.append(this.name, SHA1.hex('bucky$' + this.value + '$bucky'))
-// }
-// }
- else {
- fd.append(this.name, this.value);
- hasCSRF = hasCSRF || this.name == "_csrf"
- }
- });
-
-// if (! hasCSRF) {
-// fd.append("_csrf", $("[name=_csrf]").attr("value"))
-// }
-//
- return fd
- },
-
- save: function(e, successCallback, errorCallback){
- e && e.preventDefault()
-
- this.$errors.hide().css("opacity", 0.0);
-
- if (this.validate) {
- var errors = this.validate()
- if (errors && errors.length) {
- if (errorCallback) {
- errorCallback(errors)
- }
- else {
- this.showErrors(errors)
- }
- return
- }
- }
-
- var action = typeof this.action == "function" ? this.action() : this.action
- if (! action) return
-
- var request = $.ajax({
- url: action,
- type: this.method,
- data: this.serialize(),
-// headers: { "csrf-token": $("[name=_csrf]").attr("value") },
- dataType: "json",
- processData: false,
- contentType: false,
- success: function(response){
-
- if (response.error) {
- var errors = []
- for (var key in response.error.errors) {
- errors.push(response.error.errors[key].message);
- }
- if (errorCallback) {
- errorCallback(errors)
- }
- else {
- this.showErrors(errors)
- }
- return
- }
- else {
- if (successCallback) {
- successCallback(response)
- }
- if (this.success) {
- this.success(response)
- }
- }
-
-
- }.bind(this),
- error: function(response){
- }.bind(this),
- complete: function(response){
- if (this.useMinotaur) {
- Minotaur.hide()
- }
- }.bind(this),
- })
-
- if (this.useMinotaur) {
- Minotaur.show()
- }
-
- },
-
-})
-
-/*
-
-var ModalFormView = ModalView.extend(FormView.prototype).extend({
-
- load: function(){
- this.reset()
- this.show()
- }
-
-})
-
-*/ \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/vendor/view/router.js b/StoneIsland/platforms/ios/www/js/vendor/view/router.js
index d766880f..a8ec331f 100644
--- a/StoneIsland/platforms/ios/www/js/vendor/view/router.js
+++ b/StoneIsland/platforms/ios/www/js/vendor/view/router.js
@@ -14,8 +14,10 @@ var Router = View.extend({
},
parseRoute: function(pathname){
-
- if (pathname[0] !== "/" && pathname[0] !== "#") { pathname = "/" + pathname }
+
+ pathname = pathname.replace(/^#/, "")
+
+ if (pathname[0] !== "/") { pathname = "/" + pathname }
var routes = this.routes,
path = pathname.split("/");
@@ -25,7 +27,7 @@ var Router = View.extend({
path[i] = null
}
}
-
+
if (pathname in routes) {
this[this.routes[pathname]]()
return
diff --git a/StoneIsland/platforms/ios/www/js/vendor/view/scrollable.js b/StoneIsland/platforms/ios/www/js/vendor/view/scrollable.js
new file mode 100644
index 00000000..7cd96f89
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/vendor/view/scrollable.js
@@ -0,0 +1,20 @@
+var ScrollableView = View.extend({
+
+ events: {
+ "load img": "deferScrollToTop",
+ },
+
+ deferScrollToTop: function(){
+ setTimeout(this.scrollToTop.bind(this), 0)
+ },
+
+ refreshScroller: function(){
+ this.scroller.refresh()
+ },
+
+ scrollToTop: function(){
+ this.scroller.refresh()
+ app.collection.scroller.scrollTo(0, 0)
+ },
+
+}) \ No newline at end of file
diff --git a/StoneIsland/platforms/ios/www/js/vendor/view/serializable.js b/StoneIsland/platforms/ios/www/js/vendor/view/serializable.js
new file mode 100644
index 00000000..e9459229
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/vendor/view/serializable.js
@@ -0,0 +1,129 @@
+var SerializableView = View.extend({
+
+ events: {
+ "change select": "update_select",
+ "focus input": "focus_input",
+ },
+
+ preload: function(data){
+ if (! data && sdk.env == "production") { return }
+ data = data || this.test_data
+ if (! data) { return }
+
+ Object.keys(data).forEach(function(key){
+ var value = data[key]
+ var $el = this.$("[name=" + key + "]")
+
+ if ($el.attr("type") == "checkbox") {
+ $el.prop("checked", value)
+ }
+ else if ($el.prop("tagName") == "SELECT") {
+ $el.val( value )
+ this.update_select({ currentTarget: $el })
+ }
+ else {
+ $el.val( value )
+ }
+ }.bind(this))
+ },
+
+ serialize: function(){
+ var fields = {}
+ this.$("input[name], select[name], textarea[name]").each( function(){
+ if (this.type == "checkbox") {
+ if ($(this).prop("checked")) {
+ fields[this.name] = this.value
+ }
+ }
+ else {
+ fields[this.name] = this.value
+ }
+ })
+ return fields
+ },
+
+ deserialize: function(data){
+ this.$("input[name], textarea[name]").val("")
+ Object.keys(data).forEach(function(k){
+ this.$("[" + k + "]").val(data[k])
+ })
+ },
+
+ focus_input: function(e){
+ $(e.currentTarget).removeClass("error_hilite")
+ },
+
+ update_select: function(e){
+ var $target = $(e.currentTarget), value = $target.val()
+ var label = $($("select")[0]).find("option").filter(function(){ return this.value === value }).html()
+
+ $target.parent().addClass("picked")
+ $target.parent().find("span").html(label)
+ },
+
+ validate: function(errors){
+ var data = this.serialize()
+ var errors = []
+ var presence_msgs = this.validate_presence
+ Object.keys(presence_msgs).forEach(function(k){
+ if (! data[k]) errors.push( [ k, presence_msgs[k] ] )
+ })
+ this.validate_fields && this.validate_fields(data, errors)
+ this.cc && this.cc.validate(errors)
+ this.address && this.address.validate(errors)
+ return { errors: errors, data: data }
+ },
+
+ show_errors: function(errors){
+ var msgs = []
+ errors.forEach(function(e, i){
+ if (i > 0) { return }
+ this.$("[name=" + e[0] + "]").addClass('error_hilite')
+ msgs.push(e[1])
+ }.bind(this))
+ this.$msg.html(msgs.join("<br>"))
+ this.$msg.addClass('alert-notice')
+ },
+
+ hide_errors: function(){
+ this.$msg.removeClass('alert-notice')
+ this.$msg.html("")
+ },
+
+ save: function(e){
+ e && e.preventDefault()
+
+ var valid = this.validate()
+ if (valid.errors.length) {
+ this.show_errors(valid.errors)
+ return
+ }
+ else {
+ this.hide_errors()
+ }
+
+ app.curtain.show("loading")
+ this.action({
+ data: valid.data,
+ success: function(data){
+ app.curtain.hide("loading")
+ this.success(data)
+ }.bind(this),
+ error: function(data){
+ app.curtain.hide("loading")
+ this.error(data)
+ }.bind(this),
+ })
+ },
+
+ success: function(data){
+ console.log("SUCCESS", data)
+ },
+
+ error: function(data){
+ console.log("FAIL", data)
+ },
+
+})
+
+var FormView = View.extend(SerializableView.prototype).extend(ScrollableView.prototype)
diff --git a/StoneIsland/platforms/ios/www/js/vendor/view/view.js b/StoneIsland/platforms/ios/www/js/vendor/view/view.js
index 9a8ab5b9..41638ab7 100644
--- a/StoneIsland/platforms/ios/www/js/vendor/view/view.js
+++ b/StoneIsland/platforms/ios/www/js/vendor/view/view.js
@@ -60,10 +60,15 @@ var View = (function($, _){
var eventName = match[1], selector = match[2];
method = _.bind(method, this);
eventName += '.delegateEvents' + this._id;
- if (is_mobile && (selector === 'mouseenter' || selector === 'mouseleave')) {
- continue
+ if (is_mobile) {
+ if (eventName === 'mouseenter' || eventName === 'mouseleave') {
+ continue
+ }
+// if (eventName === 'click') {
+// eventName = 'tap'
+// }
}
- else if (selector === '') {
+ if (selector === '') {
this.$el.on(eventName, method);
} else {
this.$el.on(eventName, selector, method);