-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-nutrition-label.min.js
1 lines (1 loc) · 4.81 KB
/
angular-nutrition-label.min.js
1
"use strict";angular.module("nutritionix.nutrition-label",[]).constant("nutritionLabelGlobalOptions",{overrides:{}}).directive("nutritionLabel",["$log","nutritionLabelGlobalOptions",function(a,u){return{restrict:"A",template:'\n <div>\n <div class="label-container"></div>\n <div class="label-mode-switch" ng-if="!settings.hideModeSwitcher">\n FDA Label Style:\n <label class="radio-inline">\n <input type="radio" name="labelMode" ng-value="false" ng-model="vm.showLegacyVersion"> 2018 Version\n </label>\n <label class="radio-inline">\n <input type="radio" name="labelMode" ng-value="true" ng-model="vm.showLegacyVersion"> Legacy Version\n </label>\n </div>\n </div>\n ',scope:{item:"=nutritionLabel",options:"=?nutritionLabelOptions"},link:function(l,a,t){var n=a.find(".label-container");function i(){var e=angular.extend({},u,t,l.options||{},l.item,u.overrides,l.vm||{});return angular.forEach(e,function(a,t){"$"===t[0]?delete e[t]:-1===t.indexOf("userFunction")&&angular.isFunction(a)&&(e[t]=a(e))}),e}function e(){var a,t;if(n.html(""),angular.isObject(l.item)){if((a=angular.element("<div>").attr("id","label-"+Math.random().toString(36).substring(2))).appendTo(n),"function"==typeof(t=i()).userFunctionOnQuantityChange){var e=t.userFunctionOnQuantityChange;t.userFunctionOnQuantityChange=function(){e.apply(t,arguments),l.$apply()}}t.calorieIntake&&t.adjustUserDailyValues&&["valuePotassium_2018","valueVitaminA","valueVitaminC","valueVitaminD","valueCalcium","valueIron"].forEach(function(a){t[a]&&(t[a]*=2e3/t.calorieIntake)}),t.applyMathRounding&&["valueServingWeightGrams","valueServingPerContainer","valueCalories","valueFatCalories","valueTotalFat","valueSatFat","valueTransFat","valuePolyFat","valueMonoFat","valueCholesterol","valueSodium","valuePotassium","valueTotalCarb","valueFibers","valueSugars","valueAddedSugars","valueProteins","valueVitaminA","valueVitaminC","valueVitaminD","valueCalcium","valueIron"].forEach(function(a){angular.isUndefined(t[a])||(t[a]=function(a){if(!a)return a;var t;t=a<1?2:a<10?1:0;var e=Math.pow(10,t);return Math.round(a*e)/e}(t[a]))}),l.settings=t,a.nutritionLabel(t)}}var r=i();l.vm={showLegacyVersion:!!angular.isUndefined(r.showLegacyVersion)||!!r.showLegacyVersion},l.$watch(function(){return JSON.stringify(i())},function(a,t){a!==t&&e()}),e()}}}]).filter("trackFoodToLabelData",["$log","nutritionLabelGlobalOptions",function(a,e){var i={itemName:"Item",brandName:"Nutritionix",allowFDARounding:!1,applyMathRounding:!0,valueServingUnitQuantity:1,valueServingSizeUnit:"Serving",showIngredients:!1},r=[{labelAttribute:"valueCalories",attrId:208},{labelAttribute:"valueFatCalories",attrId:204,adapter:function(a){return 9*a}},{labelAttribute:"valueTotalFat",attrId:204},{labelAttribute:"valueSatFat",attrId:606},{labelAttribute:"valueTransFat",attrId:605},{labelAttribute:"valueMonoFat",attrId:645},{labelAttribute:"valuePolyFat",attrId:646},{labelAttribute:"valueCholesterol",attrId:601},{labelAttribute:"valueSodium",attrId:307},{labelAttribute:"valuePotassium",attrId:306},{labelAttribute:"valuePotassium_2018",attrId:306,dailyValue:4700},{labelAttribute:"valueTotalCarb",attrId:205},{labelAttribute:"valueFibers",attrId:291},{labelAttribute:"valueSugars",attrId:269},{labelAttribute:"valueAddedSugars",attrId:539},{labelAttribute:"valueProteins",attrId:203},{labelAttribute:"valueVitaminA",attrId:318,dailyValue:5e3},{labelAttribute:"valueVitaminC",attrId:401,dailyValue:60},{labelAttribute:"valueVitaminD",attrId:328,dailyValue:20},{labelAttribute:"valueCalcium",attrId:301,dailyValue:1300},{labelAttribute:"valueIron",attrId:303,dailyValue:18},{labelAttribute:"valueCaffeine",attrId:262}];return function(a){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},l=2<arguments.length&&void 0!==arguments[2]?arguments[2]:1,n={full_nutrients:angular.copy(a.full_nutrients)};return n.itemName=(a.food_name||"").replace(/^([a-z])|\s+([a-z])/g,function(a){return a.toUpperCase()}),n.brandName=a.brand_name,n.valueServingUnitQuantity=a.serving_qty,n.valueServingSizeUnit=a.serving_unit,n.valueServingWeightGrams=a.serving_weight_grams/l,r.forEach(function(a){var t=function(a,t){t=t.toString();for(var e=0;e<a.length;e+=1)if(a[e].attr_id.toString()===t)return a[e].value}(n.full_nutrients,a.attrId);if(angular.isUndefined(t))n[a.labelAttribute.replace("value","show")]=!1;else{if(angular.isFunction(a.adapter)&&(t=a.adapter(t)),l&&1!==l&&(t/=l),a.dailyValue){t=100/a.dailyValue*t;var e="daily"+a.labelAttribute[0].toUpperCase()+a.labelAttribute.substr(1);n[e]=a.dailyValue}n[a.labelAttribute]=t,n[a.labelAttribute.replace("value","show")]=!0}}),l&&1!==l&&angular.forEach(n.full_nutrients,function(a){a.value/=l}),angular.extend(n,t),angular.forEach(i,function(a,t){angular.isUndefined(n[t])&&angular.isUndefined(e[t])&&(n[t]=a)}),n}}]);