1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-12-27 09:58:20 +01:00
antd-web-apps/blog/assets/main.js
Xuan Sang LE 9d8e0916a2 fix blog
2018-09-05 19:07:37 +02:00

126 lines
4.7 KiB
JavaScript

var scheme = undefined;
String.prototype.__ = function()
{
return this
}
function subscribe(prefix)
{
if(scheme) return;
// get scheme
$.get(prefix+"/rst/subscribe.html")
.done(function(d) {
scheme = $.parseHTML(d)
var obs = riot.observable()
$(scheme).css("visibility","hidden")
$("#desktop" ).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")
})
riot.mount(scheme, {observable:obs})
})
.fail(function() {
alert( "Cannot get the form" );
})
}
function mailtoMe(prefix)
{
if(scheme) return;
// get scheme
$.get(prefix+"/rst/sendto.html")
.done(function(d) {
scheme = $.parseHTML(d)
var obs = riot.observable()
$(scheme).css("visibility","hidden")
$("#desktop" ).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")
})
riot.mount(scheme, {observable:obs})
})
.fail(function() {
alert( "Cannot get the form" );
})
}