/** * Define the angular app */ 'use strict'; var app = (function () { Helpers.validateSaveVersion(); var app = angular.module('scienceAlchemy', ['ngDragDrop', 'ui.grid','ngAnimate']); // directives /** * Provides an easy way to toggle a checkboxes indeterminate property * * @example */ // app.directive('uiIndeterminate', [ // function () { // // return { // compile: function (tElm, tAttrs) { // if (!tAttrs.type || tAttrs.type.toLowerCase() !== 'checkbox') { // return angular.noop; // } // // return function ($scope, elm, attrs) { // $scope.$watch(attrs.uiIndeterminate, function (newVal) { // elm[0].indeterminate = !!newVal; // }); // }; // } // }; // } // ]); /** * Make little score animations when score changes require ng-model="score" */ function cfsScoreChange($compile) { return { link: function (scope, element, attrs) { scope.$watch(attrs.ngModel, function (newValue, oldValue) { console.log('value changed, new value is: ' + newValue, oldValue); // showUpdateValue var num = newValue-oldValue; var formatted = Helpers.formatNumberPostfix(num); var insert; if (num > 0) { insert = angular.element("
") .attr("class", "update-plus") .html("+" + formatted); } else { insert = angular.element("
") .attr("class", "update-minus") .html(formatted); } // showUpdate element.append(insert); insert.animate({ "bottom":"+=30px", "opacity": 0 }, { duration: 500, complete: function() { angular.element(this).remove(); }}); }); } }; }; cfsScoreChange.$inject = ['$compile']; app.directive('cfsScoreChange', cfsScoreChange); /** * Directive to render a rule and bind it's option with select boxes * This expects ng-model="rule" as an attribute */ function cfsRule($compile) { return { link: function (scope, element, attrs) { var rule = scope.$eval(attrs.ngModel); // first generate a select box for each option (using lodash templating) _.templateSettings.interpolate = /<%=([\s\S]+?)%>/g; var optionTmpl = '' + '\n'; var tmplParams = _.defaults({},rule.options,rule.otherOptions); for (var option in rule.optionDesc) { if (rule.optionDesc.hasOwnProperty(option)) { var vals = rule.optionDesc[option].possibleVals; if (vals) { tmplParams[option] = _.template(optionTmpl)({ option: option }); } else { // if there are no options replace '{{color}}' with 'color' tmplParams[option] = option; } } } // now put each select box into description // replace '{{color}}' with '