Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

<div ng-view></div>

<footer>
<div ng-include='"partials/form-releases.html"'></div>
</footer>

<!-- In production use:
<script src="//ajax.googleapis.com/ajax/libs/angularjs/x.x.x/angular.min.js"></script>
-->
Expand Down
17 changes: 17 additions & 0 deletions app/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,21 @@ angular.module('myApp.controllers', [])
}
});
});
}])
.controller('RefCtrl', ['$scope', '$location', '$window', 'Prismic', function ($scope, $location, $window, Prismic) {
Prismic.ctx().then(function(ctx){
// Get available refs.
$scope.refs = ctx.api.data.refs;
// Find selected release based on URL query.
var release = _.where($scope.refs, {ref: $location.search().ref});
$scope.selectedRelease = release.length > 0 ? release[0] : $scope.refs[0];
$scope.newRef = function(selected) {
// When select element changed, update ctx object and configure
// $location service.
ctx.ref = selected.ref;
$location.path($location.path()).search({'ref': selected.ref});
// Alternatively, you can reload the page.
// $window.location.href = $location.path()+"?ref="+selected.ref;
}
});
}]);
3 changes: 3 additions & 0 deletions app/partials/form-releases.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<form ng-controller="RefCtrl">
<select ng-show="refs.length" name="ref" ng-model="selectedRelease" ng-options="ref.label for ref in refs" ng-change="newRef(selectedRelease)"></select>
</form>