var $scope;
var app = angular.module('app', []);
/**
* Creates an ng-repeat with an overflow area to enable inline editing with overflow.
*
* Nesting is not supported.
*/
app.directive('editableCollection', function factory($compile) {
return {
link: function (scope, el, attrs, controller) {
//parse the element and attributes
if (!attrs.expandingOn) {
throw 'Expected exanding-on attribute on element: '
+ el.html() + '\n but found: '
+ JSON.stringify(attrs.$attr) + '\n';
}
var split = attrs.editableCollection.split(' ');
var elementName = split[0];
var collectionName = split[2];
if (split.length != 3 || split[1] != 'in') {
throw 'Expected editable collection defined as "{element} in {collection}" got: '
+ attrs.editableCollection;
}
//Take the elements from this one to move to a child ng-repeat
var original = el.contents();
//Add the ng-repeat for the actual collection
var repeater = angular.element('<div/>');
repeater.attr('ng-repeat', attrs.editableCollection);
repeater.append(original);
el.append(repeater);
//Add the ng-repeat for the overflow
var overflowId = 'shouldBeUniquelyGeneratedToAvoidCollisions';
console.log('Created overflow with id: '+overflowId+ ' for '+collectionName);
scope[overflowId] = [
{}
];
var overflow = repeater.clone();
overflow.attr('ng-repeat',
elementName + ' in ' + overflowId);
el.append(overflow);
//Watch the first element and expand the overflow if needed
scope.$watch(overflowId+'[0].' + attrs.expandingOn, function (value) {
if (value && scope[overflowId].length < 2) {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.