Search code examples
javascriptcssangularjszurb-foundation-5

Foundation 5 clearing lightbox not working with angularjs dynamic images


I'm trying to use the clearing lightbox component from Zurb Foundation 5 into my angularjs application but I haven't found the way, example code here:

Using the code below what I get is a mess but it should look like the Foundation Clearing documentation

<html>
<head>
    <title>TODO supply a title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width">
    <link href="http://cdn.foundation5.zurb.com/foundation.css" rel="stylesheet"/>
</head>
<body>       
    <div ng-app="app" ng-controller="ClearingController">
        <ul class="clearing-thumbs large-12 columns small-block-grid-4" data-clearing>
            <li ng-repeat="imagen in imagenes"><a href="{{imagen}}"><img ng-src="{{imagen}}"></a></li>
        </ul>
    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.foundation5.zurb.com/foundation.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <script type="text/javascript">
                angular.module('app', [])
                        .controller('ClearingController', ['$scope', function($scope) {
                                $scope.imagenes = ["http://placehold.it/1000x1000&text=image1", "http://placehold.it/1000x1000&text=image2", "http://placehold.it/1000x1000&text=image3", "http://placehold.it/1000x1000&text=image4", "http://placehold.it/1000x1000&text=image5", "http://placehold.it/1000x1000&text=image6", "http://placehold.it/1000x1000&text=image7", "http://placehold.it/1000x1000&text=image8"];
                                $(document).foundation();
                            }]);

    </script>
</body>
</html>

Do anyone have an idea about how to make it work?


Solution

  • while testing it threw Uncaught ReferenceError: Modernizr is not defined so added http://www.modernizr.com/downloads/modernizr-latest.js, internally used by foundation.js

    as per the documentation $(document).foundation(); should be before </body> and $(document).foundation(); initialize Foundation scripts so moved out of the angular scope.

    example : http://codepen.io/anon/pen/eNwGQq