Git Product home page Git Product logo

nutrition-label's Introduction

Nutrition Label jQuery Plugin by Nutritionix

NPM

Check out the Demo!

Summary: Create a FDA-style nutrition label with any nutrition data source (even the Nutritionix API!)

Installation

getting the files from github and including the required files using cdn

git clone [email protected]:nutritionix/nutrition-label.git
<!-- include the needed font from google api -->
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Archivo+Black" />
<!-- include the nutrition label plugin css file -->
<link rel="stylesheet" type="text/css" href="/bower_components/nutrition-label-jquery-plugin/dist/css/nutritionLabel-min.css">
<!-- include the jquery library from the google cdn -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<!-- include the nutrition label plugin js file -->
<script type="text/javascript" src="/bower_components/nutrition-label-jquery-plugin/dist/js/nutritionLabel-min.js"></script>

using bower

bower install --save nutrition-label-jquery-plugin

using npm

npm install nutrition-label-jquery-plugin

<!-- include the needed font from google api -->
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Archivo+Black" />
<!-- include the nutrition label plugin css file -->
<link rel="stylesheet" type="text/css" href="/bower_components/nutrition-label-jquery-plugin/dist/css/nutritionLabel-min.css">
<!-- include the jquery library -->
<script type="text/javascript" src="/bower_components/jquery/dist/jquery.min.js"></script>
<!-- include the nutrition label plugin js file -->
<script type="text/javascript" src="/bower_components/nutrition-label-jquery-plugin/dist/js/nutritionLabel-min.js"></script>

Usage

For some sample usage, you can check out the demo page.

nutrition-label's People

Contributors

genesis23rd avatar majin22 avatar mattsilv avatar sourcec0de avatar yurko-fedoriv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nutrition-label's Issues

[wrong repo] 7

removing the detail as there's no way to delete the ticket. should be on a different repo

Writing HTMl

ensure this is what is happeneing

//User embeds script
//  calls passing in their variableHash --- > ntx(variableHash)


// USE BELOW WITHIN YOUR NTX PROTOTYPE
//----------------------------------------------------------------------------------------------
//GET THE ELEMENT to be writen to without JQUERY -->$('.nutritionDiv')
// Do not use getElementByClassName -> only in modern browsers

var selectedDiv = document.getElementById("nutritionDiv");

// WRITE HTML to the Div
selectedDiv.innerHTML= htmlToBeWritten;
// ^--WITHIN NTX Prototype FUNCTION

[wrong repo] 6

removing the detail as there's no way to delete the ticket. should be on a different repo

minor improvement - decrease the space between the textbox and serving size unit name

decrease the space between the textbox and the serving size unit name

textbox-spacing

what I did is I added a class on the serving size unit and serving size grams if the textbox is present so that the css changes won't affect the label when the serving size textbox is not present

when the textbox is present and there is a serving grams, the code is

<div class="cf">
    <div class="servingSizeText fl">Serving Size</div>
    <div class="rel servingSizeField fl">
        <div class="setter">
            <a rel="nofollow" class="unitQuantityUp" href="Increase the quantity"></a>
            <a rel="nofollow" class="unitQuantityDown" href="Decrease the quantity"></a>
        </div><!-- closing class="setter" -->
        <input type="text" class="unitQuantityBox" value="6.0">
    </div><!-- closing class="servingSizeField" -->
    <div class="servingUnit fl unitHasTextbox">DONUTS</div>
    <div class="servingWeightGrams fl gramsHasTextbox">(2.6g)</div>
</div>

when the textbox is present and there is no serving grams, the code is

<div class="cf">
    <div class="servingSizeText fl">Serving Size</div>
    <div class="rel servingSizeField fl">
        <div class="setter">
            <a rel="nofollow" class="unitQuantityUp" href="Increase the quantity"></a>
            <a rel="nofollow" class="unitQuantityDown" href="Decrease the quantity"></a>
        </div><!-- closing class="setter" -->
        <input type="text" class="unitQuantityBox" value="6.0">
    </div><!-- closing class="servingSizeField" -->
    <div class="servingUnit fl unitHasTextbox">DONUTS</div>
</div>

when the textbox is not present and there is a serving grams, the code is

<div class="cf">
    <div class="servingSizeText fl">Serving Size</div>
    <div class="servingUnitQuantity fl">6</div>
    <div class="servingUnit fl ">DONUTS</div>
    <div class="servingWeightGrams fl ">(2.6g)</div>
</div>

when the textbox is not present and there is no serving grams, the code is

<div class="cf">
    <div class="servingSizeText fl">Serving Size</div>
    <div class="servingUnitQuantity fl">6</div>
    <div class="servingUnit fl ">DONUTS</div>
</div>

let me know if you need me to make more changes

Changes on the decimal values of the plugin

If a value does not have a decimal, we should not show the ".0"

Currently, something with 4g of fat will show as 4.0g of fat Instead, it should show only as "4g" fat.

This should apply to all decimals we show on the plugin and overrides the decimal places settings. this will be a new setting that will be enabled by default

eg. if the decimal places is 2 like 2.33 or 4.00 we will still drop the unnecessary zeroes so the final values on this example is 2.33 and 4

related to nix task https://github.com/mattsilvllc/Nutritionix-Yii/issues/25

[wrong repo] 3

removing the detail as there's no way to delete the ticket. should be on a different repo

Bug on the previous value when the user entered an invalid value

reported by https://github.com/pzykoh

http://dev2.nutritionix.com/boston-market/menu/special-diets/premium?allergens=eggs,fish,gluten,milk,peanuts,soy,tree_nuts,wheat​

​- Click the more info of Rotisserie Chicken - Half Chicken​,
The default serving size is 10.1oz, when you change the decimal value into a letter (ex: 10.a), then click anywhere on the label, instead of the value returning to 10.1, it returns to 10.


I've made a quick test and here are the results:

Original Value: 12.34

Change Value = Resulted Value
a2.34             = 12.34
1a.34             = 1
12.a4             = 12
12.3a             = 12.3
12.34a            = 12.34

this is related to the changes made for version 6.0.13 - May 2, 2016

New Feature: when a user enters an invalid value on the quantity textbox, the label now replace it with the previous valid value and not 1.0

[wrong repo] 5

removing the detail as there's no way to delete the ticket. should be on a different repo

changes on the plugin settings - showItemNameAtTheTop and showBrandName and position of the item name

remove the 'show item name' at the top setting to simplify things


the show brand name will now appear after the item name if the setting showBrandName is true and brandName is not null

"ITEM NAME" dash (-) "BRAND NAME"

changes will be near this code:

            nutritionLabel += tabTemp + '<div class="name '+ itemNameClass +'">' + $this.settings.itemName + '</div>\n';

item name should appear right below the title - http://awesomescreenshot.com/0ec18gu2c6

[wrong repo] 4

removing the detail as there's no way to delete the ticket. should be on a different repo

changes on the increment on the textbox arrows (serving size qty textbox feature)

when the value is 0.5 to 1.0 then the decrement is 0.5

1.0 => down arrow is clicked => 0.5
0.9 => down arrow is clicked => 0.4
0.8 => down arrow is clicked => 0.3
0.7 => down arrow is clicked => 0.2
0.6 => down arrow is clicked => 0.1
0.5 => down arrow is clicked => 0.0
0.4 => down arrow is clicked => 0.0
0.3 => down arrow is clicked => 0.0
0.2 => down arrow is clicked => 0.0
0.1 => down arrow is clicked => 0.0

when the value is 0.0 to 0.9 then the increment is 0.5

0.0 => up arrow is clicked => 0.5
0.1 => up arrow is clicked => 0.6
0.2 => up arrow is clicked => 0.7
0.3 => up arrow is clicked => 0.8
0.4 => up arrow is clicked => 0.9
0.5 => up arrow is clicked => 1.0
0.6 => up arrow is clicked => 1.1
0.7 => up arrow is clicked => 1.2
0.8 => up arrow is clicked => 1.3
0.9 => up arrow is clicked => 1.4

when the value is 2.0 to 1.1 then the down arrow will take the value to 1

2.0 => down arrow is clicked => 1.0
1.9 => down arrow is clicked => 1.0
1.8 => down arrow is clicked => 1.0
1.7 => down arrow is clicked => 1.0
1.6 => down arrow is clicked => 1.0
1.5 => down arrow is clicked => 1.0
1.4 => down arrow is clicked => 1.0
1.3 => down arrow is clicked => 1.0
1.2 => down arrow is clicked => 1.0
1.1 => down arrow is clicked => 1.0

when the value is 1.0 and above then the increment is 1.0

Divide by zero issue (NaN) for some daily values

It is possible that calculating the daily values may lead to a "NaN" being displayed to the user.

For exampe, if dailyValueSodium == 0, then the following code will produce a "NaN" on screen:

($this.settings.allowFDARounding ? roundPotassiumRule($this.settings.valuePotassium) : $this.settings.valuePotassium) / ($this.settings.dailyValuePotassium * calorieIntakeMod)

serving per container

from Matt

As a low priority task, can you update our nutrition label to dynamically change servings per container if the value exists.

crunchy cookies chocolate chip - dairy-free nut-free soy-free food allergy-friendly 2013-12-10 17-40-06




from @majin22

Hi Matt,

Will the formula be servings per container * quantity on the textbox?

If yes, should we recompute the servings per container depending on the initial value on the textbox? Eg. if the servings on the textbox is 0.25 and the servings per container is 8, the initial value will be 2?

Thanks.




from Matt

The formula will need to follow these steps:

  1. Determine total qty of items per container by taking original serving qty * original servings per container

Example:
2 Cookies
5 Servings Per Container

The total_qty would be 2*5 = 10.

  1. Determine dynamic servings per container by taking $total_qty/$serving_qty.

In the example 10 / 2 = 5. So there are 5 servings per container.

If user changed it to 1 cookie, it would be 10 / 1 = 10 servings per container (if the serving is 1 cookie, there are 10 cookies in the box)

ReferenceError: x is not defined

Hi, I have this problem when I'm trying to use it.

captura de pantalla 2017-01-04 a las 8 27 02 a m

My code

<div id="test"></div>
$('#test').nutritionLabel();

Thanks for your support!

new rounding rules

from Matt

Here are the rounding rules for Vitamins:

Round to nearest even number percent as long as it is below 10 percent
Round to the nearest 5 percent increment when above 10 and up to 50 percent.
Round to nearest 10 percent when above 50 percent

jquery label plugin - major changes

based on a chat with @mattsilv

(1) change the label to not allow any string input - before we allow string and numeric inputs on the nutrition values

(2) have the serving_unit_qty display in an input box and then change the values in the label if you modify the serving unit (assuming the value is present and not null) - value should be a float, can't be a string

(2a) the textbox can be activated by pressing enter on the textbox

(2b) there will be an up and down arrow that can change the value of the serving unit qty (like the arrows on the calculator)

(3) add a simple setting to be able to hide the textbox on (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.