1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-20 02:18:20 +01:00
antd-web-apps/blog/assets/main.js

135 lines
5.5 KiB
JavaScript
Raw Permalink Normal View History

2018-09-05 19:07:37 +02:00
var scheme = undefined;
2020-09-18 13:17:43 +02:00
OS.GUI.workspace = undefined;
String.prototype.__ = function () {
return this;
};
function subscribe(prefix) {
if (!OS.GUI.workspace) OS.GUI.workspace = $("body");
if (scheme) return;
2018-09-05 19:07:37 +02:00
// get scheme
2020-09-18 13:17:43 +02:00
$.get(prefix + "/rst/subscribe.html")
.done(function (d) {
scheme = $.parseHTML(d);
var obs = new OS.API.Announcer();
$(scheme).css("visibility", "hidden");
$("body").append(scheme);
obs.on("exit", function () {
$(scheme).remove();
scheme = undefined;
});
obs.on("rendered", function (d) {
$(".afx-window-title", scheme).html("Subscribe");
$("[data-id='send']", scheme).click(function () {
var status = $("[data-id='status']", scheme);
status.html("");
var els = $("[data-class='data']", scheme);
var data = {};
for (var i = 0; i < els.length; i++)
data[els[i].name] = $(els[i]).val();
if (
data.email == "" ||
data.subject == "" ||
data.content == "" ||
data.name == ""
)
return status.html("Please enter all the fields");
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (!re.test(String(data.email).toLowerCase()))
return status.html("Email is not correct");
$.ajax({
type: "POST",
url: prefix + "/service/subscribe",
contentType: "application/json",
data: JSON.stringify(data),
dataType: "json",
success: null,
})
.done(function (r) {
if (r.error) {
console.log(r.error);
alert(r.error);
} else {
obs.trigger("exit");
alert("You have been subscribed. Thanks");
}
})
.fail(function (e, s) {
console.log(e);
alert("Error: " + e);
});
});
$(scheme).css("visibility", "visible");
});
scheme[0].uify(obs, true);
2018-09-05 19:07:37 +02:00
})
2020-09-18 13:17:43 +02:00
.fail(function () {
alert("Cannot get the form");
});
2018-09-05 19:07:37 +02:00
}
2020-09-18 13:17:43 +02:00
function mailtoMe(prefix) {
if (!OS.GUI.workspace) OS.GUI.workspace = $("body");
if (scheme) return;
2018-09-05 19:07:37 +02:00
// get scheme
2020-09-18 13:17:43 +02:00
$.get(prefix + "/rst/sendto.html")
.done(function (d) {
scheme = $.parseHTML(d);
var obs = new OS.API.Announcer();
$(scheme).css("visibility", "hidden");
$("body").append(scheme);
obs.on("exit", function () {
$(scheme).remove();
scheme = undefined;
});
obs.on("rendered", function (d) {
$(".afx-window-title", scheme).html("Send me an email");
$("[data-id='send']", scheme).click(function () {
var status = $("[data-id='status']", scheme);
status.html("");
var els = $("[data-class='data']", scheme);
var data = {};
for (var i = 0; i < els.length; i++)
data[els[i].name] = $(els[i]).val();
if (
data.email == "" ||
data.subject == "" ||
data.content == "" ||
data.name == ""
)
return status.html("Please enter all the fields");
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (!re.test(String(data.email).toLowerCase()))
return status.html("Email is not correct");
$.ajax({
type: "POST",
url: prefix + "/service/sendmail",
contentType: "application/json",
data: JSON.stringify(data),
dataType: "json",
success: null,
})
.done(function (r) {
if (r.error) {
console.log(r.error);
alert(r.error);
} else {
obs.trigger("exit");
alert("Email sent. Thank");
}
})
.fail(function () {
alert("Service unavailable at the moment");
});
});
$(scheme).css("visibility", "visible");
});
scheme[0].uify(obs, true);
2018-09-05 19:07:37 +02:00
})
2020-09-18 13:17:43 +02:00
.fail(function () {
alert("Cannot get the form");
});
}