Skip to content

Instantly share code, notes, and snippets.

@max-kk
Last active August 4, 2016 15:02
Show Gist options
  • Save max-kk/1cd328071714dfd43786da5c69c64286 to your computer and use it in GitHub Desktop.
Save max-kk/1cd328071714dfd43786da5c69c64286 to your computer and use it in GitHub Desktop.
jQuery.cachedScript = function( url, options ) {
// Allow user to set any option except for dataType, cache, and url
options = $.extend( options || {}, {
dataType: "script",
cache: true,
url: url
});
// Use $.ajax() since it is more flexible than $.getScript
// Return the jqXHR object so we can chain callbacks
return jQuery.ajax( options );
};
var swal_loaded = false;
function swal_load() {
if ( !swal_loaded ) {
jQuery.cachedScript("https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js");
var swal_stylesheet = document.createElement('link')
swal_stylesheet.setAttribute('rel', 'stylesheet')
swal_stylesheet.setAttribute('type', 'text/css')
swal_stylesheet.setAttribute('href', "https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css")
document.getElementsByTagName('head')[0].appendChild(swal_stylesheet);
swal_loaded = true;
}
}
swal_load();
function show_message(title, message, type) {
if ( type == undefined ) {
type = "success";
}
if ( typeof swal != "undefined" ) {
swal(title, message, type);
} else {
alert(title + message);
}
}
show_message("Отправлено!", "Спасибо за заявку! Скоро с Вами свяжется наш менеджер.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment