forked from GabiAxel/ng-polymer-elements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ng-polymer-elements.min.js
1 lines (1 loc) · 4.36 KB
/
ng-polymer-elements.min.js
1
!function(angular){angular.module("ng-polymer-elements",[]).config(["$compileProvider","$injector",function($compileProvider,$injector){"use strict";var inputMappings={ngModel:"=value",ngDisabled:"=disabled",ngFocused:"=focused"},selectorMappings={ngModel:"=selected"},multiSelectableMappings={ngModel:function property(element){return element.hasAttribute("multi")?"selectedValues":"selected"}},checkMappings={ngModel:"=checked",ngDisabled:"=disabled",ngChange:"&iron-change"},allMappings={ironSelector:multiSelectableMappings,paperInput:inputMappings,paperTextarea:inputMappings,paperRadioGroup:selectorMappings,paperTabs:selectorMappings,paperMenu:multiSelectableMappings,paperCheckbox:checkMappings,paperToggleButton:checkMappings,paperDialog:{ngOpened:"=opened",ngOverlayOpened:"&iron-overlay-opened",ngOverlayClosed:"&iron-overlay-closed"},paperSlider:{ngModel:"=value",ngChange:"&value-change",ngDisabled:"=disabled"},goldEmailInput:inputMappings,goldPhoneInput:inputMappings,goldCcInput:{ngModel:"=value",ngDisabled:"=disabled",ngFocused:"=focused",ngCardType:"=cardType"},goldCcExpirationInput:inputMappings,goldCcCvcInput:inputMappings,goldZipInput:inputMappings,googleFeeds:{ngModel:"=results",loading:"=loading",ngError:"&google-feeds-error",ngQueryError:"&google-feeds-queryerror",ngQueryResponse:"&google-feeds-queryresponse",ngResponse:"&google-feeds-response",ngMultiResponse:"&google-multi-feeds-response"},googleMap:{ngMap:"=map",ngLatitude:"=latitude",ngLongitude:"=longitude"},googleSheets:{ngRows:"=rows",ngSheet:"=sheet",ngTab:"=tab"}};if($injector.has("$ngPolymerMappings")){var extendedMappings=$injector.get("$ngPolymerMappings");angular.extend(allMappings,extendedMappings)}Object.keys(allMappings).forEach(function(tag){var mappings=allMappings[tag];$compileProvider.directive(tag,["$parse","$window",function($parse,$window){var scopeDefinition={},keys=Object.keys(mappings);return keys.forEach(function(attr){var mapped=mappings[attr],mappingType;switch(typeof mapped){case"string":if(mappingType=mapped.charAt(0),"="!==mappingType&&"&"!==mappingType)throw'Invalid mapping: "'+mapped+'" - must begin with "=" or "&"';mapped=mapped.substr(1);break;case"function":switch(mapped.name){case"property":mappingType="=";break;case"event":mappingType="&";break;default:throw'Invalid mapping for "'+attr+'" - function name must be "property" or "event"'}break;default:throw'Invalid mapped type for "'+attr+'" - must be string or function'}scopeDefinition[attr]=mappingType}),{restrict:"E",scope:scopeDefinition,link:function(scope,element,attrs){var el=element[0],observers={};scope.$on("$destroy",function(){Object.keys(observers).forEach(function(key){var observer=observers[key];Object.unobserve(el[key],observer)})}),keys.forEach(function(attr){if(attrs[attr]){var mapped=mappings[attr],mappingType;if("function"==typeof mapped?(mappingType="property"===mapped.name?"=":"&",mapped=mapped(el)):(mappingType=mapped.charAt(0),mapped=mapped.substr(1)),"&"===mappingType){var fn=$parse(attrs[attr]);el.addEventListener(mapped,function(e){scope.$apply(function(){fn(scope.$parent,{$event:e})})})}else{var propertyName=mapped,propertyInfo=el.getPropertyInfo(mapped),propertyType=propertyInfo.type,readOnly=propertyInfo.readOnly;if(!readOnly&&!el[propertyName])switch(propertyType){case Array:el[propertyName]=[];break;case Object:el[propertyName]={}}var attachObserver=function(){if(!readOnly)switch(observers[propertyName]&&(Object.unobserve(el[propertyName],observers[propertyName]),delete observers[propertyName]),propertyType){case Array:case Object:observers[propertyName]=function(){scope.$apply(function(){scope[attr]||(scope[attr]=propertyType===Array?[]:{}),angular.copy(el[propertyName],scope[attr])})},Object.observe(el[propertyName],observers[propertyName])}};attachObserver();var handler=function(){setTimeout(function(){var value=scope[attr];propertyType!=Array&&propertyType!=Object?void 0!==value&&(el[propertyName]=value):value&&(el[propertyName]=angular.copy(value),attachObserver())})};readOnly||(scope.$watch(attr,handler,!0),handler(scope[attr]));var eventName=propertyName.replace(/([A-Z])/g,function($1){return"-"+$1.toLowerCase()})+"-changed";el.addEventListener(eventName,function(event){var value=el[propertyName];el.async(function(){scope.$apply(function(){propertyType===Array||propertyType===Object?scope[attr]=angular.copy(value):scope[attr]!=value&&(scope[attr]=value)}),attachObserver()})})}}})}}}])})}])}(angular);