Pig Libs

by phollott

HTML

<!-- ng-app and ng-controller hook AngularJS -->
<div ng-app="libber" ng-controller="libberCtrl" class="left book">
    
<h2>The Pig and the Box: Mad Lib Edition</h2>

    <div class="lib-pick">
        <div>
            <label>An animal:</label>
            <input type="text" ng-model="animal[0]" />
        </div>
        <div>
            <label>Another word for that animal:</label>
            <input type="text" ng-model="animal[1]" />
        </div>
        <div>
            <label>An animal:</label>
            <input type="text" ng-model="animal[2]" />
        </div>
        <div>
            <label>An animal:</label>
            <input type="text" ng-model="animal[3]" />
        </div>
        <div>
            <label>An animal:</label>
            <input type="text" ng-model="animal[4]" />
        </div>
        <div>
            <label>An animal:</label>
            <input type="text" ng-model="animal[5]" />
        </div>
        <div>
            <label>An animal that should never wear a tutu:</label>
            <input type="text" ng-model="animal[6]" />
        </div>
        <div>
            <label>A vegetable:</label>
            <input type="text" ng-model="vegetable[0]" />
        </div>
        <div>
            <label>Another vegetable:</label>
            <input type="text" ng-model="vegetable[1]" />
        </div>
        <div>
            <label>Another vegetable:</label>
            <input type="text" ng-model="vegetable[2]" />
        </div>
        <div>
            <label>A kind of fruit:</label>
            <input type="text" ng-model="fruit[0]" />
        </div>
        <div>
            <label>Another kind of fruit:</label>
            <input type="text" ng-model="fruit[1]" />
        </div>
        <div>
            <label>A questionable fruit:</label>
            <input type="text" ng-model="fruit[2]" />
        </div>
        <div>
            <label>A first name:</label>
            <input type="text" ng-model="name[0]" />
      ...

CSS

body {
    font: 100% georgia, sans-serif;
    line-height: 1.6;
    color: #555753;
}
button {
    font: italic normal 0.8em georgia, sans-serif;
    letter-spacing: 1px;
    color: #7D775C;
}
span.init {
    width: 0.7em;
    font-size: 400%;
    font-family: algerian, courier;
    line-height: 80%;
}
.book {
    position: relative;
    font: 75% georgia, sans-serif;
    width: 420px;
    height: 560px;
    line-height: 1.88889;
    margin-right: 10px;
    padding: 10px;
    background-color: #F5F5DC;
}
.left {
    float: left;
}
.right {
    float: right;
}
div.lib-pick {
    height:88px;
    overflow-y:scroll;
    width:96%;
    border-bottom: thin dotted;
}
.footer {
    position: absolute;
    bottom: 0px;
    left: 310px;
    height: 28px;
}
div.header {
    visibility: hidden;
}
div.nav {
    position: absolute;
    top: 0px;
}

JavaScript

// Angular allows you to write more modular code
angular.module('libber', []);

// Angular controllers provide initialization 
angular.module('libber')
    .controller('libberCtrl',

function ($scope) {
    $scope.pageId = "1"
    $scope.animal = ['pig', 'hog', 'duck', 'bunny', 'turtle', 'squirrel', 'cow']
    $scope.vegetable = ['turnip', 'carrot', 'potato']
    $scope.fruit = ['apple', 'banana', 'coconut']
    $scope.name = ['Maurice']

    // the main function sets page id for show/hide
    $scope.turnPage = function (in_page) {
        $scope.pageId = in_page
    }
});

// Angular custom directive - like a custom tag
angular.module('libber')
    .directive('choose', function () {
    return {
        template: '<button class="right"  ng-click="$parent.turnPage(page)">{{desc}} - go to page {{page}}</button>',
    }
});

// Angular allows you to add simple text filters
angular.module('libber')
    .filter('capitalize', function () {
    return function (input) {
        return input.substring(0, 1).toUpperCase() + input.substring(1);
    }
});


libber.directive('pick', function () {
    return {
        transclude: true
/*        template: '<div>baba' +
            '<label>Hey:</label>' +
            '<ng-transclude></ng-transclude>' +
            '</div>' */
    }
});