2018-03-15 22:36:05 +01:00
|
|
|
var scheme = undefined;
|
|
|
|
String.prototype.__ = function()
|
|
|
|
{
|
|
|
|
return this
|
|
|
|
}
|
2018-06-05 16:28:53 +02:00
|
|
|
function subscribe(prefix)
|
|
|
|
{
|
|
|
|
if(scheme) return;
|
|
|
|
// get scheme
|
|
|
|
$.get(prefix+"/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 + "/subscribe.lua",
|
|
|
|
contentType: 'application/json',
|
|
|
|
data: JSON.stringify(data),
|
|
|
|
dataType: 'json',
|
|
|
|
success: null
|
|
|
|
}).done(function(r){
|
|
|
|
if(r.error)
|
|
|
|
alert(r.error)
|
|
|
|
else
|
|
|
|
{
|
|
|
|
obs.trigger("exit")
|
|
|
|
alert("You have been subscribed. Thanks")
|
|
|
|
}
|
|
|
|
}).fail(function(e, s){
|
|
|
|
alert("Error: " + e)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
$(scheme).css("visibility","visible")
|
|
|
|
})
|
|
|
|
riot.mount(scheme, {observable:obs})
|
|
|
|
})
|
|
|
|
.fail(function() {
|
|
|
|
alert( "Cannot get the form" );
|
|
|
|
})
|
|
|
|
}
|
2018-03-15 22:47:54 +01:00
|
|
|
function mailtoMe(prefix)
|
2018-03-15 22:36:05 +01:00
|
|
|
{
|
|
|
|
if(scheme) return;
|
|
|
|
// get scheme
|
2018-03-15 22:47:54 +01:00
|
|
|
$.get(prefix+"/sendto.html")
|
2018-03-15 22:36:05 +01:00
|
|
|
.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',
|
2018-03-15 22:47:54 +01:00
|
|
|
url: prefix + "/sendmail.lua",
|
2018-03-15 22:36:05 +01:00
|
|
|
contentType: 'application/json',
|
|
|
|
data: JSON.stringify(data),
|
|
|
|
dataType: 'json',
|
|
|
|
success: null
|
|
|
|
}).done(function(r){
|
|
|
|
if(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" );
|
|
|
|
})
|
|
|
|
}
|