var scripts = document.getElementsByTagName( "script" ); var thisScriptTag = scripts[ scripts.length - 1 ]; var theme = thisScriptTag.getAttribute("theme"); var width = thisScriptTag.getAttribute("width"); var lang = thisScriptTag.getAttribute("lang"); var loc = thisScriptTag.getAttribute("loc"); var pos = thisScriptTag.getAttribute("pos"); var widget_done = false; var notLoaded = true; var widget_wrapper_id = Math.floor((Math.random()*1000)+1); var w_id = "#" + widget_wrapper_id + " "; var newAdd; var slideDirection; var startPosition; if (!theme) { theme = "lingos"; } if (theme == "lingos" && !width) { width = 710; }else if (!width){ width = 340; } height = 470; if (!lang) { lang = ""; } if (!loc) { loc = ""; } if (!pos) { pos = "right"; } if (pos == "right") { slideDirection = "right"; startPosition = width; } if (pos == "left") { slideDirection = "left"; startPos = "0px"; } if (pos == "top") { slideDirection = "up"; startPos = "0px"; } if (pos == "bottom") { slideDirection = "down"; startPos = "0px"; } if (typeof jQuery != "undefined") { _do_widgets(lang, loc); }else{ var _s=document.createElement("script"); _s.setAttribute("type","text/javascript"); _s.setAttribute("src","https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"); document.getElementsByTagName("head")[0].appendChild(_s); } if (typeof jQuery != "undefined") { _do_widgets(lang, loc); }else{ setTimeout("_check_jquery()",50); } function _check_jquery() { if (typeof jQuery != "undefined") { _do_widgets(lang, loc); }else{ setTimeout("_check_jquery()",50); } } function _do_widgets(lang, loc) {if (!widget_done) { var _s=document.createElement("link"); _s.setAttribute("rel", "stylesheet"); _s.setAttribute("type", "text/css"); _s.setAttribute("href", "https://lingos.co/sites/all/themes/lingos_theme/css/widget.css"); document.getElementsByTagName("head")[0].appendChild(_s); var _s=document.createElement("script"); _s.setAttribute("type","text/javascript"); _s.setAttribute("src","https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places&callback=initialize"); document.getElementsByTagName("head")[0].appendChild(_s); var _s=document.createElement("script"); _s.setAttribute("type","text/javascript"); _s.setAttribute("src","https://lingos.co/sites/all/themes/lingos_theme/js/widget.js"); document.getElementsByTagName("head")[0].appendChild(_s); var _s=document.createElement("script"); _s.setAttribute("type","text/javascript"); _s.setAttribute("src","https://lingos.co/sites/all/libraries/jquery-ui-1.8.7/jquery-ui-1.7.3.custom.min.js"); document.getElementsByTagName("head")[0].appendChild(_s); var _kmq = _kmq || []; var _kmk = _kmk || "df0cd5d84acbace3d8b27c4bd857e3aee0949de2"; function _kms(u){ setTimeout(function(){ var d = document, f = d.getElementsByTagName("script")[0], s = d.createElement("script"); s.type = "text/javascript"; s.async = true; s.src = u; f.parentNode.insertBefore(s, f); }, 1); } _kms("//i.kissmetrics.com/i.js"); _kms("//doug1izaerwt3.cloudfront.net/" + _kmk + ".1.js"); _kmq.push(["identify", window.location.hostname]); } widget_done = true; } function initialize() { var _s=document.createElement("script"); _s.setAttribute("type","text/javascript"); _s.setAttribute("src","https://lingos.co/sites/all/themes/lingos_theme/js/jquery.geocomplete.min.js"); document.getElementsByTagName("head")[0].appendChild(_s); jQuery.ajax({ url: "https://lingos.co/widget_html/" + lang + "/" + loc + "/" + pos + "/" + width + "/" + height + "/" + window.location.hostname + "?callback=?", type: "GET", dataType:"jsonp", crossDomain: "true", cache: false, timeout: 60000, error: function(XMLHttpRequest, textStatus, errorThrown){ }, success: function(result){ var _d = document.createElement("div"); _d.setAttribute("id", widget_wrapper_id); if (pos == "right" || pos == "left") { _d.setAttribute("class", "widget_position_vertical"); }else{ _d.setAttribute("class", "widget_position_horizontal"); } jQuery(_d).html(result.html); jQuery(thisScriptTag).after(_d); jQuery(w_id + ".lingos_widget_menu li").click(function() { lingos_widget_show(this); jQuery(w_id + "#lingos_widget_content").show("slide", {direction: "right"}, width); }); jQuery(w_id + "#lingos_widget_header .close").click(function() { if (pos == "right" || pos == "left") { jQuery(w_id +"#lingos_widget_content").hide("slide", {direction: pos}, width); } if (pos == "top") { jQuery(w_id +"#lingos_widget_content").hide("slide", {direction: "up"}, height); } if (pos == "bottom") { jQuery(w_id +"#lingos_widget_content").hide("slide", {direction: "down"}, height); } }); jQuery(w_id + "#lingos_widget_iframe").load(function (){ if (!notLoaded) { setTimeout("lingos_widget_loaded()", 500) } }); jQuery(w_id + "#lingos_widget_content").css("width", width + "px"); if (pos == "right") { jQuery(w_id + "#lingos_widget_content").css("left", "-" + width + "px"); } if (pos == "left") { jQuery(w_id + "#lingos_widget_content").css("left", jQuery("#lingos_widget_menu_content").width() + "px"); } if (pos == "right" || pos == "left") { jQuery(w_id + "#lingos_widget_content").css("top", "0px"); } if (pos == "top") { jQuery(w_id + "#lingos_widget_content").css("top", jQuery("#lingos_widget_menu_content").height() + "px"); }if (pos == "bottom") { jQuery(w_id + "#lingos_widget_content").css("bottom", jQuery("#lingos_widget_menu_content").height() + "px"); } jQuery(w_id + "#lingos_widget_wrapper").css("display", "block"); jQuery(w_id + "#lingos_widget_iframe").attr("width", width + "px"); jQuery("#lingos-widget-form .form-item-location input").geocomplete({ details: "form", country: "" }); jQuery("#lingos-widget-form #edit-location").geocomplete({ details: "form", country: "" }); jQuery("#lingos-widget-form #edit-location").bind("geocode:result", function(event, result){ newAdd = result.formatted_address.replace(", UK", ""); jQuery("#lingos-widget-form #edit-location").val(result.formatted_address.replace(", UK", "")); setTimeout("doNewAdd()", 100); }); } }); } function doNewAdd() { jQuery("#lingos-widget-form #edit-location").val(newAdd); } function lingos_widget_loaded() { jQuery(w_id +"#lingos_widget_wait").css("visibility", "hidden"); jQuery(w_id +"#lingos_widget_iframe").css("visibility", "visible"); notLoaded = true; } function lingos_widget_show(type) { notLoaded = false; jQuery(w_id +"#lingos_widget_iframe").css("visibility", "hidden"); jQuery(w_id +"#lingos_widget_wait").css("visibility", "visible"); jQuery(w_id +"#lingos_widget_iframe").attr("src", "https://lingos.co/language-lessons/" + jQuery("#edit-language").val() + "/" + jQuery("#edit-location").val() + "?widget=true&no_bsd=TRUE&width=700&height=410"); }