diff --git a/README.md b/README.md index 0617206..2046146 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,13 @@ ### References ### -Module Icon made by http://www.flaticon.com/authors/gregor-cresnar from www.flaticon.com +* Module Icon made by http://www.flaticon.com/authors/gregor-cresnar from www.flaticon.com +* International number codes by https://jackocnr.com/ from https://github.com/jackocnr/intl-tel-input ### To-do ### * Form submission security -* Telephone dropdown code country +✔ Telephone dropdown code country * Try it in PS 1.5.XX ### Please feel free to contribute ### diff --git a/callmeback.php b/callmeback.php index 54279d3..e1df6fb 100755 --- a/callmeback.php +++ b/callmeback.php @@ -159,9 +159,38 @@ public function getHookController($hookName) */ public function hookDisplayHeader() { - $this->context->smarty->assign(array( - 'callmeback_ajax' => $this->context->link->getModuleLink($this->name, 'ajax', array(), null, null, true), - )); + $ip = $this->getUserIP(); + $current_country = $this->getIPInfo($ip, "Country Code"); + + if (Tools::isEmpty($current_country)) { + $current_country = Context::getContext()->country->iso_code; + } + + $active_countries = array_column(Country::getCountries(Context::getContext()->country->iso_code), 'iso_code'); + + // Show preffered country codes in dropdown list, only if there are a few countries available. + if (sizeof($active_countries) < 5) { + $this->context->smarty->assign( + array( + 'prefered_countries' => $active_countries, + ) + ); + } + else { + $this->context->smarty->assign( + array( + 'prefered_countries' => [Context::getContext()->country->iso_code], + ) + ); + } + + $this->context->smarty->assign( + array( + 'dir' => $this->getBaseUrl() . 'modules/' . $this->name . '/views/js/', + 'callmeback_ajax' => $this->context->link->getModuleLink($this->name, 'ajax', array(), null, null, true), + 'current_country' => $current_country, + ) + ); return $this->display(__FILE__, 'views/templates/front/jsdef.tpl'); } @@ -186,10 +215,14 @@ public function hookDisplayBackOfficeHeader() * @return string Hook HTML */ public function hookdisplayProductButtons() - { + { $config = $this->getConfiguration(); $config['callmebackimg'] = $this->getBaseUrl().'modules/callmeback/phone-call.png'; - $this->context->smarty->assign('callmeback_config', $config); + $this->context->smarty->assign( + array( + 'callmeback_config' => $config, + ) + ); return $this->display(__FILE__, 'views/templates/front/callmebutton.tpl'); } @@ -200,8 +233,14 @@ public function hookdisplayProductButtons() * @param array $params Hook parameters */ public function hookDisplayFooter($params) - { - $this->context->controller->addJs($this->_path.'views/js/callmeback.js'); + { + if (isset(Context::getContext()->controller->php_self) && Context::getContext()->controller->php_self == 'product') { + $this->context->controller->addJs($this->_path.'views/js/callmeback.js'); + $this->context->controller->addJs($this->_path.'views/js/intlTelInput.min.js'); + $this->context->controller->addCss($this->_path.'views/css/intlTelInput.min.css'); + $this->context->controller->addCss($this->_path.'views/css/style.css'); + } + } /** @@ -398,11 +437,11 @@ public function processConfiguration() public function getConfiguration() { $configs = array(); - $configs[self::SURNAME] = Configuration::get(self::SURNAME); - $configs[self::EMAIL] = Configuration::get(self::EMAIL); - $configs[self::TELEPHONE2] = Configuration::get(self::TELEPHONE2); - $configs[self::MESSAGE] = Configuration::get(self::MESSAGE); - $configs[self::HOURS] = Configuration::get(self::HOURS); + $configs[strtolower(self::SURNAME)] = Configuration::get(self::SURNAME); + $configs[strtolower(self::EMAIL)] = Configuration::get(self::EMAIL); + $configs[strtolower(self::TELEPHONE2)] = Configuration::get(self::TELEPHONE2); + $configs[strtolower(self::MESSAGE)] = Configuration::get(self::MESSAGE); + $configs[strtolower(self::HOURS)] = Configuration::get(self::HOURS); return $configs; } @@ -443,4 +482,109 @@ public function getTranslatedAjaxMessages() 'form_error_telephone' => $this->l('Telephone is not correct, it should be 10 digits.'), ); } + + /** + * Get country information by IP address. + * + * @param string Current user IP + * @param string Specific data we went returned + * @param string (Optional) Deep detect + * @return string|array Returns data based on purpose|Returns all information if purpose is 'Location' + */ + public function getIPInfo($ip = NULL, $purpose = "location", $deep_detect = TRUE) { + $output = NULL; + if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) { + $ip = $_SERVER["REMOTE_ADDR"]; + if ($deep_detect) { + if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) + $ip = $_SERVER['HTTP_CLIENT_IP']; + } + } + $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose))); + $support = array("country", "countrycode", "state", "region", "city", "location", "address"); + $continents = array( + "AF" => "Africa", + "AN" => "Antarctica", + "AS" => "Asia", + "EU" => "Europe", + "OC" => "Australia (Oceania)", + "NA" => "North America", + "SA" => "South America" + ); + if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) { + $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip)); + if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) { + switch ($purpose) { + case "location": + $output = array( + "city" => @$ipdat->geoplugin_city, + "state" => @$ipdat->geoplugin_regionName, + "country" => @$ipdat->geoplugin_countryName, + "country_code" => @$ipdat->geoplugin_countryCode, + "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)], + "continent_code" => @$ipdat->geoplugin_continentCode + ); + break; + case "address": + $address = array($ipdat->geoplugin_countryName); + if (@strlen($ipdat->geoplugin_regionName) >= 1) + $address[] = $ipdat->geoplugin_regionName; + if (@strlen($ipdat->geoplugin_city) >= 1) + $address[] = $ipdat->geoplugin_city; + $output = implode(", ", array_reverse($address)); + break; + case "city": + $output = @$ipdat->geoplugin_city; + break; + case "state": + $output = @$ipdat->geoplugin_regionName; + break; + case "region": + $output = @$ipdat->geoplugin_regionName; + break; + case "country": + $output = @$ipdat->geoplugin_countryName; + break; + case "countrycode": + $output = @$ipdat->geoplugin_countryCode; + break; + } + } + } + return $output; + } + + /** + * Get country information by IP address. + * + * @return string Current user IP. + */ + public function getUserIP() + { + // Get real visitor IP behind CloudFlare network + if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) { + $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"]; + $_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"]; + } + $client = @$_SERVER['HTTP_CLIENT_IP']; + $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; + $remote = $_SERVER['REMOTE_ADDR']; + + if(filter_var($client, FILTER_VALIDATE_IP)) + { + $ip = $client; + } + elseif(filter_var($forward, FILTER_VALIDATE_IP)) + { + $ip = $forward; + } + else + { + $ip = $remote; + } + + return $ip; + } } diff --git a/controllers/admin/AdminCallMeBackController.php b/controllers/admin/AdminCallMeBackController.php index 29abb85..b4682e6 100755 --- a/controllers/admin/AdminCallMeBackController.php +++ b/controllers/admin/AdminCallMeBackController.php @@ -21,6 +21,7 @@ public function __construct() $this->bootstrap = true; $this->table = 'callmeback'; $this->className = 'callmeback'; + $this->identifier = 'id'; $this->list_no_link = true; $this->fields_list = array( 'id' => array( @@ -85,10 +86,10 @@ public function __construct() ), 'called' => array( 'title' => $this->l('Called'), + 'active' => 'toggleCalled', 'align' => 'text-center', 'havingFilter' => true, - 'filter_key' => 'a!called', - 'callback' => 'calledStatus', + 'type' => 'bool', 'class' => 'calledStatus', ), ); @@ -101,39 +102,38 @@ public function __construct() $this->_select = 't.name as `product_name`'; $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_lang` t ON (a.`id_product` = t.`id_product`)'; - $this->_where = 'and t.`id_lang` = '.$this->context->language->id; + $this->_where = 'AND t.`id_lang` = '.$this->context->language->id.' AND t.`id_shop`=a.`id_shop`'; $this->_orderBy = 'date_add'; $this->_orderWay = 'DESC'; } /** - * @param int $idCallMeBack - * @param string $tr - * @return mixed + * Implements postProcess() */ - public function calledStatus($idCallMeBack, $tr) + public function postProcess() { - $tpl = $this->context->smarty->createTemplate(_PS_MODULE_DIR_.'/callmeback/views/templates/admin/check-called.tpl'); - $tpl->assign( - array( - 'id_callmeback' => $tr['id'], - 'called' => $tr['called'], - ) - ); - - return $tpl->fetch(); + + if (Tools::getIsset('toggleCalled'.$this->table)) { + $this->toggleArchived(); + } + parent::postProcess(); } /** - * Load JS and CSS + * Helper function that updates Called status of row. */ - public function setMedia() - { - // We call the parent method - parent::setMedia(); - // Save the module path in a variable - $this->path = __PS_BASE_URI__.'modules/callmeback/'; - // Include the module CSS and JS files needed - $this->context->controller->addJS($this->path.'views/js/callmeback-admin.js'); + public function toggleArchived() + { + $id = Tools::getValue('id'); + $query = "SELECT `called` FROM " . _DB_PREFIX_ . "callmeback WHERE `id`=" . $id; + $is_called = Db::getInstance()->getValue($query); + + // Check called value and change it. + $is_called == 0 ? $data = array('called' => 1) : $data = array('called' => 0); + + $where = '`id`=' . $id; + Db::getInstance()->update('callmeback', $data, $where); + Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token); } + } diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 443a9b3..af3e0bc 100644 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -52,13 +52,13 @@ public function initContent() $inputErrors[] = $translatedFormessages['form_error_email']; } - if (!$telephone1) { - $inputErrors[] = $translatedFormessages['form_error_telephone_field']; - } elseif (!is_numeric($telephone1)) { - $inputErrors[] = $translatedFormessages['form_error_telephone']; - } elseif (strlen($telephone1) != 10) { - $inputErrors[] = $translatedFormessages['form_error_telephone']; - } + // if (!$telephone1) { + // $inputErrors[] = $translatedFormessages['form_error_telephone_field']; + // } elseif (!is_numeric($telephone1)) { + // $inputErrors[] = $translatedFormessages['form_error_telephone']; + // } elseif (strlen($telephone1) != 10) { + // $inputErrors[] = $translatedFormessages['form_error_telephone']; + // } if (empty($inputErrors)) { if ($token === $systemToken) { diff --git a/views/css/intlTelInput.min.css b/views/css/intlTelInput.min.css new file mode 100644 index 0000000..4deb52b --- /dev/null +++ b/views/css/intlTelInput.min.css @@ -0,0 +1 @@ +.iti{position:relative;display:inline-block}.iti *{box-sizing:border-box;-moz-box-sizing:border-box}.iti__hide{display:none}.iti__v-hide{visibility:hidden}.iti input,.iti input[type=tel],.iti input[type=text]{position:relative;z-index:0;margin-top:0!important;margin-bottom:0!important;padding-right:36px;margin-right:0}.iti__flag-container{position:absolute;top:0;bottom:0;right:0;padding:1px}.iti__selected-flag{z-index:1;position:relative;display:flex;align-items:center;height:100%;padding:0 6px 0 8px}.iti__arrow{margin-left:6px;width:0;height:0;border-left:3px solid transparent;border-right:3px solid transparent;border-top:4px solid #555}.iti__arrow--up{border-top:none;border-bottom:4px solid #555}.iti__country-list{position:absolute;z-index:2;list-style:none;text-align:left;padding:0;margin:0 0 0 -1px;box-shadow:1px 1px 4px rgba(0,0,0,.2);background-color:#fff;border:1px solid #ccc;white-space:nowrap;max-height:200px;overflow-y:scroll;-webkit-overflow-scrolling:touch}.iti__country-list--dropup{bottom:100%;margin-bottom:-1px}@media (max-width:500px){.iti__country-list{white-space:normal}}.iti__flag-box{display:inline-block;width:20px}.iti__divider{padding-bottom:5px;margin-bottom:5px;border-bottom:1px solid #ccc}.iti__country{padding:5px 10px;outline:0}.iti__dial-code{color:#999}.iti__country.iti__highlight{background-color:rgba(0,0,0,.05)}.iti__country-name,.iti__dial-code,.iti__flag-box{vertical-align:middle}.iti__country-name,.iti__flag-box{margin-right:6px}.iti--allow-dropdown input,.iti--allow-dropdown input[type=tel],.iti--allow-dropdown input[type=text],.iti--separate-dial-code input,.iti--separate-dial-code input[type=tel],.iti--separate-dial-code input[type=text]{padding-right:6px;padding-left:52px;margin-left:0}.iti--allow-dropdown .iti__flag-container,.iti--separate-dial-code .iti__flag-container{right:auto;left:0}.iti--allow-dropdown .iti__flag-container:hover{cursor:pointer}.iti--allow-dropdown .iti__flag-container:hover .iti__selected-flag{background-color:rgba(0,0,0,.05)}.iti--allow-dropdown input[disabled]+.iti__flag-container:hover,.iti--allow-dropdown input[readonly]+.iti__flag-container:hover{cursor:default}.iti--allow-dropdown input[disabled]+.iti__flag-container:hover .iti__selected-flag,.iti--allow-dropdown input[readonly]+.iti__flag-container:hover .iti__selected-flag{background-color:transparent}.iti--separate-dial-code .iti__selected-flag{background-color:rgba(0,0,0,.05)}.iti--separate-dial-code .iti__selected-dial-code{margin-left:6px}.iti--container{position:absolute;top:-1000px;left:-1000px;z-index:1060;padding:1px}.iti--container:hover{cursor:pointer}.iti-mobile .iti--container{top:30px;bottom:30px;left:30px;right:30px;position:fixed}.iti-mobile .iti__country-list{max-height:100%;width:100%}.iti-mobile .iti__country{padding:10px 10px;line-height:1.5em}.iti__flag{width:20px}.iti__flag.iti__be{width:18px}.iti__flag.iti__ch{width:15px}.iti__flag.iti__mc{width:19px}.iti__flag.iti__ne{width:18px}.iti__flag.iti__np{width:13px}.iti__flag.iti__va{width:15px}@media (-webkit-min-device-pixel-ratio:2),(min-resolution:192dpi){.iti__flag{background-size:5652px 15px}}.iti__flag.iti__ac{height:10px;background-position:0 0}.iti__flag.iti__ad{height:14px;background-position:-22px 0}.iti__flag.iti__ae{height:10px;background-position:-44px 0}.iti__flag.iti__af{height:14px;background-position:-66px 0}.iti__flag.iti__ag{height:14px;background-position:-88px 0}.iti__flag.iti__ai{height:10px;background-position:-110px 0}.iti__flag.iti__al{height:15px;background-position:-132px 0}.iti__flag.iti__am{height:10px;background-position:-154px 0}.iti__flag.iti__ao{height:14px;background-position:-176px 0}.iti__flag.iti__aq{height:14px;background-position:-198px 0}.iti__flag.iti__ar{height:13px;background-position:-220px 0}.iti__flag.iti__as{height:10px;background-position:-242px 0}.iti__flag.iti__at{height:14px;background-position:-264px 0}.iti__flag.iti__au{height:10px;background-position:-286px 0}.iti__flag.iti__aw{height:14px;background-position:-308px 0}.iti__flag.iti__ax{height:13px;background-position:-330px 0}.iti__flag.iti__az{height:10px;background-position:-352px 0}.iti__flag.iti__ba{height:10px;background-position:-374px 0}.iti__flag.iti__bb{height:14px;background-position:-396px 0}.iti__flag.iti__bd{height:12px;background-position:-418px 0}.iti__flag.iti__be{height:15px;background-position:-440px 0}.iti__flag.iti__bf{height:14px;background-position:-460px 0}.iti__flag.iti__bg{height:12px;background-position:-482px 0}.iti__flag.iti__bh{height:12px;background-position:-504px 0}.iti__flag.iti__bi{height:12px;background-position:-526px 0}.iti__flag.iti__bj{height:14px;background-position:-548px 0}.iti__flag.iti__bl{height:14px;background-position:-570px 0}.iti__flag.iti__bm{height:10px;background-position:-592px 0}.iti__flag.iti__bn{height:10px;background-position:-614px 0}.iti__flag.iti__bo{height:14px;background-position:-636px 0}.iti__flag.iti__bq{height:14px;background-position:-658px 0}.iti__flag.iti__br{height:14px;background-position:-680px 0}.iti__flag.iti__bs{height:10px;background-position:-702px 0}.iti__flag.iti__bt{height:14px;background-position:-724px 0}.iti__flag.iti__bv{height:15px;background-position:-746px 0}.iti__flag.iti__bw{height:14px;background-position:-768px 0}.iti__flag.iti__by{height:10px;background-position:-790px 0}.iti__flag.iti__bz{height:14px;background-position:-812px 0}.iti__flag.iti__ca{height:10px;background-position:-834px 0}.iti__flag.iti__cc{height:10px;background-position:-856px 0}.iti__flag.iti__cd{height:15px;background-position:-878px 0}.iti__flag.iti__cf{height:14px;background-position:-900px 0}.iti__flag.iti__cg{height:14px;background-position:-922px 0}.iti__flag.iti__ch{height:15px;background-position:-944px 0}.iti__flag.iti__ci{height:14px;background-position:-961px 0}.iti__flag.iti__ck{height:10px;background-position:-983px 0}.iti__flag.iti__cl{height:14px;background-position:-1005px 0}.iti__flag.iti__cm{height:14px;background-position:-1027px 0}.iti__flag.iti__cn{height:14px;background-position:-1049px 0}.iti__flag.iti__co{height:14px;background-position:-1071px 0}.iti__flag.iti__cp{height:14px;background-position:-1093px 0}.iti__flag.iti__cr{height:12px;background-position:-1115px 0}.iti__flag.iti__cu{height:10px;background-position:-1137px 0}.iti__flag.iti__cv{height:12px;background-position:-1159px 0}.iti__flag.iti__cw{height:14px;background-position:-1181px 0}.iti__flag.iti__cx{height:10px;background-position:-1203px 0}.iti__flag.iti__cy{height:14px;background-position:-1225px 0}.iti__flag.iti__cz{height:14px;background-position:-1247px 0}.iti__flag.iti__de{height:12px;background-position:-1269px 0}.iti__flag.iti__dg{height:10px;background-position:-1291px 0}.iti__flag.iti__dj{height:14px;background-position:-1313px 0}.iti__flag.iti__dk{height:15px;background-position:-1335px 0}.iti__flag.iti__dm{height:10px;background-position:-1357px 0}.iti__flag.iti__do{height:14px;background-position:-1379px 0}.iti__flag.iti__dz{height:14px;background-position:-1401px 0}.iti__flag.iti__ea{height:14px;background-position:-1423px 0}.iti__flag.iti__ec{height:14px;background-position:-1445px 0}.iti__flag.iti__ee{height:13px;background-position:-1467px 0}.iti__flag.iti__eg{height:14px;background-position:-1489px 0}.iti__flag.iti__eh{height:10px;background-position:-1511px 0}.iti__flag.iti__er{height:10px;background-position:-1533px 0}.iti__flag.iti__es{height:14px;background-position:-1555px 0}.iti__flag.iti__et{height:10px;background-position:-1577px 0}.iti__flag.iti__eu{height:14px;background-position:-1599px 0}.iti__flag.iti__fi{height:12px;background-position:-1621px 0}.iti__flag.iti__fj{height:10px;background-position:-1643px 0}.iti__flag.iti__fk{height:10px;background-position:-1665px 0}.iti__flag.iti__fm{height:11px;background-position:-1687px 0}.iti__flag.iti__fo{height:15px;background-position:-1709px 0}.iti__flag.iti__fr{height:14px;background-position:-1731px 0}.iti__flag.iti__ga{height:15px;background-position:-1753px 0}.iti__flag.iti__gb{height:10px;background-position:-1775px 0}.iti__flag.iti__gd{height:12px;background-position:-1797px 0}.iti__flag.iti__ge{height:14px;background-position:-1819px 0}.iti__flag.iti__gf{height:14px;background-position:-1841px 0}.iti__flag.iti__gg{height:14px;background-position:-1863px 0}.iti__flag.iti__gh{height:14px;background-position:-1885px 0}.iti__flag.iti__gi{height:10px;background-position:-1907px 0}.iti__flag.iti__gl{height:14px;background-position:-1929px 0}.iti__flag.iti__gm{height:14px;background-position:-1951px 0}.iti__flag.iti__gn{height:14px;background-position:-1973px 0}.iti__flag.iti__gp{height:14px;background-position:-1995px 0}.iti__flag.iti__gq{height:14px;background-position:-2017px 0}.iti__flag.iti__gr{height:14px;background-position:-2039px 0}.iti__flag.iti__gs{height:10px;background-position:-2061px 0}.iti__flag.iti__gt{height:13px;background-position:-2083px 0}.iti__flag.iti__gu{height:11px;background-position:-2105px 0}.iti__flag.iti__gw{height:10px;background-position:-2127px 0}.iti__flag.iti__gy{height:12px;background-position:-2149px 0}.iti__flag.iti__hk{height:14px;background-position:-2171px 0}.iti__flag.iti__hm{height:10px;background-position:-2193px 0}.iti__flag.iti__hn{height:10px;background-position:-2215px 0}.iti__flag.iti__hr{height:10px;background-position:-2237px 0}.iti__flag.iti__ht{height:12px;background-position:-2259px 0}.iti__flag.iti__hu{height:10px;background-position:-2281px 0}.iti__flag.iti__ic{height:14px;background-position:-2303px 0}.iti__flag.iti__id{height:14px;background-position:-2325px 0}.iti__flag.iti__ie{height:10px;background-position:-2347px 0}.iti__flag.iti__il{height:15px;background-position:-2369px 0}.iti__flag.iti__im{height:10px;background-position:-2391px 0}.iti__flag.iti__in{height:14px;background-position:-2413px 0}.iti__flag.iti__io{height:10px;background-position:-2435px 0}.iti__flag.iti__iq{height:14px;background-position:-2457px 0}.iti__flag.iti__ir{height:12px;background-position:-2479px 0}.iti__flag.iti__is{height:15px;background-position:-2501px 0}.iti__flag.iti__it{height:14px;background-position:-2523px 0}.iti__flag.iti__je{height:12px;background-position:-2545px 0}.iti__flag.iti__jm{height:10px;background-position:-2567px 0}.iti__flag.iti__jo{height:10px;background-position:-2589px 0}.iti__flag.iti__jp{height:14px;background-position:-2611px 0}.iti__flag.iti__ke{height:14px;background-position:-2633px 0}.iti__flag.iti__kg{height:12px;background-position:-2655px 0}.iti__flag.iti__kh{height:13px;background-position:-2677px 0}.iti__flag.iti__ki{height:10px;background-position:-2699px 0}.iti__flag.iti__km{height:12px;background-position:-2721px 0}.iti__flag.iti__kn{height:14px;background-position:-2743px 0}.iti__flag.iti__kp{height:10px;background-position:-2765px 0}.iti__flag.iti__kr{height:14px;background-position:-2787px 0}.iti__flag.iti__kw{height:10px;background-position:-2809px 0}.iti__flag.iti__ky{height:10px;background-position:-2831px 0}.iti__flag.iti__kz{height:10px;background-position:-2853px 0}.iti__flag.iti__la{height:14px;background-position:-2875px 0}.iti__flag.iti__lb{height:14px;background-position:-2897px 0}.iti__flag.iti__lc{height:10px;background-position:-2919px 0}.iti__flag.iti__li{height:12px;background-position:-2941px 0}.iti__flag.iti__lk{height:10px;background-position:-2963px 0}.iti__flag.iti__lr{height:11px;background-position:-2985px 0}.iti__flag.iti__ls{height:14px;background-position:-3007px 0}.iti__flag.iti__lt{height:12px;background-position:-3029px 0}.iti__flag.iti__lu{height:12px;background-position:-3051px 0}.iti__flag.iti__lv{height:10px;background-position:-3073px 0}.iti__flag.iti__ly{height:10px;background-position:-3095px 0}.iti__flag.iti__ma{height:14px;background-position:-3117px 0}.iti__flag.iti__mc{height:15px;background-position:-3139px 0}.iti__flag.iti__md{height:10px;background-position:-3160px 0}.iti__flag.iti__me{height:10px;background-position:-3182px 0}.iti__flag.iti__mf{height:14px;background-position:-3204px 0}.iti__flag.iti__mg{height:14px;background-position:-3226px 0}.iti__flag.iti__mh{height:11px;background-position:-3248px 0}.iti__flag.iti__mk{height:10px;background-position:-3270px 0}.iti__flag.iti__ml{height:14px;background-position:-3292px 0}.iti__flag.iti__mm{height:14px;background-position:-3314px 0}.iti__flag.iti__mn{height:10px;background-position:-3336px 0}.iti__flag.iti__mo{height:14px;background-position:-3358px 0}.iti__flag.iti__mp{height:10px;background-position:-3380px 0}.iti__flag.iti__mq{height:14px;background-position:-3402px 0}.iti__flag.iti__mr{height:14px;background-position:-3424px 0}.iti__flag.iti__ms{height:10px;background-position:-3446px 0}.iti__flag.iti__mt{height:14px;background-position:-3468px 0}.iti__flag.iti__mu{height:14px;background-position:-3490px 0}.iti__flag.iti__mv{height:14px;background-position:-3512px 0}.iti__flag.iti__mw{height:14px;background-position:-3534px 0}.iti__flag.iti__mx{height:12px;background-position:-3556px 0}.iti__flag.iti__my{height:10px;background-position:-3578px 0}.iti__flag.iti__mz{height:14px;background-position:-3600px 0}.iti__flag.iti__na{height:14px;background-position:-3622px 0}.iti__flag.iti__nc{height:10px;background-position:-3644px 0}.iti__flag.iti__ne{height:15px;background-position:-3666px 0}.iti__flag.iti__nf{height:10px;background-position:-3686px 0}.iti__flag.iti__ng{height:10px;background-position:-3708px 0}.iti__flag.iti__ni{height:12px;background-position:-3730px 0}.iti__flag.iti__nl{height:14px;background-position:-3752px 0}.iti__flag.iti__no{height:15px;background-position:-3774px 0}.iti__flag.iti__np{height:15px;background-position:-3796px 0}.iti__flag.iti__nr{height:10px;background-position:-3811px 0}.iti__flag.iti__nu{height:10px;background-position:-3833px 0}.iti__flag.iti__nz{height:10px;background-position:-3855px 0}.iti__flag.iti__om{height:10px;background-position:-3877px 0}.iti__flag.iti__pa{height:14px;background-position:-3899px 0}.iti__flag.iti__pe{height:14px;background-position:-3921px 0}.iti__flag.iti__pf{height:14px;background-position:-3943px 0}.iti__flag.iti__pg{height:15px;background-position:-3965px 0}.iti__flag.iti__ph{height:10px;background-position:-3987px 0}.iti__flag.iti__pk{height:14px;background-position:-4009px 0}.iti__flag.iti__pl{height:13px;background-position:-4031px 0}.iti__flag.iti__pm{height:14px;background-position:-4053px 0}.iti__flag.iti__pn{height:10px;background-position:-4075px 0}.iti__flag.iti__pr{height:14px;background-position:-4097px 0}.iti__flag.iti__ps{height:10px;background-position:-4119px 0}.iti__flag.iti__pt{height:14px;background-position:-4141px 0}.iti__flag.iti__pw{height:13px;background-position:-4163px 0}.iti__flag.iti__py{height:11px;background-position:-4185px 0}.iti__flag.iti__qa{height:8px;background-position:-4207px 0}.iti__flag.iti__re{height:14px;background-position:-4229px 0}.iti__flag.iti__ro{height:14px;background-position:-4251px 0}.iti__flag.iti__rs{height:14px;background-position:-4273px 0}.iti__flag.iti__ru{height:14px;background-position:-4295px 0}.iti__flag.iti__rw{height:14px;background-position:-4317px 0}.iti__flag.iti__sa{height:14px;background-position:-4339px 0}.iti__flag.iti__sb{height:10px;background-position:-4361px 0}.iti__flag.iti__sc{height:10px;background-position:-4383px 0}.iti__flag.iti__sd{height:10px;background-position:-4405px 0}.iti__flag.iti__se{height:13px;background-position:-4427px 0}.iti__flag.iti__sg{height:14px;background-position:-4449px 0}.iti__flag.iti__sh{height:10px;background-position:-4471px 0}.iti__flag.iti__si{height:10px;background-position:-4493px 0}.iti__flag.iti__sj{height:15px;background-position:-4515px 0}.iti__flag.iti__sk{height:14px;background-position:-4537px 0}.iti__flag.iti__sl{height:14px;background-position:-4559px 0}.iti__flag.iti__sm{height:15px;background-position:-4581px 0}.iti__flag.iti__sn{height:14px;background-position:-4603px 0}.iti__flag.iti__so{height:14px;background-position:-4625px 0}.iti__flag.iti__sr{height:14px;background-position:-4647px 0}.iti__flag.iti__ss{height:10px;background-position:-4669px 0}.iti__flag.iti__st{height:10px;background-position:-4691px 0}.iti__flag.iti__sv{height:12px;background-position:-4713px 0}.iti__flag.iti__sx{height:14px;background-position:-4735px 0}.iti__flag.iti__sy{height:14px;background-position:-4757px 0}.iti__flag.iti__sz{height:14px;background-position:-4779px 0}.iti__flag.iti__ta{height:10px;background-position:-4801px 0}.iti__flag.iti__tc{height:10px;background-position:-4823px 0}.iti__flag.iti__td{height:14px;background-position:-4845px 0}.iti__flag.iti__tf{height:14px;background-position:-4867px 0}.iti__flag.iti__tg{height:13px;background-position:-4889px 0}.iti__flag.iti__th{height:14px;background-position:-4911px 0}.iti__flag.iti__tj{height:10px;background-position:-4933px 0}.iti__flag.iti__tk{height:10px;background-position:-4955px 0}.iti__flag.iti__tl{height:10px;background-position:-4977px 0}.iti__flag.iti__tm{height:14px;background-position:-4999px 0}.iti__flag.iti__tn{height:14px;background-position:-5021px 0}.iti__flag.iti__to{height:10px;background-position:-5043px 0}.iti__flag.iti__tr{height:14px;background-position:-5065px 0}.iti__flag.iti__tt{height:12px;background-position:-5087px 0}.iti__flag.iti__tv{height:10px;background-position:-5109px 0}.iti__flag.iti__tw{height:14px;background-position:-5131px 0}.iti__flag.iti__tz{height:14px;background-position:-5153px 0}.iti__flag.iti__ua{height:14px;background-position:-5175px 0}.iti__flag.iti__ug{height:14px;background-position:-5197px 0}.iti__flag.iti__um{height:11px;background-position:-5219px 0}.iti__flag.iti__un{height:14px;background-position:-5241px 0}.iti__flag.iti__us{height:11px;background-position:-5263px 0}.iti__flag.iti__uy{height:14px;background-position:-5285px 0}.iti__flag.iti__uz{height:10px;background-position:-5307px 0}.iti__flag.iti__va{height:15px;background-position:-5329px 0}.iti__flag.iti__vc{height:14px;background-position:-5346px 0}.iti__flag.iti__ve{height:14px;background-position:-5368px 0}.iti__flag.iti__vg{height:10px;background-position:-5390px 0}.iti__flag.iti__vi{height:14px;background-position:-5412px 0}.iti__flag.iti__vn{height:14px;background-position:-5434px 0}.iti__flag.iti__vu{height:12px;background-position:-5456px 0}.iti__flag.iti__wf{height:14px;background-position:-5478px 0}.iti__flag.iti__ws{height:10px;background-position:-5500px 0}.iti__flag.iti__xk{height:15px;background-position:-5522px 0}.iti__flag.iti__ye{height:14px;background-position:-5544px 0}.iti__flag.iti__yt{height:14px;background-position:-5566px 0}.iti__flag.iti__za{height:14px;background-position:-5588px 0}.iti__flag.iti__zm{height:14px;background-position:-5610px 0}.iti__flag.iti__zw{height:10px;background-position:-5632px 0}.iti__flag{height:15px;box-shadow:0 0 1px 0 #888;background-image:url(../img/flags.png);background-repeat:no-repeat;background-color:#dbdbdb;background-position:20px 0}@media (-webkit-min-device-pixel-ratio:2),(min-resolution:192dpi){.iti__flag{background-image:url(../img/flags@2x.png)}}.iti__flag.iti__np{background-color:transparent} \ No newline at end of file diff --git a/views/css/style.css b/views/css/style.css new file mode 100644 index 0000000..87db96c --- /dev/null +++ b/views/css/style.css @@ -0,0 +1,19 @@ +#callmeback { + margin: 0 auto; + display: block; + margin-bottom: 15px; +} + +#callmeback-form { + padding: 0 20px 20px; +} + +#callmeback-form #callmeback_telephone.error, +#callmeback-form #callmeback_telephone2.error { + border: 1px solid crimson; +} + +#callmeback-form #error-msg { + padding-top: 7px; + color: crimson; +} \ No newline at end of file diff --git a/views/img/flags.png b/views/img/flags.png new file mode 100644 index 0000000..3fa1bec Binary files /dev/null and b/views/img/flags.png differ diff --git a/views/img/flags@2x.png b/views/img/flags@2x.png new file mode 100644 index 0000000..7cc3ed3 Binary files /dev/null and b/views/img/flags@2x.png differ diff --git a/views/js/callmeback-admin.js b/views/js/callmeback-admin.js deleted file mode 100755 index 1754da0..0000000 --- a/views/js/callmeback-admin.js +++ /dev/null @@ -1,37 +0,0 @@ -/* -* @author Sarafoudis Nikolaos for 01generator.com -* @license MIT License -*/ - -var baseUrl = document.location.origin; - -$( document ).ready(function() { - $('.calledStatus').each(function(){ - $(this).find('.checkbox-called').on('click', function (){ - // event.preventDefault(); - var callid = $(this).data('callid'); - var call_checked = $(this).prop('checked'); - if (call_checked == 0) { - call_checked = 'false'; - } else { - call_checked = 'true'; - } - $.ajax({ - url: callmeback_ajax, - type: 'POST', - data: 'method=updateCalled&callid=' + callid + '&callchecked=' + call_checked, - dataType: 'json', - success: function(data) { - console.log(data); - // if (data['callupdated']){ - - // } - // OTHER SUCCESS COMMAND - CHECK THE RETURN VALUE - }, - error: function(XMLHttpRequest, textStatus, errorThrown) { - console.log(XMLHttpRequest); - } - }); - }); - }); -}); \ No newline at end of file diff --git a/views/js/callmeback.js b/views/js/callmeback.js index 84a7f2b..ece06b9 100755 --- a/views/js/callmeback.js +++ b/views/js/callmeback.js @@ -4,6 +4,24 @@ */ $(document).ready(function () { + var tel1 = document.querySelector("#callmeback_telephone"); + var iti1 = intlTelInput(tel1, { + separateDialCode : true, + preferredCountries : prefered_countries, + utilsScript : dir + 'utils.js' + }); + iti1.setCountry(current_country_iso_code); + + if ($("#callmeback_telephone2").length) { + var tel2 = document.querySelector("#callmeback_telephone2"); + var iti2 = intlTelInput(tel2, { + separateDialCode : true, + preferredCountries : prefered_countries, + utilsScript : dir + 'utils.js' + }); + iti2.setCountry(current_country_iso_code); + } + $('#callmeback').on('click', function () { event.preventDefault(); $('#callmeback-form-msg-ok').hide(); @@ -11,105 +29,131 @@ $(document).ready(function () { $('#callmeback-form').toggle('slow'); }); + $('#callmeback_telephone, #callmeback_telephone2').on('focus', function () { + $('#callmeback_telephone').removeClass('error'); + $('#callmeback_telephone2').removeClass('error'); + }); + $('#callmeback-submit').on('click', function () { event.preventDefault(); - var product_id = $('#product_page_product_id').val(); - var callmeback_name = $('#callmeback_name').val(); - var callmeback_telephone = $('#callmeback_telephone').val(); - var form_errors = []; - // Surname - if ($("#callmeback_surname").length) { - var callmeback_surname = $('#callmeback_surname').val(); - } else { - var callmeback_surname = ''; - } - // Email - if ($("#callmeback_email").length) { - var callmeback_email = $('#callmeback_email').val(); - } else { - var callmeback_email = ''; - } - // Tele 2 - if ($("#callmeback_telephone2").length) { - var callmeback_telephone2 = $('#callmeback_telephone2').val(); - } else { - var callmeback_telephone2 = ''; - } - // Hours from - if ($("#callmeback_hours_from").length) { - var callmeback_hours_from = $('#callmeback_hours_from').val(); - } else { - var callmeback_hours_from = ''; - } - // Hours to - if ($("#callmeback_hours_to").length) { - var callmeback_hours_to = $('#callmeback_hours_to').val(); - } else { - var callmeback_hours_to = ''; + var errorMap = ["Invalid number", "Invalid country code", "Too short", "Too long", "Invalid number"]; + var errorMsg = document.querySelector("#error-msg"); + + console.log($.trim(iti2)); + + console.log($('#callmeback_telephone2')); + if (typeof iti1 != 'undefined' && !iti1.isValidNumber()) { + $('#callmeback_telephone').addClass('error'); + var errorCode = iti1.getValidationError(); + errorMsg.innerHTML = errorMap[errorCode]; + $(errorMsg).removeClass('hide'); } - // Message - if ($("#callmeback_msg").length) { - var callmeback_msg = $('#callmeback_msg').val(); - } else { - var callmeback_msg = ''; + else if (typeof iti2 != 'undefined' && $('#callmeback_telephone2').val().trim() != '' && !iti2.isValidNumber()) { + $('#callmeback_telephone2').addClass('error'); + var errorCode = iti2.getValidationError(); + errorMsg.innerHTML = errorMap[errorCode]; + $(errorMsg).removeClass('hide'); } - console.log('method=callmebackSubmit&ajax=true' - + '&product_id=' + product_id - + '&token=' + static_token - + '&callmeback_name=' + callmeback_name - + '&callmeback_telephone=' + callmeback_telephone - + '&callmeback_surname=' + callmeback_surname - + '&callmeback_email=' + callmeback_email - + '&callmeback_telephone2=' + callmeback_telephone2 - + '&callmeback_hours_from=' + callmeback_hours_from - + '&callmeback_hours_to=' + callmeback_hours_to - + '&callmeback_msg=' + callmeback_msg); - // (typeof callmeback_surname !== 'undefined')? : ; - $.ajax({ - url: callmeback_ajax, - type: 'POST', - data: 'method=callmebackSubmit&ajax=true' - + '&product_id=' + product_id - + '&token=' + static_token - + '&callmeback_name=' + callmeback_name - + '&callmeback_telephone=' + callmeback_telephone - + '&callmeback_surname=' + callmeback_surname - + '&callmeback_email=' + callmeback_email - + '&callmeback_telephone2=' + callmeback_telephone2 - + '&callmeback_hours_from=' + callmeback_hours_from - + '&callmeback_hours_to=' + callmeback_hours_to - + '&callmeback_msg=' + callmeback_msg, - dataType: 'json', - success: function (data) { - if (data['callmeback_call']) { - // data['callmeback_call_html'] - // $('#callmeback-form-msg').html(data['callmeback_call_html']); - $('#callmeback-form').toggle('slow'); - $('#callmeback-form-msg-alert').hide(); - $('#callmeback-form-msg-ok').toggle('fast'); - $('#callmeback-form-msg').toggle('slow'); - } else { - var alert_message = ''; - if (data['callmeback_call_html'] == 'sql_error') { - alert_message = data['sql_error_msg']; - } else if (data['callmeback_call_html'] == 'ajax_error') { - alert_message = data['ajax_error_msg']; - } else if (data['callmeback_call_html'] == 'form_error') { - alert_message = ''; - console.log(alert_message); + $('#callmeback-form').toggle('slow'); + $('#callmeback-form-msg-alert').html(alert_message); + $('#callmeback-form-msg-ok').hide(); + $('#callmeback-form-msg-alert').show(); + $('#callmeback-form-msg').show('slow'); } - $('#callmeback-form').toggle('slow'); - $('#callmeback-form-msg-alert').html(alert_message); - $('#callmeback-form-msg-ok').hide(); - $('#callmeback-form-msg-alert').show(); - $('#callmeback-form-msg').show('slow'); + // OTHER SUCCESS COMMAND - CHECK THE RETURN VALUE } - // OTHER SUCCESS COMMAND - CHECK THE RETURN VALUE - } - }); + }); + } }); }); \ No newline at end of file diff --git a/views/js/intlTelInput.min.js b/views/js/intlTelInput.min.js new file mode 100644 index 0000000..46c2b55 --- /dev/null +++ b/views/js/intlTelInput.min.js @@ -0,0 +1,8 @@ +/* + * International Telephone Input v16.0.0 + * https://github.com/jackocnr/intl-tel-input.git + * Licensed under the MIT license + */ + +!function(a){var b=function(a,b,c){"use strict";return function(){function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function e(a,b){for(var c=0;cthis.dialCodeMaxLen&&(this.dialCodeMaxLen=b.length),this.q.hasOwnProperty(b)||(this.q[b]=[]);for(var e=0;e-1})}else if(this.d.excludeCountries.length){var b=this.d.excludeCountries.map(function(a){return a.toLowerCase()});this.p=g.filter(function(a){return-1===b.indexOf(a.iso2)})}else this.p=g}},{key:"_d0",value:function(){for(var a=0;a"),c+="
"),c+="".concat(e.name,""),c+="+".concat(e.dialCode,""),c+=""}this.m.insertAdjacentHTML("beforeend",c)}},{key:"_h",value:function(){var a=this.a.value,b=this._5(a),c=this._w(a),d=this.d,e=d.initialCountry,f=d.nationalMode,g=d.autoHideDialCode,h=d.separateDialCode;b&&!c?this._v(a):"auto"!==e&&(e?this._z(e.toLowerCase()):b&&c?this._z("us"):(this.j=this.preferredCountries.length?this.preferredCountries[0].iso2:this.p[0].iso2,a||this._z(this.j)),a||f||g||h||(this.a.value="+".concat(this.s.dialCode))),a&&this._u(a)}},{key:"_i",value:function(){this._j(),this.d.autoHideDialCode&&this._l(),this.d.allowDropdown&&this._i2(),this.hiddenInput&&this._i0()}},{key:"_i0",value:function(){var a=this;this._a14=function(){a.hiddenInput.value=a.getNumber()},this.a.form&&this.a.form.addEventListener("submit",this._a14)}},{key:"_i1",value:function(){for(var a=this.a;a&&"LABEL"!==a.tagName;)a=a.parentNode;return a}},{key:"_i2",value:function(){var a=this;this._a9=function(b){a.m.classList.contains("iti__hide")?a.a.focus():b.preventDefault()};var b=this._i1();b&&b.addEventListener("click",this._a9),this._a10=function(){!a.m.classList.contains("iti__hide")||a.a.disabled||a.a.readOnly||a._n()},this.selectedFlag.addEventListener("click",this._a10),this._a11=function(b){a.m.classList.contains("iti__hide")&&-1!==["ArrowUp","ArrowDown"," ","Enter"].indexOf(b.key)&&(b.preventDefault(),b.stopPropagation(),a._n()),"Tab"===b.key&&a._2()},this.k.addEventListener("keydown",this._a11)}},{key:"_i3",value:function(){var b=this;this.d.utilsScript&&!a.intlTelInputUtils?a.intlTelInputGlobals.windowLoaded?a.intlTelInputGlobals.loadUtils(this.d.utilsScript):a.addEventListener("load",function(){a.intlTelInputGlobals.loadUtils(b.d.utilsScript)}):this.i0(),"auto"===this.d.initialCountry?this._i4():this.h()}},{key:"_i4",value:function(){a.intlTelInputGlobals.autoCountry?this.handleAutoCountry():a.intlTelInputGlobals.startedLoadingAutoCountry||(a.intlTelInputGlobals.startedLoadingAutoCountry=!0,"function"==typeof this.d.geoIpLookup&&this.d.geoIpLookup(function(b){a.intlTelInputGlobals.autoCountry=b.toLowerCase(),setTimeout(function(){return n("handleAutoCountry")})},function(){return n("rejectAutoCountryPromise")}))}},{key:"_j",value:function(){var a=this;this._a12=function(){a._v(a.a.value)&&a._8()},this.a.addEventListener("keyup",this._a12),this._a13=function(){setTimeout(a._a12)},this.a.addEventListener("cut",this._a13),this.a.addEventListener("paste",this._a13)}},{key:"_j2",value:function(a){var b=this.a.getAttribute("maxlength");return b&&a.length>b?a.substr(0,b):a}},{key:"_l",value:function(){var a=this;this._a8=function(){a._l2()},this.a.form&&this.a.form.addEventListener("submit",this._a8),this.a.addEventListener("blur",this._a8)}},{key:"_l2",value:function(){if("+"===this.a.value.charAt(0)){var a=this._m(this.a.value);a&&this.s.dialCode!==a||(this.a.value="")}}},{key:"_m",value:function(a){return a.replace(/\D/g,"")}},{key:"_m2",value:function(a){var c=b.createEvent("Event");c.initEvent(a,!0,!0),this.a.dispatchEvent(c)}},{key:"_n",value:function(){this.m.classList.remove("iti__hide"),this.m.setAttribute("aria-expanded","true"),this._o(),this.b&&(this._x(this.b,!1),this._3(this.b,!0)),this._p(),this.u.classList.add("iti__arrow--up"),this._m2("open:countrydropdown")}},{key:"_n2",value:function(a,b,c){c&&!a.classList.contains(b)?a.classList.add(b):!c&&a.classList.contains(b)&&a.classList.remove(b)}},{key:"_o",value:function(){var c=this;if(this.d.dropdownContainer&&this.d.dropdownContainer.appendChild(this.dropdown),!this.g){var d=this.a.getBoundingClientRect(),e=a.pageYOffset||b.documentElement.scrollTop,f=d.top+e,g=this.m.offsetHeight,h=f+this.a.offsetHeight+ge;if(this._n2(this.m,"iti__country-list--dropup",!h&&i),this.d.dropdownContainer){var j=!h&&i?0:this.a.offsetHeight;this.dropdown.style.top="".concat(f+j,"px"),this.dropdown.style.left="".concat(d.left+b.body.scrollLeft,"px"),this._a4=function(){return c._2()},a.addEventListener("scroll",this._a4)}}}},{key:"_o2",value:function(a){for(var b=a;b&&b!==this.m&&!b.classList.contains("iti__country");)b=b.parentNode;return b===this.m?null:b}},{key:"_p",value:function(){var a=this;this._a0=function(b){var c=a._o2(b.target);c&&a._x(c,!1)},this.m.addEventListener("mouseover",this._a0),this._a1=function(b){var c=a._o2(b.target);c&&a._1(c)},this.m.addEventListener("click",this._a1);var c=!0;this._a2=function(){c||a._2(),c=!1},b.documentElement.addEventListener("click",this._a2);var d="",e=null;this._a3=function(b){b.preventDefault(),"ArrowUp"===b.key||"ArrowDown"===b.key?a._q(b.key):"Enter"===b.key?a._r():"Escape"===b.key?a._2():/^[a-zA-ZÀ-ÿ ]$/.test(b.key)&&(e&&clearTimeout(e),d+=b.key.toLowerCase(),a._s(d),e=setTimeout(function(){d=""},1e3))},b.addEventListener("keydown",this._a3)}},{key:"_q",value:function(a){var b="ArrowUp"===a?this.c.previousElementSibling:this.c.nextElementSibling;b&&(b.classList.contains("iti__divider")&&(b="ArrowUp"===a?b.previousElementSibling:b.nextElementSibling),this._x(b,!0))}},{key:"_r",value:function(){this.c&&this._1(this.c)}},{key:"_s",value:function(a){for(var b=0;bi){d&&(m+=n);var o=g-j;e.scrollTop=m-o}}},{key:"_4",value:function(a,b){var c,d=this.a.value,e="+".concat(a);if("+"===d.charAt(0)){var f=this._5(d);c=f?d.replace(f,e):e}else{if(this.d.nationalMode||this.d.separateDialCode)return;if(d)c=e+d;else{if(!b&&this.d.autoHideDialCode)return;c=e}}this.a.value=c}},{key:"_5",value:function(a){var b="";if("+"===a.charAt(0))for(var c="",d=0;dc?Math.max(0,a.length+c):c;if(k(a))return k(b)&&1==b.length?a.indexOf(b,c):-1;for(;cb?1:aa.length?!1:O(Fa,a)}function Ja(a){return O(Da,a)?P(a,ya):P(a,xa)}function Ka(a){var b=Ja(a.toString());a.c="";a.a(b)}function La(a){return null!=a&&(1!=A(a,9)||-1!=w(a,9)[0])}function P(a,b){for(var c=new F,d,e=a.length,f=0;fb?2:f[f.length-1]=b.c.length)throw Error("Phone number too short after IDD"); +a:{a=b.toString();if(0!=a.length&&"0"!=a.charAt(0))for(e=a.length,b=1;3>=b&&b<=e;++b)if(c=parseInt(a.substring(0,b),10),c in K){d.a(a.substring(b));d=c;break a}d=0}if(0!=d)return u(f,1,d),d;throw Error("Invalid country calling code");}if(null!=c&&(g=y(c,10),h=""+g,l=b.toString(),0==l.lastIndexOf(h,0)&&(h=new F(l.substring(h.length)),l=t(c,1),l=new RegExp(y(l,2)),Ra(h,c,null),h=h.toString(),!O(l,b.toString())&&O(l,h)||3==Y(a,b.toString(),c,-1))))return d.a(h),e&&u(f,6,10),u(f,1,g),g;u(f,1,0);return 0} +function Ra(a,b,c){var d=a.toString(),e=d.length,f=t(b,15);if(0!=e&&null!=f&&0!=f.length){var g=new RegExp("^(?:"+f+")");if(e=g.exec(d)){f=new RegExp(y(t(b,1),2));var h=O(f,d),l=e.length-1;b=t(b,16);if(null==b||0==b.length||null==e[l]||0==e[l].length){if(!h||O(f,d.substring(e[0].length)))null!=c&&0b.c.length)throw Error("The string supplied is too short to be a phone number");null!=g&&(c=new F,e=new F(b.toString()),Ra(e,g,c),a=Y(a,e.toString(),g,-1),2!=a&&4!=a&&5!=a&&(b=e,d&&0a)throw Error("The string supplied is too short to be a phone number");if(17
-
- diff --git a/views/templates/front/jsdef.tpl b/views/templates/front/jsdef.tpl index dd11eb8..02b9aec 100644 --- a/views/templates/front/jsdef.tpl +++ b/views/templates/front/jsdef.tpl @@ -5,4 +5,10 @@ *} \ No newline at end of file