Dan Brown

Started transfer to angularjs

...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
5 "insert-css": "^0.2.0" 5 "insert-css": "^0.2.0"
6 }, 6 },
7 "dependencies": { 7 "dependencies": {
8 + "angular": "^1.5.0-rc.0",
9 + "angular-resource": "^1.5.0-rc.0",
8 "babel-runtime": "^5.8.29", 10 "babel-runtime": "^5.8.29",
9 "bootstrap-sass": "^3.0.0", 11 "bootstrap-sass": "^3.0.0",
10 "dropzone": "^4.0.1", 12 "dropzone": "^4.0.1",
......
1 +<div class="toggle-switch" ng-click="switch()" ng-class="{'active': isActive}">
2 + <input type="hidden" ng-attr-name="{{name}}" ng-attr-value="{{value}}"/>
3 + <div class="switch-handle"></div>
4 +</div>
...\ No newline at end of file ...\ No newline at end of file
1 -
2 -<template>
3 - <div class="toggle-switch" @click="switch" :class="{'active': isActive}">
4 - <input type="hidden" :name="name" :value="value"/>
5 - <div class="switch-handle"></div>
6 - </div>
7 -</template>
8 -
9 -
10 -<script>
11 - module.exports = {
12 - props: ['name', 'value'],
13 - data: function() {
14 - return {
15 - isActive: this.value == true && this.value != 'false'
16 - }
17 - },
18 - ready: function() {
19 - this.value = (this.value == true && this.value != 'false') ? 'true' : 'false';
20 - },
21 - methods: {
22 - switch: function() {
23 - this.isActive = !this.isActive;
24 - this.value = this.isActive ? 'true' : 'false';
25 - }
26 - }
27 - };
28 -</script>
...\ No newline at end of file ...\ No newline at end of file
1 +
2 +var toggleSwitchTemplate = require('./components/toggle-switch.html');
3 +
4 +module.exports = function(ngApp) {
5 +
6 + /**
7 + * Toggle Switches
8 + * Have basic on/off functionality.
9 + * Use string values of 'true' & 'false' to dictate the current state.
10 + */
11 + ngApp.directive('toggleSwitch', function() {
12 + return {
13 + restrict: 'E',
14 + template: toggleSwitchTemplate,
15 + scope: true,
16 + link: function(scope, element, attrs) {
17 + scope.name = attrs.name;
18 + scope.value = attrs.value;
19 + scope.isActive = scope.value == true && scope.value != 'false';
20 + scope.value = (scope.value == true && scope.value != 'false') ? 'true' : 'false';
21 +
22 + scope.switch = function() {
23 + scope.isActive = !scope.isActive;
24 + scope.value = scope.isActive ? 'true' : 'false';
25 + }
26 +
27 + }
28 + };
29 + });
30 +
31 +
32 +};
...\ No newline at end of file ...\ No newline at end of file
1 +// Configure ZeroClipboard
1 window.ZeroClipboard = require('zeroclipboard'); 2 window.ZeroClipboard = require('zeroclipboard');
2 window.ZeroClipboard.config({ 3 window.ZeroClipboard.config({
3 swfPath: '/ZeroClipboard.swf' 4 swfPath: '/ZeroClipboard.swf'
4 }); 5 });
5 6
7 +// AngularJS - Create application and load components
8 +var angular = require('angular');
9 +var angularResource = require('angular-resource');
10 +var app = angular.module('bookStack', ['ngResource']);
11 +var directives = require('./directives')(app);
12 +
6 // Global jQuery Elements 13 // Global jQuery Elements
7 $(function () { 14 $(function () {
8 15
...@@ -23,32 +30,8 @@ $(function () { ...@@ -23,32 +30,8 @@ $(function () {
23 30
24 }); 31 });
25 32
26 -function elemExists(selector) {
27 - return document.querySelector(selector) !== null;
28 -}
29 -
30 // TinyMCE editor 33 // TinyMCE editor
31 if(elemExists('#html-editor')) { 34 if(elemExists('#html-editor')) {
32 var tinyMceOptions = require('./pages/page-form'); 35 var tinyMceOptions = require('./pages/page-form');
33 tinymce.init(tinyMceOptions); 36 tinymce.init(tinyMceOptions);
34 } 37 }
...\ No newline at end of file ...\ No newline at end of file
35 -
36 -// Vue JS elements
37 -var Vue = require('vue');
38 -Vue.use(require('vue-resource'));
39 -
40 -// Vue Components
41 -Vue.component('image-manager', require('./components/image-manager.vue'));
42 -Vue.component('image-picker', require('./components/image-picker.vue'));
43 -Vue.component('toggle-switch', require('./components/toggle-switch.vue'));
44 -
45 -// Vue Controllers
46 -if(elemExists('#book-dashboard')) {
47 - new Vue(require('./pages/book-show'));
48 -}
49 -
50 -// Global Vue Instance
51 -// Needs to be loaded after all components we want to use.
52 -var app = new Vue({
53 - el: '#app'
54 -});
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
19 19
20 @yield('head') 20 @yield('head')
21 </head> 21 </head>
22 -<body class="@yield('body-class')" id="app"> 22 +<body class="@yield('body-class')" ng-app="bookStack">
23 23
24 @include('partials/notifications') 24 @include('partials/notifications')
25 25
......