-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
449 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,99 @@ | ||
$(document).ready(function () { | ||
/*globals window */ | ||
|
||
$(document.body).delegate("form", "submit", function () { | ||
var form$ = $(this) | ||
, formData = form$.serialize() | ||
, bookmark = form$.hasClass("bookmark"); | ||
$("input, textarea", form$).attr("disabled", "disabled"); | ||
$("input[type=submit]", form$).val("Sending..."); | ||
(function (crafity, $, window) { | ||
|
||
$("html").addClass("loading"); | ||
$.ajax({ | ||
type: 'POST', | ||
url: form$.attr("action") + "?layout=false", | ||
data: formData, | ||
success: function (data, textStatus, xhr) { | ||
if (form$.hasClass("async")) { | ||
try { | ||
var url = xhr.getResponseHeader("x-crafity-location").split("?")[0] | ||
, content$ = $("#content") | ||
, data$ = $("<div/>").append(data); | ||
"use strict"; | ||
|
||
console.log("SUCCESS arguments", arguments); | ||
console.log("--> url", url); | ||
content$.attr("data-href", url); | ||
if (bookmark) { | ||
crafity.navigation.hashInfo.update(""); | ||
crafity.navigation.hashInfo.change({ href: url }); | ||
} | ||
crafity.ready(function () { | ||
|
||
content$.removeClass('loading').addClass('loaded'); | ||
content$.find(".columns").addClass("open"); | ||
data$.find(".columns").addClass("open"); | ||
return; | ||
|
||
$(window.document.body).delegate("form", "submit", function () { | ||
var form$ = $(this) | ||
, formData = form$.serialize() | ||
, bookmark = form$.hasClass("bookmark") | ||
, submitButton$ = $("input[type=submit]", form$) | ||
, target, target$ | ||
, href = form$.attr("action"); | ||
|
||
var showContent = function showContent(data$, url) { | ||
data$ = content$.empty().append(data$.children()[0]); | ||
content$.attr("data-href", url); | ||
$("html").removeClass("not-ready").addClass("ready"); | ||
setTimeout(function () { | ||
data$.find(".columns").removeClass("open"); | ||
}, 1); | ||
} | ||
$("input, textarea", form$).attr("disabled", "disabled"); | ||
submitButton$.val(submitButton$.attr("data-busy-value") || submitButton$.val()).addClass("busy"); | ||
|
||
if (form$.attr("data-async") === "content") { | ||
target = form$.attr("data-async-target"); | ||
target$ = form$.nearest(target); | ||
} | ||
|
||
if (!target$ || !target$.length) { | ||
throw new Error("Unable to find target element for form result"); | ||
} | ||
|
||
$("html").addClass("loading"); | ||
|
||
$.ajax({ | ||
type: 'POST', | ||
url: href + (href.indexOf("?") > -1 ? "&" : "?") + ("layout=false"), | ||
data: formData, | ||
success: function (data, textStatus, xhr) { | ||
if (form$.hasClass("async")) { | ||
try { | ||
var url = xhr.getResponseHeader("x-crafity-location").split("?")[0] | ||
, data$ = $("<div/>").append(data) | ||
, showContent; | ||
console.log("data$", data$); | ||
console.log("SUCCESS arguments", arguments); | ||
console.log("--> url", url); | ||
target$.attr("data-href", url); | ||
if (bookmark) { | ||
crafity.navigation.hashInfo.update(""); | ||
crafity.navigation.hashInfo.change({ href: url }); | ||
} | ||
|
||
if ($("html").hasClass("ready")) { | ||
setTimeout(function () { | ||
target$.removeClass('loading').addClass('loaded'); | ||
target$.find(".columns").addClass("open"); | ||
data$.find(".columns").addClass("open"); | ||
|
||
showContent = function showContent(data$, url) { | ||
data$ = target$.empty().append(data$.children()[0]); | ||
target$.attr("data-href", url); | ||
$("html").removeClass("not-ready").addClass("ready"); | ||
setTimeout(function () { | ||
data$.find(".columns").removeClass("open"); | ||
}, 1); | ||
}; | ||
|
||
if ($("html").hasClass("ready")) { | ||
setTimeout(function () { | ||
showContent(data$, url); | ||
}, 500); | ||
} else { | ||
showContent(data$, url); | ||
}, 500); | ||
} else { | ||
showContent(data$, url); | ||
} | ||
} catch (err) { | ||
console.log("ERROR arguments", err); | ||
crafity.flash.show({ message: err.message, type: "error" }); | ||
} | ||
} catch (err) { | ||
console.log("ERROR arguments", err); | ||
konnektid.flash.show({ message: err.message, type: "error" }); | ||
return; | ||
} | ||
return; | ||
} | ||
|
||
form$ | ||
.closest(".body") | ||
.empty() | ||
.append(data); | ||
form$ | ||
.closest(".body") | ||
.empty() | ||
.append(data); | ||
|
||
form$.closest("section").removeClass("visible").addClass("visible"); | ||
form$.closest("section").removeClass("visible").addClass("visible"); | ||
|
||
$("html").removeClass("loading"); | ||
console.log("postResult", data); | ||
}, | ||
error: function (jqXHR, textStatus, errorThrown) { | ||
console.log("jqXHR, textStatus, errorThrown", jqXHR, jqXHR.error(), textStatus, errorThrown); | ||
konnektid.flash.show({ message: jqXHR.responseText, type: jqXHR.status !== 400 ? "error" : "warning" }); | ||
} | ||
$("html").removeClass("loading"); | ||
console.log("postResult", data); | ||
}, | ||
error: function (jqXHR, textStatus, errorThrown) { | ||
console.log("jqXHR, textStatus, errorThrown", jqXHR, jqXHR.error(), textStatus, errorThrown); | ||
crafity.flash.show({ message: jqXHR.responseText, type: jqXHR.status !== 400 ? "error" : "warning" }); | ||
} | ||
}); | ||
return false; | ||
}); | ||
return false; | ||
|
||
}); | ||
|
||
}); | ||
}(window.crafity = window.crafity || {}, window.jQuery, window)); |
Oops, something went wrong.