|
16 | 16 | header('Content-Type: application/json'); |
17 | 17 | echo json_encode(array('diff' => $diff->getDifference())); |
18 | 18 | } else { |
19 | | - ?> |
20 | | - <html ng-app="demo"> |
21 | | - <head> |
22 | | - <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script> |
23 | | - <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-sanitize.min.js"></script> |
24 | | - <style> |
25 | | - .row { |
26 | | - width: 90%; |
27 | | - clear: both; |
28 | | - margin: 0 auto; |
29 | | - } |
30 | | - .html-edit { |
31 | | - float: left; |
32 | | - width: 45%; |
33 | | - position: relative; |
34 | | - } |
35 | | - .html-preview { |
36 | | - float: right; |
37 | | - width: 45%; |
38 | | - border: 1px solid #999; |
39 | | - height: 200px; |
40 | | - overflow: auto; |
41 | | - padding: 5px; |
42 | | - } |
43 | | - textarea { |
44 | | - width: 100%; |
45 | | - height: 210px; |
46 | | - } |
47 | | - </style> |
48 | | - </head> |
49 | | - <body> |
50 | | - <div ng-controller="diffCtrl"> |
51 | | - <div class="controls row"> |
52 | | - <button ng-click="reset()">RESET</button> |
53 | | - <span ng-repeat="demo in demos"> |
54 | | - <button ng-click="diffDemo($index)">DEMO {{$index + 1}}</button> |
55 | | - </span> |
56 | | - </div> |
57 | | - |
58 | | - <div class="row"> |
59 | | - <h2>Old HTML</h2> |
60 | | - <div class="html-edit"> |
61 | | - <textarea ng-model="oldText" name="old_text" ng-change="update()"></textarea> |
62 | | - </div> |
63 | | - <div class="html-preview" ng-bind-html="trustHtml(oldText)"></div> |
64 | | - </div> |
65 | | - <div class="row"> |
66 | | - <h2>New HTML</h2> |
67 | | - <div class="html-edit"> |
68 | | - <textarea ng-model="newText" name="new_text" ng-change="update()"></textarea> |
69 | | - </div> |
70 | | - <div class="html-preview" ng-bind-html="trustHtml(newText)"></div> |
71 | | - </div> |
72 | | - |
73 | | - <div class="row"> |
74 | | - <h2>Compared HTML <span ng-show="loading || waiting">- {{ loading ? 'Loading' : 'Waiting' }}...</span></h2> |
75 | | - <div class="html-edit"> |
76 | | - <textarea ng-model="diff" name="diff" disabled ng-change="update()"></textarea> |
77 | | - </div> |
78 | | - <div class="html-preview" ng-bind-html="trustHtml(diff)"></div> |
79 | | - </div> |
80 | | - </div> |
81 | | - |
82 | | - <script type="text/javascript"> |
83 | | - var demo = angular.module('demo', ['ngSanitize']); |
84 | | - |
85 | | - demo.controller('diffCtrl', ['$scope', '$http', '$sce', '$timeout', function ($scope, $http, $sce, $timeout) { |
86 | | - $scope.demos = []; |
87 | | - $scope.updateDelay = 800; |
88 | | - $scope.currentTimeout = null; |
89 | | - $scope.loading = false; |
90 | | - $scope.waiting = false; |
91 | | - |
92 | | - $scope.trustHtml = function (text) { |
93 | | - return typeof text !== 'undefined' ? $sce.trustAsHtml(text) : ''; |
94 | | - }; |
95 | | - |
96 | | - $scope.reset = function () { |
97 | | - $scope.oldText = ''; |
98 | | - $scope.newText = ''; |
99 | | - $scope.diff = ''; |
100 | | - $scope.loading = false; |
101 | | - $scope.waiting = false; |
102 | | - if ($scope.currentTimeout) { |
103 | | - $timeout.cancel($scope.currentTimeout); |
104 | | - } |
105 | | - } |
106 | | - |
107 | | - $scope.update = function () { |
108 | | - if ($scope.currentTimeout) { |
109 | | - $timeout.cancel($scope.currentTimeout); |
110 | | - } |
111 | | - $scope.currentTimeout = $timeout(function () { |
112 | | - $scope.getDiff(); |
113 | | - }, $scope.updateDelay); |
114 | | - |
115 | | - $scope.waiting = true; |
116 | | - }; |
117 | | - |
118 | | - $scope.getDiff = function () { |
119 | | - $scope.waiting = false; |
120 | | - $scope.loading = true; |
121 | | - $http.post('index.php', { oldText: $scope.oldText, newText: $scope.newText }) |
122 | | - .success(function (data) { |
123 | | - $scope.diff = data.diff; |
124 | | - $scope.loading = false; |
125 | | - }); |
126 | | - }; |
127 | | - |
128 | | - $scope.loadDemos = function () { |
129 | | - $http.get('demo_text.php') |
130 | | - .success(function (data) { |
131 | | - $scope.demos = data; |
132 | | - }); |
133 | | - }; |
134 | | - |
135 | | - $scope.diffDemo = function (index) { |
136 | | - if (typeof index === 'undefined') { |
137 | | - index = 0; |
138 | | - } |
139 | | - |
140 | | - $scope.oldText = $scope.demos[index]['old']; |
141 | | - $scope.newText = $scope.demos[index]['new']; |
142 | | - $scope.getDiff(); |
143 | | - }; |
144 | | - |
145 | | - $scope.loadDemos(); |
146 | | - }]); |
147 | | - </script> |
148 | | - </body> |
149 | | - </html> |
150 | | - |
151 | | - <?php |
| 19 | + header('Content-Type: text/html'); |
| 20 | + echo file_get_contents('demo.html'); |
152 | 21 | } |
0 commit comments