Skip to content

Commit e16eb87

Browse files
author
André König
committed
[Feature] Functionality for passing inline templates.
1 parent f1608b6 commit e16eb87

File tree

8 files changed

+69
-24
lines changed

8 files changed

+69
-24
lines changed

CONTRIBUTORS

Lines changed: 0 additions & 8 deletions
This file was deleted.

CONTRIBUTORS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# angular-deckgrid - contributors
2+
3+
_(ordered by first contribution)_
4+
5+
- [Ben Ma](http://github.com/benjaminma)
6+
- [Mike](http://github.com/mikenikles)
7+
- [Mladen Danic ](http://github.com/Maidomax)
8+
- [Patrick Stapleton](http://github.com/gdi2290)
9+
- [johnwest80](http://github.com/johnwest80)
10+
- [Sebastian Oergel](http://github.com/sebastianoe)

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ Do you use the `angular-deckgrid` and would like to be featured here? Just send
141141

142142
## Changelog
143143

144+
### Version 0.4.0 (20140224)
145+
146+
- [Feature] Functionality for passing inline templates.
147+
144148
### Version 0.3.0 (20140220)
145149

146150
- [Feature] It is now possible to access the index of a card from within the card's template. This is accessible via the $index property of the card reference like {{card.$index}}.
@@ -171,6 +175,7 @@ Do you use the `angular-deckgrid` and would like to be featured here? Just send
171175

172176
## Credits
173177

178+
* All the [people](https://github.com/akoenig/angular-deckgrid/blob/master/CONTRIBUTORS.md) who made outstanding contributions to the `angular-deckgrid` so far.
174179
* [AngularJS](http://angularjs.org) Needless to say. You know the beast. One of the best frontend frameworks in the world.
175180
* [Rolando Murillo](http://rolandomurillo.com/) and [Giorgio Leveroni](https://github.com/ppold), the guys behind [salvattore](http://salvattore.com/) who inspired me to implement a similar solution for the AngularJS world.
176181

angular-deckgrid.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! angular-deckgrid (v0.3.1-dev) - Copyright: 2013 - 2014, André König ([email protected]) - MIT */
1+
/*! angular-deckgrid (v0.4.0) - Copyright: 2013 - 2014, André König ([email protected]) - MIT */
22
/*
33
* angular-deckgrid
44
*
@@ -41,8 +41,9 @@ angular.module('akoenig.deckgrid').directive('deckgrid', [
4141
angular.module('akoenig.deckgrid').factory('DeckgridDescriptor', [
4242

4343
'Deckgrid',
44+
'$templateCache',
4445

45-
function initialize (Deckgrid) {
46+
function initialize (Deckgrid, $templateCache) {
4647

4748
'use strict';
4849

@@ -66,7 +67,7 @@ angular.module('akoenig.deckgrid').factory('DeckgridDescriptor', [
6667
// Will be created in the linking function.
6768
//
6869
this.$$deckgrid = null;
69-
70+
this.transclude = true;
7071
this.link = this.$$link.bind(this);
7172
}
7273

@@ -87,10 +88,41 @@ angular.module('akoenig.deckgrid').factory('DeckgridDescriptor', [
8788
* The deckgrid link method. Will instantiate the deckgrid.
8889
*
8990
*/
90-
Descriptor.prototype.$$link = function $$link (scope, elem, attrs) {
91+
Descriptor.prototype.$$link = function $$link (scope, elem, attrs, nullController, transclude) {
9192
scope.$on('$destroy', this.$$destroy.bind(this));
9293

93-
scope.cardTemplate = attrs.cardtemplate;
94+
if (attrs.cardtemplate === undefined) {
95+
if (attrs.cardtemplatestring === undefined) {
96+
// use the provided inner html as template
97+
transclude(scope, function onTransclude (innerHTML) {
98+
var extractedInnerHTML = [],
99+
i = 0,
100+
len = innerHTML.length,
101+
outerHTML;
102+
103+
for (i; i < len; i = i + 1) {
104+
outerHTML = innerHTML[i].outerHTML;
105+
106+
if (outerHTML !== undefined) {
107+
extractedInnerHTML.push(outerHTML);
108+
}
109+
}
110+
111+
$templateCache.put('innerHtmlTemplate', extractedInnerHTML.join());
112+
});
113+
} else {
114+
// use the provided template string
115+
//
116+
// note: the attr is accessed via the elem object, as the attrs content
117+
// is already compiled and thus lacks the {{...}} expressions
118+
$templateCache.put('innerHtmlTemplate', elem.attr('cardtemplatestring'));
119+
}
120+
121+
scope.cardTemplate = 'innerHtmlTemplate';
122+
} else {
123+
// use the provided template file
124+
scope.cardTemplate = attrs.cardtemplate;
125+
}
94126

95127
scope.mother = scope.$parent;
96128

angular-deckgrid.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-deckgrid",
3-
"version": "0.3.1-dev",
3+
"version": "0.4.0",
44
"author": "André König ([email protected])",
55
"description": "A lightweight masonry-like grid for AngularJS.",
66
"license": "MIT",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-deckgrid",
3-
"version": "0.3.1-dev",
3+
"version": "0.4.0",
44
"author": "André König ([email protected])",
55
"description": "A lightweight masonry-like grid for AngularJS.",
66
"license": "MIT",

src/descriptor.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,21 @@ angular.module('akoenig.deckgrid').factory('DeckgridDescriptor', [
6767
if (attrs.cardtemplate === undefined) {
6868
if (attrs.cardtemplatestring === undefined) {
6969
// use the provided inner html as template
70-
transclude(scope, function(innerHtml) {
71-
var extractedInnerHtml = [];
72-
for (var i = 0; i < innerHtml.length; i++) {
73-
var outerHTML = innerHtml[i].outerHTML;
70+
transclude(scope, function onTransclude (innerHTML) {
71+
var extractedInnerHTML = [],
72+
i = 0,
73+
len = innerHTML.length,
74+
outerHTML;
75+
76+
for (i; i < len; i = i + 1) {
77+
outerHTML = innerHTML[i].outerHTML;
78+
7479
if (outerHTML !== undefined) {
75-
extractedInnerHtml.push(outerHTML);
80+
extractedInnerHTML.push(outerHTML);
7681
}
7782
}
78-
$templateCache.put('innerHtmlTemplate', extractedInnerHtml.join());
83+
84+
$templateCache.put('innerHtmlTemplate', extractedInnerHTML.join());
7985
});
8086
} else {
8187
// use the provided template string
@@ -90,7 +96,7 @@ angular.module('akoenig.deckgrid').factory('DeckgridDescriptor', [
9096
// use the provided template file
9197
scope.cardTemplate = attrs.cardtemplate;
9298
}
93-
99+
94100
scope.mother = scope.$parent;
95101

96102
this.$$deckgrid = Deckgrid.create(scope, elem[0]);

0 commit comments

Comments
 (0)