Last active
August 29, 2015 14:07
-
-
Save grimen/7ce97422bb555837e9a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
# Polymer => Angular :( | |
xImage = angular.module 'a-image', [] | |
xImage | |
.factory 'XImageElementObject', () -> | |
return XImageElementObject | |
xImage.instance = new XImageElementObject | |
xImage.instance.filters.forEach (filt) -> | |
xImage | |
.filter filt, (XImageElementObject) -> | |
return xImage.instance[filt].bind(xImage.instance) | |
xImage | |
.directive 'aImage', ($filter, XImageElementObject) -> | |
scope = {} | |
xImage.instance.attributes.forEach (attr) -> | |
scope[attr] = '@' | |
return { | |
restrict: 'E' | |
templateUrl: "/components/angular/a-image/index.html" | |
scope: scope | |
link: (scope, element, attrs) -> | |
xImage.elementID = (xImage.elementID || 0) | |
xImage.elementID++ | |
scope.elementID = xImage.elementID | |
element.attr('id', "a-image-#{scope.elementID}") | |
scope.object = new XImageElementObject(element[0]) | |
scope.object.attributes.forEach (attr) -> | |
if value = scope[attr] | |
scope.object[attr] = value | |
attrs.$observe attr, (value) -> | |
if value | |
scope.object[attr] = value | |
Object.observe scope.object, (changes) -> | |
for change in changes | |
value = scope.object[change.name] | |
callback = scope.object[scope.object.observe[change.name]] | |
if callback | |
try | |
callback.call(scope.object, value) | |
catch err | |
console.log err | |
if ~Object.keys(scope.object.publish).indexOf(change.name) | |
scope[change.name] = change.object[change.name] | |
if scope.object.publish[change.name].reflect | |
if change.object[change.name] | |
element.attr(change.name, '') | |
else | |
element.removeAttr(change.name) | |
scope.$apply() | |
scope.object.ready() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
# Polymer :) | |
Polymer(XImageElementObject.prototype) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment