/* * jQuery v1.9.1 included */ $(document).ready(function () { // Redirection to new link of Help Intake Form, incase user uses old URL const oldFormUrl = `${window.location.origin}/hc/${document.documentElement.lang.toLowerCase()}/requests/new`; const newFormUrl = oldFormUrl + '?ticket_form_id=360001225811'; if(window.location.href === oldFormUrl) { window.location.href = newFormUrl; } // social share popups $(".share a").click(function (e) { e.preventDefault(); window.open(this.href, "", "height = 500, width = 500"); }); const setiframeCssForDarkTheme = ({ iframeOpenWidget, iframeOpenbutton, iframeOpenfooter, iframeOpenheader, iframeOpentextarea }) => { iframeOpenfooter.css("box-shadow", "none"); iframeOpenfooter.css("padding", "0"); iframeOpenheader.css("padding", "0"); iframeOpentextarea.css("padding", "0 1px"); iframeOpentextarea.css("margin", "0 0 3px"); iframeOpentextarea.css("height", "20px"); $('body').css('overflow', 'hidden'); } const setiframeCssForLightTheme = ({ iframeOpenWidget, iframeOpenbutton, iframeOpenfooter, iframeOpenheader, iframeOpentextarea }) => { iframeOpenfooter.css("box-shadow", "rgb(255 255 255) 0px 0px 0.857143rem 0.571429rem"); iframeOpenfooter.css("padding", "1.07143rem 1.42857rem"); iframeOpenheader.css("padding", "0.571429rem 1rem"); iframeOpentextarea.css("padding", "0.714286em 0.857143em"); iframeOpentextarea.css("margin", "8px 0 0 0"); iframeOpentextarea.css("height", "66px"); $('body').css('overflow', 'initial'); } const setWidgetIconColorsForDarkTheme = ({ iframebutton }) => { iframebutton.css("cssText", "border:2px solid #fff !important;"); iframebutton.find('svg').css("cssText", "fill:#fff;color:#fff;"); iframebutton.find('path').css("cssText", "fill:#fff;"); } const setWidgetIconColorsForLightTheme = ({ iframebutton }) => { iframebutton.css("cssText", "border:none !important;"); iframebutton.find('svg').css("cssText", "fill:#1B2D15;color:#1B2D15;"); iframebutton.find('path').css("cssText", "fill:#1B2D15;"); } const checkIfThemeIsDark = () => { return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; } //Add focus on help widget $(document).on('DOMNodeInserted', 'iframe#launcher', function() { setTimeout(function () { const iframebutton = $('iframe#launcher').contents().find('button'); iframebutton.attr('aria-expanded','false'); iframebutton.focus(function () { $(this).css("outline", "auto"); }); iframebutton.blur(function () { $(this).css("outline", "none"); }); //detects the theme change and updates the color of an active page. window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { event.matches ? setWidgetIconColorsForDarkTheme({ iframebutton }) : setWidgetIconColorsForLightTheme({ iframebutton }); }); //sets the colors as per the active theme when the page is loaded. checkIfThemeIsDark() ? setWidgetIconColorsForDarkTheme({ iframebutton }) : setWidgetIconColorsForLightTheme({ iframebutton }); iframebutton.click(function () { $(document).on('DOMNodeInserted', 'iframe#webWidget', function() { setTimeout(function () { const iframeOpenWidget = $('iframe#webWidget').contents(); $('iframe#webWidget').attr("aria-expanded","true"); const iframeOpenbutton = iframeOpenWidget.find('button'); const iframeOpenfooter = iframeOpenWidget.find('footer'); const iframeOpenheader = iframeOpenWidget.find('header'); const iframeOpentextarea = iframeOpenfooter.find('textarea'); iframeOpenWidget.find('#widgetHeaderTitle').attr("aria-level","2"); iframeOpentextarea.css("border-color","#8D8E92"); let injectedStyleSheet = $(''); const targetElement = $('#webWidget').contents().find('#Embed'); targetElement.before(injectedStyleSheet); if ($(window).width() <= 320) { setiframeCssForDarkTheme({ iframeOpenWidget, iframeOpenfooter, iframeOpenbutton, iframeOpenheader, iframeOpentextarea }); } // Fix help widget form on 400% screen size $(window).on("resize", function () { let windowWidth = $(this).width(); if (windowWidth <= 320) { setiframeCssForDarkTheme({ iframeOpenWidget, iframeOpenbutton, iframeOpenfooter, iframeOpenheader, iframeOpentextarea }); } else { setiframeCssForLightTheme({ iframeOpenWidget, iframeOpenbutton, iframeOpenfooter, iframeOpenheader, iframeOpentextarea }); } }); if (checkIfThemeIsDark()) { iframeOpenWidget.find('header').parent().css("border", "2px solid #fff"); iframeOpenheader.css("border-bottom", "2px solid #fff"); iframeOpenbutton.find('path').css("cssText", "color:#fff !important;"); } else { iframeOpenWidget.find('header').parent().css("border", "none;"); iframeOpenheader.css("border-bottom", "none"); iframeOpenbutton.find('path').css("cssText", "color:#1B2D15 !important;"); } iframeOpenbutton.click(function () { $('body').css('overflow', 'initial'); }); iframeOpenbutton.focus(function () { this.style.setProperty("outline", "auto", "important"); }); iframeOpenbutton.blur(function () { $(this).css("outline", "none"); }); }, 200); }); }); }, 100); }); // To fix WPC accessibility issue removing Iframe var myVar = setInterval(function () { $("#automaticAnswers").contents().find(".u-paddingTT").css('color', 'black'); $("#automaticAnswers").remove(); }, 100); setTimeout(function () { // clearInterval(myVar); }, 2500); // show form controls when the textarea receives focus or backbutton is used and value exists var $commentContainerTextarea = $(".comment-container textarea"), $commentContainerFormControls = $(".comment-form-controls, .comment-ccs"); $commentContainerTextarea.one("focus", function () { $commentContainerFormControls.show(); }); if ($commentContainerTextarea.val() !== "") { $commentContainerFormControls.show(); } // Expand Request comment form when Add to conversation is clicked var $showRequestCommentContainerTrigger = $(".request-container .comment-container .comment-show-container"), $requestCommentFields = $(".request-container .comment-container .comment-fields"), $requestCommentSubmit = $(".request-container .comment-container .request-submit-comment"); $showRequestCommentContainerTrigger.on("click", function () { $showRequestCommentContainerTrigger.hide(); $requestCommentFields.show(); $requestCommentSubmit.show(); $commentContainerTextarea.focus(); }); // Mark as solved button var $requestMarkAsSolvedButton = $(".request-container .mark-as-solved:not([data-disabled])"), $requestMarkAsSolvedCheckbox = $(".request-container .comment-container input[type=checkbox]"), $requestCommentSubmitButton = $(".request-container .comment-container input[type=submit]"); $requestMarkAsSolvedButton.on("click", function () { $requestMarkAsSolvedCheckbox.attr("checked", true); $requestCommentSubmitButton.prop("disabled", true); $(this).attr("data-disabled", true).closest("form").submit(); }); // Change Mark as solved text according to whether comment is filled var $requestCommentTextarea = $(".request-container .comment-container textarea"); $requestCommentTextarea.on("keyup", function () { if ($requestCommentTextarea.val() !== "") { $requestMarkAsSolvedButton.text($requestMarkAsSolvedButton.data("solve-and-submit-translation")); $requestCommentSubmitButton.prop("disabled", false); } else { $requestMarkAsSolvedButton.text($requestMarkAsSolvedButton.data("solve-translation")); $requestCommentSubmitButton.prop("disabled", true); } }); // Disable submit button if textarea is empty if ($requestCommentTextarea.val() === "") { $requestCommentSubmitButton.prop("disabled", true); } // Submit requests filter form in the request list page $("#request-status-select, #request-organization-select") .on("change", function () { search(); }); // Submit requests filter form in the request list page $("#quick-search").on("keypress", function (e) { if (e.which === 13) { search(); } }); function search() { window.location.search = $.param({ query: $("#quick-search").val(), status: $("#request-status-select").val(), organization_id: $("#request-organization-select").val() }); } $(".header .icon-menu").on("click", function (e) { e.stopPropagation(); var menu = document.getElementById("user-nav"); var isExpanded = menu.getAttribute("aria-expanded") === "true"; menu.setAttribute("aria-expanded", !isExpanded); }); if ($("#user-nav").children().length === 0) { $(".header .icon-menu").hide(); } // Submit organization form in the request page $("#request-organization select").on("change", function () { this.form.submit(); }); // Toggles expanded aria to collapsible elements $(".collapsible-nav, .collapsible-sidebar").on("click", function (e) { e.stopPropagation(); var isExpanded = this.getAttribute("aria-expanded") === "true"; this.setAttribute("aria-expanded", !isExpanded); }); }); $(document).ready(function () { var hostname = window.location.hostname; // change text of Post Actions dropdown menu statuses $('.post-actions .dropdown-menu :nth-child(3)').text('staff comment'); $('.post-actions .dropdown-menu :nth-child(4)').text('under review'); $('.post-actions .dropdown-menu :nth-child(5)').text('updated'); $('.post-actions .dropdown-menu :nth-child(6)').text('needs info'); //hide empty status in dropdown $('#statusDrop a:last-child').hide(); //'My feedback' CTA Functionality var user_link; if (document.getElementById("user")) { $("#user-menu a").each(function () { if ($(this).text() == "My profile") { user_link = $(this).attr('href'); } }); $('#myFeedCta').attr('href', 'https://minecrafthelp.zendesk.com' + user_link); } else { $('#myFeedCta').attr('href', '#'); } //'My Feedback' on-click $("#myFeedCta").click(function (e) { var target = $(this).attr('href'); if (target == '#') { var logHref = $('.login').attr('href'); $("#myFeedCta").attr('href', logHref); } }); function mobile_search_box() { $(".menu-mobile").removeClass('bg-on-mobile'); $(".menu-mobile .menuLay img").attr("src", $(".menu-mobile .menuLay img").attr('data-mouseDef')); if ($('.show-on-mobile').is(':visible')) { $('.clearfix').removeClass('show-on-mobile'); } if (!$('.tabSer').is(':visible')) { $('.searchSpan .searchLay').addClass('closeSer'); $('.searchSpan .searchLay').css('background', '#313131'); $('.tabSer').show(); $('main').css('padding-top', '94px'); } else { $('.searchSpan .searchLay').removeClass('closeSer'); $('.searchSpan .searchLay').css('background', 'transparent'); $('.tabSer').hide(); $('main').css('padding-top', '0px'); } } // Start of #382194 accessibility bug fix $('body').on('keydown', '.searchLay', function (event) { if (event.keyCode == 13) { mobile_search_box(); } }); // End of #382194 accessibility bug fix $('body').on('click', '.searchLay', function (event) { mobile_search_box(); /*$(".menu-mobile").removeClass('bg-on-mobile'); $(".menu-mobile .menuLay img").attr("src", $(".menu-mobile .menuLay img").attr('data-mouseDef')); if ($('.show-on-mobile').is(':visible')) { $('.clearfix').removeClass('show-on-mobile'); } if (!$('.tabSer').is(':visible')) { $('.searchSpan .searchLay').addClass('closeSer'); $('.searchSpan .searchLay').css('background', '#313131'); $('.tabSer').show(); $('main').css('padding-top', '94px'); } else { $('.searchSpan .searchLay').removeClass('closeSer'); $('.searchSpan .searchLay').css('background', 'transparent'); $('.tabSer').hide(); $('main').css('padding-top', '0px'); }*/ }); //Search form $('form.search-full').attr('id', 'menuSer') /*$("#menuSer").submit(function(event) { if($('form.search-full input[type="search"]').val().length == 0) { event.preventDefault(); return false; } else { return true; } });*/ $('body').on('click', '#searchIcon', function (event) { var y = encodeURIComponent($(this).siblings('input[type="search"]').val()); var x = "/hc/en-us/search?utf8=%E2%9C%93&query=" + y; window.location.href = x; }); //shoe selected custom status in active state var abc = $('#filtersList .dropdown-menu [role="menuitem"][aria-selected="true"]').text(); $('#filtersList.dropdown .dropdown-toggle').text('Show ' + abc); //search Icon $(".menu .search-full").append(''); //NEw post page placeholder $('.new_community_post .nesty-input').text('Please select a topic...'); $("#community_post_topic_id option:first").text('Please select a topic...'); //hide empty
in post page $('.post-body p').filter(function () { return $.trim($(this).text()) === '' }).remove(); // Top nav signin text change $('.login').text('FEEDBACK LOGIN'); // Follow text change $('.post-subscribe').text('Follow Post'); // New post text change $('.newPostText').text('Post new feedback'); }); //Article Voting Box /*$(document).ready(function() { //Check if the article has been voted already if($(".article-vote-up").attr("aria-selected") !== typeof underfined && $(".article-vote-up").attr("aria-selected") === "true") { var rateDiv = document.getElementById("rate_article"); rateDiv.innerHTML = ''; rateDiv.innerText = "Already voted!"; } if($(".article-vote-down").attr("aria-selected") !== typeof underfined && $(".article-vote-down").attr("aria-selected") === "true") { var rateDiv = document.getElementById("rate_article"); rateDiv.innerHTML = ''; rateDiv.innerText = "Already voted!"; } //On click function $(".article-vote-up").click(function() { if (document.getElementById("user")) { if ($(this).hasClass("vote-voted")) { $(this).text('Vote'); } else { $(this).text('Voted!'); $(this).css('background', '#2a81d7;'); } } else { var logHref = $('.login').attr('href'); $('.vote-button').attr('href', logHref); var rateDiv = document.getElementById("rate_article"); rateDiv.innerHTML = ''; rateDiv.innerText = "Thank you!"; } }); $(".article-vote-down").click(function() { if (document.getElementById("user")) { if ($(this).hasClass("vote-voted")) { $(this).text('Vote'); } else { $(this).text('Voted!'); $(this).css('background', '#2a81d7;'); } } else { var logHref = $('.login').attr('href'); $('.vote-button').attr('href', logHref); var rateDiv = document.getElementById("rate_article"); rateDiv.innerHTML = ''; rateDiv.innerText = "Thank you!"; } }); }); */ //Custom Voting Box $(document).ready(function () { $('a.vote-up').text('Vote'); $(".vote-sum").after("Votes"); if ($('.vote-up').hasClass("vote-voted")) { $('.vote-up').text('Voted!'); $(this).css('background', '#2a81d7;'); } $(".vote-up").click(function () { if (document.getElementById("user")) { if ($(this).hasClass("vote-voted")) { $(this).text('Vote'); } else { $(this).text('Voted!'); $(this).css('background', '#2a81d7;'); } } else { var logHref = $('.login').attr('href'); $('.vote-button').attr('href', logHref); } }); }); $(document).ready(function () { var assetsMouseLeave = $(".menu-mobile .menuLay img").attr('data-mouseClo'); var assetsMenuClose = $(".menu-mobile .menuLay img").attr('data-mouseDef'); "use strict"; $('.menu > ul > li:has( > ul)').addClass('menu-dropdown-icon'); $('.menu > ul > li > ul:not(:has(ul))').addClass('normal-sub'); //$(".menu .mLogo").before(" "); $(".menu > ul").first().before(" "); $(".menu > ul > li").hover(function (e) { }); $(".menu > ul > li").click(function () { if ($(window).width() <= 943) { $(this).children("ul").fadeToggle(150); } }); $(".menu-mobile").click(function (e) { $('.searchSpan .searchLay').removeClass('closeSer'); $(".menu-mobile").toggleClass('bg-on-mobile'); if (!$(".menu-mobile").hasClass('bg-on-mobile')) { $(".menu-mobile .menuLay img").attr("src", assetsMenuClose); } else { $(".menu-mobile .menuLay img").attr("src", assetsMouseLeave); } $(".menu > ul").toggleClass('show-on-mobile'); $('.searchSpan .searchLay').css('background', 'transparent'); $('.tabSer').css('display', 'none'); e.preventDefault(); }); }); $(window).resize(function () { $(".menu > ul > li").children("ul").hide(); $(".menu > ul").removeClass('show-on-mobile'); }); //Post form custom validations $(document).ready(function () { $('body').on('click', 'form.new_community_post input[type="submit"]', function (event) { if ($("#hc-wysiwyg").length > 0) { if ($.trim($('#community_post_title').val()) === "" || $.trim($('#community_post_details_ifr').contents().find('body').text()) === "" || $.trim($("#community_post_topic_id").val()) === "" || $('#community_post_title').val().length > 75 || $.trim($('#community_post_details_ifr').contents().find('body').text()).length > 1500) { event.preventDefault(); if ($.trim($('#community_post_title').val()) === "" || $('#community_post_title').val().length > 75) { if ($.trim($('#community_post_title').val()) === "") { $('#editorVali1').text("can't be blank"); } else if ($('#community_post_title').val().length > 75) { $('#editorVali1').text("maximum 75 characters only"); } $('#editorVali1').css('display', 'block'); } else { $('#editorVali1').css('display', 'none'); } if ($.trim($('#community_post_details_ifr').contents().find('body').text()) === "" || $.trim($('#community_post_details_ifr').contents().find('body').text()).length > 1500) { if ($.trim($('#community_post_details_ifr').contents().find('body').text()) === "") { $('#editorVali').text("can't be blank"); } else if ($.trim($('#community_post_details_ifr').contents().find('body').text()).length > 1500) { $('#editorVali').text("maximum 1500 characters only"); } $('#editorVali').css('display', 'block'); } else { $('#editorVali').css('display', 'none'); } if ($.trim($('#community_post_topic_id').val()) === "") { $('#editorVali3').css('display', 'block'); } else { $('#editorVali3').css('display', 'none'); } return false; } else { return true; } } else { if ($.trim($('#community_post_title').val()) === "" || $.trim($('#community_post_details').val()) === "" || $.trim($("#community_post_topic_id").val()) === "" || $('#community_post_title').val().length > 75 || $('#community_post_details').val().length > 1500) { event.preventDefault(); if ($.trim($('#community_post_title').val()) === "" || $('#community_post_title').val().length > 75) { if ($.trim($('#community_post_title').val()) === "") { $('#editorVali1').text("can't be blank"); } else if ($('#community_post_title').val().length > 75) { $('#editorVali1').text("maximum 75 charecters only"); } $('#editorVali1').css('display', 'block'); } else { $('#editorVali1').css('display', 'none'); } if ($.trim($('#community_post_details').val()) === "" || $('#community_post_details').val().length > 1500) { if ($.trim($('#community_post_details').val()) === "") { $('#editorVali').text("can't be blank"); } else if ($('#community_post_details').val().length > 1500) { $('#editorVali').text("maximum 1500 charecters only"); } $('#editorVali').css('display', 'block'); } else { $('#editorVali').css('display', 'none'); } if ($.trim($('#community_post_topic_id').val()) === "") { $('#editorVali3').css('display', 'block'); } else { $('#editorVali3').css('display', 'none'); } return false; } else { return true; } } }); }); //Comment form custom validation $(document).ready(function () { $('body').on('click', 'form.comment-form input[type="submit"]', function (event) { if ($("#hc-wysiwyg").length > 0) { if ($.trim($('#community_comment_body_ifr').contents().find('body').text()).length > 1500) { event.preventDefault(); if ($.trim($('#community_comment_body_ifr').contents().find('body').text()).length > 1500) { $('#editorValiCom').css('display', 'block'); } else { $('#editorValiCom').css('display', 'none'); } return false; } else { return true; } } else { if ($.trim($('#community_comment_body').val()).length > 1500) { event.preventDefault(); if ($.trim($('#community_comment_body').val()).length > 1500) { $('#editorValiCom').css('display', 'block'); } else { $('#editorValiCom').css('display', 'none'); } return false; } else { return true; } } }); }); /* Request Creation */ $(document).ready(function () { var hostname = window.location.hostname; $(".reportComment span, .reportPost").click(function () { var arr1 = [{ "requester": { "name": "Anonymous customer" }, "subject": "Help!", "comment": { "body": "My printer is on fire!" } }]; arr1.forEach(function (elem, index) { var arr = { "request": elem }; $.ajax({ url: 'https://' + hostname + '/api/v2/requests.json', type: 'POST', data: JSON.stringify(arr), contentType: 'application/json', Accept: 'application/json', dataType: 'json', async: false, success: function (msg) { $('.hover_bkgr_fricc').show(); console.log(msg); }, error: function (xhr, errorText) { console.log('Error ' + xhr.responseText); } }); }); }); }); $(window).load(function () { $(".trigger_popup_fricc").click(function () { $('.hover_bkgr_fricc').show(); }); $('.hover_bkgr_fricc').click(function () { $('.hover_bkgr_fricc').hide(); }); $('.popupCloseButton').click(function () { $('.hover_bkgr_fricc').hide(); }); }); jQuery(window).on("load resize", function () { var assetsMenuClose = $(".menu-mobile .menuLay img").attr('data-mouseDef'); setTimeout(function () { jQuery(function () { var assetsMenuClose = $(".menu-mobile .menuLay img").attr('data-mouseDef'); var userAgent = (navigator.userAgent.match(/(iPod|iPhone|iPad|Android)/)); if (navigator.userAgent.match(/Android/i)) { $(".menu-mobile .menuLay img").attr("src", assetsMenuClose); $(".menu-mobile").removeClass('bg-on-mobile'); $(".menu > ul").removeClass('show-on-mobile'); } else if (navigator.userAgent.match(/iPod|iPhone|iPad/i)) { $(".menu-mobile .menuLay img").attr("src", assetsMenuClose); $(".menu-mobile").removeClass('bg-on-mobile'); $(".menu > ul").removeClass('show-on-mobile'); } }); }, 300); }); //$(window).load(function() { $(document).ready(function () { var url = window.location.href; var hostname = window.location.hostname; var lang = $('html').attr('lang').toLowerCase(); console.log('4444', lang) /*if (url == 'https://' + hostname + '/hc/' + lang + '/requests/new/' || url == 'https://' + hostname + '/hc/' + lang + '/requests/new') { $('.customCountry').hide(); } */ $('.customCountry').hide(); /*else { $('.customCountry').hide(); }*/ var localStorageObj = JSON.parse(localStorage.getItem('minecraftHelpForm')); if (localStorageObj && localStorageObj.params[0].url === 'report_location') { $('#request_custom_fields_360021175192').val('gf_minecraft_earth'); $('#request_custom_fields_360021224051').val('-_unsafe_location_report'); if (localStorageObj.params[1].latitude != '') { var lat = localStorageObj.params[1].latitude.replace("lat=", ""); $('#request_custom_fields_360021225191').val(lat); } if (localStorageObj.params[2].longitude != '') { var long = localStorageObj.params[2].longitude.replace("long=", ""); $('#request_custom_fields_360021177472').val(long); } } localStorage.removeItem('minecraftHelpForm'); }); /*Genoa form Country flag for PhoneNumber field functionality - 95314 */ $(document).ready(function () { $("#request_custom_fields_360021225171").attr('type', 'tel'); $("#request_custom_fields_360021225171").on('keypress', function (evt) { var charCode = (evt.which) ? evt.which : evt.keyCode; if (charCode != 46 && charCode != 45 && charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; }); $("#request_custom_fields_360021225171").wrap('
'); var countriesList = { "DZ": "213", "AO": "244", "AR": "54", "AM": "374", "AU": "61", "AT": "43", "AZ": "994", "BH": "973", "BE": "32", "BJ": "229", "BO": "591", "BW": "267", "BR": "55", "BG": "359", "BF": "226", "BI": "257", "CM": "237", "CA": "1", "CV": "238", "CF": "236", "TD": "235", "CL": "56", "CN": "86", "CO": "57", "CR": "506", "HR": "385", "CY": "357", "CZ": "420", "CD": "243", "DK": "45", "DO": "1-809", "EC": "539", "EG": "20", "SV": "503", "GQ": "240", "ER": "291", "EE": "372", "ET": "251", "FI": "358", "FR": "33", "GA": "241", "GM": "220", "GE": "995", "DE": "49", "GH": "233", "GR": "30", "GT": "502", "GN": "224", "GW": "245", "HN": "504", "HK": "852", "HU": "36", "IS": "354", "IN": "91", "ID": "62", "IR": "98", "IR": "964", "IE": "353", "IL": "972", "IT": "39", "JM": "1-876", "JP": "81", "JO": "962", "KZ": "7", "KE": "254", "KR": "82", "KW": "965", "LV": "371", "LB": "961", "LS": "266", "LR": "231", "LY": "218", "LI": "423", "LT": "370", "LU": "352", "MO": "853", "MK": "389", "MG": "261", "MW": "265", "MY": "60", "ML": "223", "MT": "356", "MR": "222", "MU": "230", "MX": "52", "MC": "377", "MA": "212", "MZ": "258", "NA": "264", "NL": "31", "NZ": "64", "NE": "227", "NG": "234", "NO": "47", "OM": "968", "PK": "92", "PA": "507", "PY": "595", "PE": "51", "PH": "63", "PL": "48", "PT": "351", "QA": "974", "CG": "242", "RO": "40", "RU": "7", "RW": "250", "ST": "239", "SA": "966", "SN": "221", "RS": "381", "SC": "248", "SG": "65", "SK": "421", "SI": "386", "ZA": "27", "ES": "34", "SD": "249", "SZ": "268", "SE": "46", "CH": "41", "SY": "963", "TW": "886", "TZ": "255", "TH": "66", "TG": "228", "TT": "1-868", "TN": "216", "TR": "90", "TM": "993", "UG": "256", "UA": "380", "AE": "971", "GB": "44", "US": "1", "UY": "598", "VE": "58", "VN": "84", "YE": "967", "ZM": "260", "ZW": "263" } $('#countryPhoneNumber').flagsdd({ countries: countriesList, scrollable: true, scrollableHeight: "200px" }); $(document).click(function (e) { e.stopPropagation(); var container = $("#flags-drop-down"); //check if the clicked area is dropDown or not if (container.has(e.target).length === 0) { $('#flags-drop-down-list').removeClass('open') } }) }); $.fn.flagsdd = function (options) { return this.each(function (i) { if ($(this).data('flags') === undefined) { $(this).data('flags', new $.generateFlagsDD(this, options, i)); } }); } var defaults = { labelMargin: "10px", scrollable: true, scrollableHeight: "250px", placeholder: { value: '', } }; var countries; var default_size = { w: 20, h: 15 }; function calcPos(letter, size) { return -(letter.toLowerCase().charCodeAt(0) - 97) * size; } $.fn.setFlagPosition = function (iso, size) { size || (size = default_size); var x = calcPos(iso[1], size.w), y = calcPos(iso[0], size.h); return $(this).css('background-position', [x, 'px ', y, 'px'].join('')); }; $.generateFlagsDD = function (element, options, i) { var plugin = this; plugin.countries = {}; plugin.selected = { value: null, text: null }; var $container = $(element); var htmlSelectId = 'flag-select'; var htmlSelect = '#' + htmlSelectId; plugin.init = function () { // Merge in global settings then merge in individual settings via data attributes plugin.countries = countries; // Initialize Settings, priority: defaults, init options, data attributes plugin.countries = countries; plugin.settings = $.extend({}, defaults, options, $container.data()); if (undefined !== plugin.settings.countries) { plugin.countries = plugin.settings.countries; } if (undefined !== plugin.settings.inputId) { htmlSelectId = plugin.settings.inputId; htmlSelect = '#' + htmlSelectId; } // Build HTML Select, Construct the drop down button, Assemble the drop down list items element and insert $container.append(buildHtmlSelect).append(buildDropDownButton).append(buildDropDownButtonItemList); $('#flags-drop-down').on('click', function () { $(".dropdown-menu").addClass('open') }) // Hide the actual HTML select $(htmlSelect).hide(); }; var buildHtmlSelect = function () { var htmlSelectElement = $('').attr('id', htmlSelectId).attr('name', plugin.settings.inputName); $.each(plugin.countries, function (code, country) { var optionAttributes = { value: code }; if (plugin.settings.selectedCountry !== undefined) { if (plugin.settings.selectedCountry === code) { optionAttributes = { value: code, selected: "selected" }; plugin.selected = { value: code, text: country } } } htmlSelectElement.append($('