Skip to content

Commit

Permalink
Add new examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed Sep 23, 2018
1 parent 895a9db commit 81ae923
Show file tree
Hide file tree
Showing 29 changed files with 391 additions and 50 deletions.
12 changes: 6 additions & 6 deletions examples/gen/country-sync.html
Expand Up @@ -4,10 +4,10 @@
<meta charset="utf-8">
<title>Example: Country sync</title>
<link rel="stylesheet" href="../css/prism.css">
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1537705480435">
<link rel="stylesheet" href="../../build/css/demo.css?1537705480435">
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1537717752654">
<link rel="stylesheet" href="../../build/css/demo.css?1537717752654">

<link rel="stylesheet" href="../css/countrySync.css?1537705480435">
<link rel="stylesheet" href="../css/countrySync.css?1537717752654">


<!-- GOOGLE ANALYTICS -->
Expand Down Expand Up @@ -50,7 +50,7 @@ <h2>Code</h2>

// init plugin
var iti = window.intlTelInput(input, {
utilsScript: &quot;../../build/js/utils.js?1537705480435&quot; // just for formatting/placeholders etc
utilsScript: &quot;../../build/js/utils.js?1537717752654&quot; // just for formatting/placeholders etc
});

// populate the country dropdown
Expand Down Expand Up @@ -94,7 +94,7 @@ <h2>Result</h2>
</div>

<script src="../js/prism.js"></script>
<script src="../../build/js/intlTelInput.js?1537705480435"></script>
<script src="./js/countrySync.js?1537705480435"></script>
<script src="../../build/js/intlTelInput.js?1537717752654"></script>
<script src="./js/countrySync.js?1537717752654"></script>
</body>
</html>
10 changes: 5 additions & 5 deletions examples/gen/default-country-ip.html
Expand Up @@ -4,8 +4,8 @@
<meta charset="utf-8">
<title>Example: Lookup user's country</title>
<link rel="stylesheet" href="../css/prism.css">
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1537705480435">
<link rel="stylesheet" href="../../build/css/demo.css?1537705480435">
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1537717752654">
<link rel="stylesheet" href="../../build/css/demo.css?1537717752654">


<!-- GOOGLE ANALYTICS -->
Expand Down Expand Up @@ -40,7 +40,7 @@ <h2>Code</h2>
callback(countryCode);
});
},
utilsScript: &quot;../../build/js/utils.js?1537705480435&quot; // just for formatting/placeholders etc
utilsScript: &quot;../../build/js/utils.js?1537717752654&quot; // just for formatting/placeholders etc
});
</code></pre>

Expand All @@ -52,7 +52,7 @@ <h2>Result</h2>
</div>

<script src="../js/prism.js"></script>
<script src="../../build/js/intlTelInput.js?1537705480435"></script>
<script src="./js/defaultCountryIp.js?1537705480435"></script>
<script src="../../build/js/intlTelInput.js?1537717752654"></script>
<script src="./js/defaultCountryIp.js?1537717752654"></script>
</body>
</html>
49 changes: 49 additions & 0 deletions examples/gen/display-number.html
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example: Display an existing number</title>
<link rel="stylesheet" href="../css/prism.css">
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1537717752654">
<link rel="stylesheet" href="../../build/css/demo.css?1537717752654">


<!-- GOOGLE ANALYTICS -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-85394876-1', 'auto');
ga('send', 'pageview');
</script>
<!-- /GOOGLE ANALYTICS -->
</head>

<body>
<a href="/">Back</a>
<h1>Example: Display an existing number</h1>
<p>We initialise the plugin on an input which already contains a full international number. The plugin will automatically select the relevant flag, and re-format the number to national format.</p>

<h2>Markup</h2>
<pre><code class="language-markup">&lt;input id=&quot;phone&quot; type=&quot;tel&quot; value=&quot;+447733312345&quot;&gt;
</code></pre>

<h2>Code</h2>
<pre><code class="language-javascript">var input = document.querySelector(&quot;#phone&quot;);
window.intlTelInput(input, {
utilsScript: &quot;../../build/js/utils.js?1537717752654&quot; // just for formatting/placeholders etc
});
</code></pre>

<h2>Result</h2>
<div id="result">
<input id="phone" type="tel" value="+447733312345">

</div>

<script src="../js/prism.js"></script>
<script src="../../build/js/intlTelInput.js?1537717752654"></script>
<script src="./js/displayNumber.js?1537717752654"></script>
</body>
</html>
10 changes: 5 additions & 5 deletions examples/gen/hidden-input.html
Expand Up @@ -4,8 +4,8 @@
<meta charset="utf-8">
<title>Example: Submitting the full international number using a hidden input</title>
<link rel="stylesheet" href="../css/prism.css">
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1537705480435">
<link rel="stylesheet" href="../../build/css/demo.css?1537705480435">
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1537717752654">
<link rel="stylesheet" href="../../build/css/demo.css?1537717752654">


<!-- GOOGLE ANALYTICS -->
Expand Down Expand Up @@ -36,7 +36,7 @@ <h2>Code</h2>
<pre><code class="language-javascript">var input = document.querySelector(&quot;#phone&quot;);
window.intlTelInput(input, {
hiddenInput: &quot;full_phone&quot;,
utilsScript: &quot;../../build/js/utils.js?1537705480435&quot; // just for formatting/placeholders etc
utilsScript: &quot;../../build/js/utils.js?1537717752654&quot; // just for formatting/placeholders etc
});
</code></pre>

Expand All @@ -50,7 +50,7 @@ <h2>Result</h2>
</div>

<script src="../js/prism.js"></script>
<script src="../../build/js/intlTelInput.js?1537705480435"></script>
<script src="./js/hiddenInput.js?1537705480435"></script>
<script src="../../build/js/intlTelInput.js?1537717752654"></script>
<script src="./js/hiddenInput.js?1537717752654"></script>
</body>
</html>
68 changes: 68 additions & 0 deletions examples/gen/init-promise.html
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example: Using the promise returned from initialisation</title>
<link rel="stylesheet" href="../css/prism.css">
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1537717752654">
<link rel="stylesheet" href="../../build/css/demo.css?1537717752654">


<!-- GOOGLE ANALYTICS -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-85394876-1', 'auto');
ga('send', 'pageview');
</script>
<!-- /GOOGLE ANALYTICS -->
</head>

<body>
<a href="/">Back</a>
<h1>Example: Using the promise returned from initialisation</h1>
<p>Use this promise to know when the plugin has completely finished initialising, including completing any asynchronous actions you might have enabled with the initialisation options e.g. fetching utils.js with the utilsScript option, and performing the ip lookup with the geoIpLookup option.</p>

<h2>Markup</h2>
<pre><code class="language-markup">&lt;!-- polyfill for IE11 --&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;
Status:
&lt;span id=&quot;status&quot;&gt;Initialising...&lt;/span&gt;
&lt;/p&gt;
&lt;input id=&quot;phone&quot; type=&quot;tel&quot;&gt;
</code></pre>

<h2>Code</h2>
<pre><code class="language-javascript">var input = document.querySelector(&quot;#phone&quot;);
var statusElement = document.querySelector(&quot;#status&quot;);

var iti = window.intlTelInput(input, {
utilsScript: &quot;../../build/js/utils.js?1537717752654&quot;,
});
iti.promise.then(function() {
statusElement.innerHTML = &quot;Initialised!&quot;;
});
</code></pre>

<h2>Result</h2>
<div id="result">
<!-- polyfill for IE11 -->
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js"></script>

<p>
Status:
<span id="status">Initialising...</span>
</p>
<input id="phone" type="tel">

</div>

<script src="../js/prism.js"></script>
<script src="../../build/js/intlTelInput.js?1537717752654"></script>
<script src="./js/initPromise.js?1537717752654"></script>
</body>
</html>
26 changes: 17 additions & 9 deletions examples/gen/is-valid-number.html
Expand Up @@ -4,10 +4,10 @@
<meta charset="utf-8">
<title>Example: Validation</title>
<link rel="stylesheet" href="../css/prism.css">
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1537705480435">
<link rel="stylesheet" href="../../build/css/demo.css?1537705480435">
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1537717752654">
<link rel="stylesheet" href="../../build/css/demo.css?1537717752654">

<link rel="stylesheet" href="../css/isValidNumber.css?1537705480435">
<link rel="stylesheet" href="../css/isValidNumber.css?1537717752654">


<!-- GOOGLE ANALYTICS -->
Expand All @@ -25,25 +25,30 @@
<body>
<a href="/">Back</a>
<h1>Example: Validation</h1>
<p>Use public isValidNumber method (utilising Google's libphonenumber) to validate the telephone number on the change event.</p>
<p>Use the isValidNumber method (which utilises Google's libphonenumber) to validate the telephone number on the blur event.</p>

<h2>Markup</h2>
<pre><code class="language-markup">&lt;input id=&quot;phone&quot; type=&quot;tel&quot;&gt;
&lt;span id=&quot;valid-msg&quot; class=&quot;hide&quot;&gt;✓ Valid&lt;/span&gt;
&lt;span id=&quot;error-msg&quot; class=&quot;hide&quot;&gt;Invalid number&lt;/span&gt;</code></pre>
&lt;span id=&quot;error-msg&quot; class=&quot;hide&quot;&gt;&lt;/span&gt;
</code></pre>

<h2>Code</h2>
<pre><code class="language-javascript">var input = document.querySelector(&quot;#phone&quot;),
errorMsg = document.querySelector(&quot;#error-msg&quot;),
validMsg = document.querySelector(&quot;#valid-msg&quot;);

// here, the index maps to the error code returned from getValidationError - see readme
var errorMap = [ &quot;Invalid number&quot;, &quot;Invalid country code&quot;, &quot;Too short&quot;, &quot;Too long&quot;, &quot;Invalid number&quot;];

// initialise plugin
var iti = window.intlTelInput(input, {
utilsScript: &quot;../../build/js/utils.js?1537705480435&quot;
utilsScript: &quot;../../build/js/utils.js?1537717752654&quot;
});

var reset = function() {
input.classList.remove(&quot;error&quot;);
errorMsg.innerHTML = &quot;&quot;;
errorMsg.classList.add(&quot;hide&quot;);
validMsg.classList.add(&quot;hide&quot;);
};
Expand All @@ -56,6 +61,8 @@ <h2>Code</h2>
validMsg.classList.remove(&quot;hide&quot;);
} else {
input.classList.add(&quot;error&quot;);
var errorCode = iti.getValidationError();
errorMsg.innerHTML = errorMap[errorCode];
errorMsg.classList.remove(&quot;hide&quot;);
}
}
Expand All @@ -70,11 +77,12 @@ <h2>Result</h2>
<div id="result">
<input id="phone" type="tel">
<span id="valid-msg" class="hide">✓ Valid</span>
<span id="error-msg" class="hide">Invalid number</span>
<span id="error-msg" class="hide"></span>

</div>

<script src="../js/prism.js"></script>
<script src="../../build/js/intlTelInput.js?1537705480435"></script>
<script src="./js/isValidNumber.js?1537705480435"></script>
<script src="../../build/js/intlTelInput.js?1537717752654"></script>
<script src="./js/isValidNumber.js?1537717752654"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/gen/js/countrySync.js
Expand Up @@ -5,7 +5,7 @@ var countryData = window.intlTelInputGlobals.getCountryData(),

// init plugin
var iti = window.intlTelInput(input, {
utilsScript: "../../build/js/utils.js?1537705480435" // just for formatting/placeholders etc
utilsScript: "../../build/js/utils.js?1537717752654" // just for formatting/placeholders etc
});

// populate the country dropdown
Expand Down
2 changes: 1 addition & 1 deletion examples/gen/js/defaultCountryIp.js
Expand Up @@ -7,5 +7,5 @@ window.intlTelInput(input, {
callback(countryCode);
});
},
utilsScript: "../../build/js/utils.js?1537705480435" // just for formatting/placeholders etc
utilsScript: "../../build/js/utils.js?1537717752654" // just for formatting/placeholders etc
});
4 changes: 4 additions & 0 deletions examples/gen/js/displayNumber.js
@@ -0,0 +1,4 @@
var input = document.querySelector("#phone");
window.intlTelInput(input, {
utilsScript: "../../build/js/utils.js?1537717752654" // just for formatting/placeholders etc
});
2 changes: 1 addition & 1 deletion examples/gen/js/hiddenInput.js
@@ -1,5 +1,5 @@
var input = document.querySelector("#phone");
window.intlTelInput(input, {
hiddenInput: "full_phone",
utilsScript: "../../build/js/utils.js?1537705480435" // just for formatting/placeholders etc
utilsScript: "../../build/js/utils.js?1537717752654" // just for formatting/placeholders etc
});
9 changes: 9 additions & 0 deletions examples/gen/js/initPromise.js
@@ -0,0 +1,9 @@
var input = document.querySelector("#phone");
var statusElement = document.querySelector("#status");

var iti = window.intlTelInput(input, {
utilsScript: "../../build/js/utils.js?1537717752654",
});
iti.promise.then(function() {
statusElement.innerHTML = "Initialised!";
});
8 changes: 7 additions & 1 deletion examples/gen/js/isValidNumber.js
Expand Up @@ -2,13 +2,17 @@ var input = document.querySelector("#phone"),
errorMsg = document.querySelector("#error-msg"),
validMsg = document.querySelector("#valid-msg");

// here, the index maps to the error code returned from getValidationError - see readme
var errorMap = [ "Invalid number", "Invalid country code", "Too short", "Too long", "Invalid number"];

// initialise plugin
var iti = window.intlTelInput(input, {
utilsScript: "../../build/js/utils.js?1537705480435"
utilsScript: "../../build/js/utils.js?1537717752654"
});

var reset = function() {
input.classList.remove("error");
errorMsg.innerHTML = "";
errorMsg.classList.add("hide");
validMsg.classList.add("hide");
};
Expand All @@ -21,6 +25,8 @@ input.addEventListener('blur', function() {
validMsg.classList.remove("hide");
} else {
input.classList.add("error");
var errorCode = iti.getValidationError();
errorMsg.innerHTML = errorMap[errorCode];
errorMsg.classList.remove("hide");
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/gen/js/modifyCountryData.js
Expand Up @@ -7,5 +7,5 @@ for (var i = 0; i < countryData.length; i++) {
}

window.intlTelInput(input, {
utilsScript: "../../build/js/utils.js?1537705480435" // just for formatting/placeholders etc
utilsScript: "../../build/js/utils.js?1537717752654" // just for formatting/placeholders etc
});
13 changes: 13 additions & 0 deletions examples/gen/js/multipleInstances.js
@@ -0,0 +1,13 @@
var inputHome = document.querySelector("#home");
var inputMobile = document.querySelector("#mobile");

window.intlTelInput(inputHome, {
initialCountry: 'gb',
placeholderNumberType: 'FIXED_LINE',
utilsScript: "../../build/js/utils.js?1537717752654" // just for formatting/placeholders etc
});
window.intlTelInput(inputMobile, {
initialCountry: 'gb',
placeholderNumberType: 'MOBILE',
utilsScript: "../../build/js/utils.js?1537717752654"
});
2 changes: 1 addition & 1 deletion examples/gen/js/nationalMode.js
Expand Up @@ -3,7 +3,7 @@ var input = document.querySelector("#phone"),

var iti = window.intlTelInput(input, {
nationalMode: true,
utilsScript: "../../build/js/utils.js?1537705480435" // just for formatting/placeholders etc
utilsScript: "../../build/js/utils.js?1537717752654" // just for formatting/placeholders etc
});

var handleChange = function() {
Expand Down
2 changes: 1 addition & 1 deletion examples/gen/js/onlyCountriesEurope.js
Expand Up @@ -4,5 +4,5 @@ window.intlTelInput(input, {
"ee", "fo", "fi", "fr", "de", "gi", "gr", "va", "hu", "is", "ie", "it", "lv",
"li", "lt", "lu", "mk", "mt", "md", "mc", "me", "nl", "no", "pl", "pt", "ro",
"ru", "sm", "rs", "sk", "si", "es", "se", "ch", "ua", "gb"],
utilsScript: "../../build/js/utils.js?1537705480435" // just for formatting/placeholders etc
utilsScript: "../../build/js/utils.js?1537717752654" // just for formatting/placeholders etc
});

0 comments on commit 81ae923

Please sign in to comment.