-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: faDeck Directive #241
Open
imheresamir
wants to merge
8
commits into
Famous:master
Choose a base branch
from
imheresamir:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5590a00
Add fa-deck directive
imheresamir 969bfda
Added Tests for faDeck Directive
imheresamir a057ba1
added faDeck example in the header comment
imheresamir 279dff9
feat: add faDeck directive
imheresamir 16c017a
test: added tests for faDeck directive
imheresamir 56caca5
chore: added faDeck example in the header comment
imheresamir ade0138
Merge branch 'master' of https://github.com/imheresamir/famous-angular
imheresamir a40203d
Merge branch 'master' of https://github.com/famous/famous-angular
imheresamir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/** | ||
* @ngdoc directive | ||
* @name faDeck | ||
* @module famous.angular | ||
* @restrict EA | ||
* @description | ||
* This directive will create a Famo.us Deck containing the | ||
* specified child elements. The provided `options` object | ||
* will pass directly through to the Famo.us faDeck's | ||
* constructor. See [https://famo.us/docs/views/Deck] | ||
* | ||
* @usage | ||
* ```html | ||
* <fa-deck fa-options="scopeOptionsObject" fa-open="scopeOpenVariable"> | ||
* <!-- zero or more render nodes --> | ||
* </fa-deck> | ||
* ``` | ||
* @example | ||
* `Fa-deck` is a Famous SequentialLayout View that can be opened and closed with a transition. Pass options (such as `direction` and `transition`) by binding an object with the property to `fa-options`. | ||
* | ||
* In the example below, an `fa-surface` and an `fa-view` are added to the deck. ng-repeat is used on an `fa-view` and the elements nested below it. The size of each `fa-surface` is `[250, 50]`. | ||
* | ||
* The modifier applied to the `fa-deck` positions it 0.5 across in the X direction and 0.25 down in the Y direction. | ||
* | ||
* A clickHandler() is bound to ng-click on the first surface, which toggles the `fa-deck` open and close actions. | ||
* | ||
<example module="faSequentialExampleApp"> | ||
<file name="index.html"> | ||
<fa-app ng-controller="DeckCtrl"> | ||
<fa-modifier fa-origin="[0.5, 0]" fa-align="[0.5, 0.25]"> | ||
<fa-deck fa-options="deckOptions" fa-open="deckOpen"> | ||
<fa-modifier fa-size="[250, 50]"> | ||
<fa-surface ng-click="clickHandler()" fa-properties="firstSurfaceProperties">Click Me</fa-surface> | ||
</fa-modifier> | ||
<fa-view ng-repeat="item in sequence"> | ||
<fa-modifier fa-size="[250, 50]"> | ||
<fa-surface fa-background-color="item.bgColor">{{ $index }}</fa-surface> | ||
</fa-modifier> | ||
</fa-view> | ||
</fa-deck> | ||
</fa-modifier> | ||
</fa-app> | ||
|
||
<script> | ||
angular.module('faDeckExampleApp', ['famous.angular']) | ||
.controller('DeckCtrl', ['$scope', '$famous', function($scope, $famous) { | ||
$scope.deckOpen = false; | ||
|
||
$scope.clickHandler = function() { | ||
$scope.deckOpen = !$scope.deckOpen; | ||
}; | ||
|
||
$scope.deckOptions = { | ||
direction: 1, // vertical = 1 (default), horizontal = 0 | ||
itemSpacing: 0, | ||
transition: {duration: 200, curve: 'easeInOut'}, | ||
}; | ||
|
||
$scope.firstSurfaceProperties = { | ||
color: 'blue', | ||
backgroundColor: 'white', | ||
border: '1px solid black', | ||
textAlign: 'center' | ||
}; | ||
|
||
$scope.sequence = [{bgColor: "orange"}, {bgColor: "red"}, {bgColor: "green"}, {bgColor: "yellow"}]; | ||
|
||
}]); | ||
</script> | ||
</file> | ||
<file name="style.css"> | ||
fa-app { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
} | ||
</file> | ||
</example> | ||
*/ | ||
|
||
angular.module('famous.angular') | ||
.directive('faDeck', ["$famous", "$famousDecorator", function ($famous, $famousDecorator) { | ||
return { | ||
template: '<div></div>', | ||
restrict: 'E', | ||
transclude: true, | ||
scope: true, | ||
compile: function (tElem, tAttrs, transclude) { | ||
window.$f = $famous; | ||
return { | ||
pre: function (scope, element, attrs) { | ||
var isolate = $famousDecorator.ensureIsolate(scope); | ||
|
||
var Deck = $famous["famous/views/Deck"]; | ||
|
||
var _children = []; | ||
|
||
var options = scope.$eval(attrs.faOptions) || {}; | ||
|
||
isolate.renderNode = new Deck(options); | ||
|
||
$famousDecorator.addRole('renderable',isolate); | ||
isolate.show(); | ||
|
||
var _updateDeck = function() { | ||
_children.sort(function(a, b) { | ||
return a.index - b.index; | ||
}); | ||
isolate.renderNode.sequenceFrom(function(_children) { | ||
var _ch = []; | ||
angular.forEach(_children, function(c, i) { | ||
_ch[i] = c.renderGate; | ||
}); | ||
return _ch; | ||
}(_children)); | ||
}; | ||
|
||
$famousDecorator.sequenceWith( | ||
scope, | ||
function(data) { | ||
_children.push(data); | ||
_updateDeck(); | ||
}, | ||
function(childScopeId) { | ||
_children = function (_children) { | ||
var _ch = []; | ||
angular.forEach(_children, function (c) { | ||
if (c.id !== childScopeId) { | ||
_ch.push(c); | ||
} | ||
}); | ||
return _ch; | ||
}(_children); | ||
_updateDeck(); | ||
} | ||
); | ||
|
||
}, | ||
post: function (scope, element, attrs) { | ||
var isolate = $famousDecorator.ensureIsolate(scope); | ||
var deckOpen = scope.$eval(attrs.faOpen); | ||
|
||
scope.$watch(function(){ | ||
return scope.$eval(attrs.faOpen); | ||
}, function () { | ||
deckOpen = scope.$eval(attrs.faOpen); | ||
(scope.$eval(deckOpen) | ||
|| attrs.faOpen == "true" | ||
|| deckOpen === true | ||
|| scope[attrs.faOpen] === true) ? isolate.renderNode.open() : isolate.renderNode.close(); | ||
}); | ||
|
||
transclude(scope, function (clone) { | ||
element.find('div').append(clone); | ||
}); | ||
|
||
$famousDecorator.registerChild(scope, element, isolate); | ||
} | ||
}; | ||
} | ||
}; | ||
}]); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems weird to store
$famous
intowindow.$f
.