nutrition-label-jquery-plugin
Version:
To be able to create a FDA-style nutrition label with any nutrition data source
149 lines (129 loc) • 4.93 kB
HTML
<html lang="en">
<head>
<title>UK Version Demo Page</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-7s5uDGW3AHqw6xtJmNNtr+OBRJUlgkNJEo78P4b0yRw= sha512-nNo+yCHEyn0smMxSswnf/OnX6/KwJuZTlNZBjauKhTK0c+zT+q5JOCx0UFhXQ6rJR9jg6Es8gPuD2uZcYDLqSw==" crossorigin="anonymous">
<link rel='stylesheet' type='text/css' media='all' href='../../nutritionLabel-min.css'>
<link rel='stylesheet' type='text/css' media='all' href='./../css/demo.css'>
<!-- google webfont for nutrition label -->
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Archivo+Black" />
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li><a href="../demo.html"><i class="icon-chevron-right"></i> Back to Demo Page</a></li>
<li><a href="#test1"><i class="icon-chevron-right"></i> Example 1</a></li>
<li><a href="#test2"><i class="icon-chevron-right"></i> Example 2</a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<div class="row">
<div class="col-md-4">
<div id="test1"></div>
</div>
<div class="col-md-8">
<h3>Example #1</h3>
<p>
<a href="https://github.com/nutritionix/nutrition-label/issues/51#issuecomment-215998212">
Basic use of the using the google analytics event feature supplying a renamed google analytics function</a>
The code for the google analytics is:
</p>
<pre>
(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','_gaNixLabel');
_gaNixLabel('create', 'UA-12345678-9', 'auto');
</pre><br/><br/>
<pre id="pre1">
$('#test1').nutritionLabel({
width : 380,
showLegacyVersion : false,
showUKVersion : true,
showItemNameForUK : true,
showDailySugars : true,
valueServingWeightGrams : 77,
dailyValueTotalFat : 70, //this should be 70 for the uk version
dailyValueCarb : 260, //this should be 260 for the uk version
dailyValueSugar : 90, //this should be 90 for the uk version
textCalories : 'Energy',
textTotalCarb : 'Carbohydrate',
textFibers : 'Fibre',
textSodium : 'Salt',
allowGoogleAnalyticsEventLog : true,
gooleAnalyticsFunctionName : '_gaNixLabel'
});
</pre>
</div>
</div><br /><br />
<div class="row">
<div class="col-md-4">
<div id="test2"></div>
</div>
<div class="col-md-8">
<h3>Example #2</h3>
<p>
This is an example where the user function "alertMe" is triggered when the quantity value is changed.
The plugin calls the function "alertMe" with 3 parameters
1. kind - textbox / up arrow / down arrow
2. previous value
3. new value
The code of "alertMe" is:
</p>
<pre>
function alertMe(kindValue, OldValue, NewValue){
console.log(
'kindValue => ' + kindValue + "\n" +
'OldValue => ' + OldValue + "\n" +
'NewValue => ' + NewValue
);
}
</pre><br/><br/>
<pre id="pre2">
$('#test2').nutritionLabel({
width : 380,
showLegacyVersion : false,
showUKVersion : true,
showItemNameForUK : true,
showDailySugars : true,
valueServingWeightGrams : 77,
dailyValueTotalFat : 70, //this should be 70 for the uk version
dailyValueCarb : 260, //this should be 260 for the uk version
dailyValueSugar : 90, //this should be 90 for the uk version
textCalories : 'Energy',
textTotalCarb : 'Carbohydrate',
textFibers : 'Fibre',
textSodium : 'Salt',
allowTriggerOfUserFunctionOnQuantityChange : true,
userFunctionNameOnQuantityChange : 'alertMe'
});
</pre>
</div>
</div><br /><br /><br />
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="../../nutritionLabel-min.js"></script>
<script type="text/javascript">
function alertMe(kindValue, OldValue, NewValue){
console.log(
'kindValue => ' + kindValue + "\n" +
'OldValue => ' + OldValue + "\n" +
'NewValue => ' + NewValue
);
}
$(document).ready(function(){
eval( eval( $('#pre1').html() ) );
eval( eval( $('#pre2').html() ) );
});
(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','_gaNixLabel');
_gaNixLabel('create', 'UA-12345678-9', 'auto');
</script>
</body>
</html>