|
20 | 20 | /* global textInputHasFocus */
|
21 | 21 |
|
22 | 22 | /*
|
23 |
| - * Copyright (c) 2016, 2017 Oracle and/or its affiliates. All rights reserved. |
| 23 | + * Copyright (c) 2016, 2019 Oracle and/or its affiliates. All rights reserved. |
24 | 24 | */
|
25 | 25 |
|
26 | 26 | /*
|
|
34 | 34 | */
|
35 | 35 | (function (window, $window) {
|
36 | 36 | if (!$window || typeof $window.create !== 'function') {
|
37 |
| - console.log('The diffWindow plugin requires $.window plugin') |
| 37 | + console.log('The diffWindow plugin requires $.window plugin'); |
38 | 38 | return;
|
39 | 39 | }
|
40 | 40 |
|
41 | 41 | var diffWindow = function () {
|
42 | 42 | this.init = function (options, context) {
|
43 |
| - return $.diffWindow = $window.create(options = $.extend({ |
| 43 | + $.diffWindow = $window.create($.extend({ |
44 | 44 | title: 'Diff jumper',
|
45 | 45 | draggable: false,
|
46 | 46 | init: function ($window) {
|
47 |
| - var $prev, $next |
48 |
| - var that = this |
| 47 | + var $prev; |
| 48 | + var $next; |
| 49 | + var that = this; |
49 | 50 |
|
50 | 51 | // set initial position by the toggle button
|
51 | 52 | that.options.$toggleButton.each(function () {
|
|
66 | 67 | left: $(this).offset().left + $(this).outerWidth(),
|
67 | 68 | opacity: 0
|
68 | 69 | }, that.options.animationDuration, function () {
|
69 |
| - that.$window.hide() |
| 70 | + that.$window.hide(); |
70 | 71 | $(this).data("animation-in-progress", null);
|
71 | 72 | });
|
72 | 73 | $(this).data("animation-in-progress", "hiding");
|
|
78 | 79 | opacity: 1
|
79 | 80 | }, that.options.animationDuration, function () {
|
80 | 81 | $(this).data("animation-in-progress", null);
|
81 |
| - }) |
| 82 | + }); |
82 | 83 | $(this).data("animation-in-progress", "showing");
|
83 | 84 | }
|
84 |
| - return false |
| 85 | + return false; |
85 | 86 | });
|
86 | 87 |
|
87 |
| - var $controls = $("<div class=\"pull-right\">") |
88 |
| - .append($prev = $("<a href='#' class='prev' title='Jump to previous chunk (shortcut b)'><< Previous</a>")) |
89 |
| - .append("<span class=\"pull-rigt\"> | </span>") |
90 |
| - .append($next = $("<a href='#' class='next' title='Jump to next chunk (shortcut n)'>Next >></a>")) |
91 |
| - .append($("<div class=\"clearfix\">")) |
| 88 | + var $controls = $('<div class="pull-right">'). |
| 89 | + append($prev = $('<a href="#" class="prev" title="Jump to previous chunk (shortcut b)"><< Previous</a>')). |
| 90 | + append('<span class="pull-rigt"> | </span>'). |
| 91 | + append($next = $('<a href="#" class="next" title="Jump to next chunk (shortcut n)">Next >></a>')). |
| 92 | + append($('<div class="clearfix">')); |
92 | 93 |
|
93 | 94 | $next.click(function (e) {
|
94 | 95 | that.nextHandler.apply(that, [e]);
|
|
105 | 106 | that.options.$toggleButton.outerWidth(),
|
106 | 107 | opacity: 0
|
107 | 108 | }, that.options.animationDuration, function () {
|
108 |
| - that.$window.hide() |
| 109 | + that.$window.hide(); |
109 | 110 | that.options.$toggleButton.data("animation-in-progress", null);
|
110 | 111 | });
|
111 | 112 | that.options.$toggleButton.data("animation-in-progress", "hiding");
|
112 | 113 | });
|
113 | 114 |
|
114 |
| - return $window |
115 |
| - .attr('id', 'diff_win') |
116 |
| - .addClass('diff-window') |
117 |
| - .addClass('diff_navigation_style') |
118 |
| - .css({ |
| 115 | + return $window. |
| 116 | + attr('id', 'diff_win'). |
| 117 | + addClass('diff-window'). |
| 118 | + addClass('diff_navigation_style'). |
| 119 | + css({ |
119 | 120 | top: '150px',
|
120 | 121 | right: '20px',
|
121 |
| - 'min-width': '300px'}) |
122 |
| - .body() |
123 |
| - .append($controls) |
124 |
| - .append(this.$summary) |
125 |
| - .append(this.$progress) |
126 |
| - .window() |
| 122 | + 'min-width': '300px'}). |
| 123 | + body(). |
| 124 | + append($controls). |
| 125 | + append(this.$summary). |
| 126 | + append(this.$progress). |
| 127 | + window(); |
127 | 128 | },
|
128 | 129 | load: function ($window) {
|
129 |
| - var that = this |
| 130 | + var that = this; |
130 | 131 | $(document).keypress(function (e) {
|
131 | 132 | if (textInputHasFocus()) {
|
132 | 133 | return true;
|
133 | 134 | }
|
134 |
| - var key = e.keyCode || e.which |
| 135 | + var key = e.keyCode || e.which; |
135 | 136 | switch (key) {
|
136 | 137 | case 110: // n
|
137 |
| - that.nextHandler(e) |
| 138 | + that.nextHandler(e); |
138 | 139 | break;
|
139 | 140 | case 98: // b
|
140 |
| - that.prevHandler(e) |
| 141 | + that.prevHandler(e); |
141 | 142 | break;
|
142 | 143 | default:
|
143 | 144 | }
|
144 | 145 | });
|
145 | 146 | },
|
146 | 147 | update: function (data) {
|
147 | 148 | var index = this.currentIndex < 0 ? 1 : (this.currentIndex + 1);
|
148 |
| - this.$summary.text(index + "/" + this.$changes.length + " chunks") |
| 149 | + this.$summary.text(index + "/" + this.$changes.length + " chunks"); |
149 | 150 | }
|
150 | 151 | }, options || {
|
151 | 152 | /*
|
|
172 | 173 | $progress: $('<div>').css('text-align', 'center'),
|
173 | 174 | $summary: $('<div>'),
|
174 | 175 | initChanges: function () {
|
175 |
| - if (this.$changes.length) |
| 176 | + if (this.$changes.length) { |
176 | 177 | return;
|
| 178 | + } |
177 | 179 | // is diff in table (udiff/sdiff) or just html text (new/old diff)?
|
178 |
| - var isTable = this.options.$parent.find("table").length > 0 |
| 180 | + var isTable = this.options.$parent.find("table").length > 0; |
179 | 181 | // get all changes
|
180 | 182 | this.$changes = isTable ? this.options.$parent.find(this.options.chunkSelector) :
|
181 |
| - this.options.$parent.find(this.options.addSelector + "," + this.options.delSelector) |
| 183 | + this.options.$parent.find(this.options.addSelector + "," + this.options.delSelector); |
182 | 184 | this.$window.update();
|
183 | 185 | },
|
184 | 186 | progress: function (str) {
|
185 |
| - var $span = $("<p>" + str + "</p>") |
186 |
| - .animate({opacity: "0.2"}, 1000) |
| 187 | + var $span = $("<p>" + str + "</p>").animate({opacity: "0.2"}, 1000); |
187 | 188 | $span.hide('fast', function () {
|
188 | 189 | $span.remove();
|
189 | 190 | });
|
190 |
| - this.$progress.html($span) |
| 191 | + this.$progress.html($span); |
191 | 192 | },
|
192 | 193 | scrollTop: function ($el) {
|
193 | 194 | if (this.options.scrollTop) {
|
194 |
| - this.options.scrollTop($el) |
| 195 | + this.options.scrollTop($el); |
195 | 196 | } else {
|
196 | 197 | $('html, body').stop().animate({
|
197 | 198 | scrollTop: $el.position().top - this.options.$parent.offset().top
|
|
200 | 201 | return this;
|
201 | 202 | },
|
202 | 203 | prevHandler: function (e) {
|
203 |
| - e.preventDefault() |
| 204 | + e.preventDefault(); |
204 | 205 | this.initChanges();
|
205 |
| - var $current = $(this.$changes[this.currentIndex - 1]) |
| 206 | + var $current = $(this.$changes[this.currentIndex - 1]); |
206 | 207 |
|
207 | 208 | if (!$current.length) {
|
208 |
| - this.$window.error("No previous chunk!") |
209 |
| - return false |
| 209 | + this.$window.error("No previous chunk!"); |
| 210 | + return false; |
210 | 211 | }
|
211 | 212 |
|
212 | 213 | this.currentIndex--;
|
213 |
| - this.progress("Going to chunk " + (this.currentIndex + 1) + "/" + this.$changes.length) |
| 214 | + this.progress("Going to chunk " + (this.currentIndex + 1) + "/" + this.$changes.length); |
214 | 215 | this.scrollTop($current);
|
215 | 216 | this.$window.update();
|
216 |
| - return false |
| 217 | + return false; |
217 | 218 | },
|
218 | 219 | nextHandler: function (e) {
|
219 |
| - e.preventDefault() |
| 220 | + e.preventDefault(); |
220 | 221 | this.initChanges();
|
221 |
| - var $current = $(this.$changes[this.currentIndex + 1]) |
| 222 | + var $current = $(this.$changes[this.currentIndex + 1]); |
222 | 223 | if (!$current.length) {
|
223 |
| - this.$window.error("No next chunk!") |
224 |
| - return false |
| 224 | + this.$window.error("No next chunk!"); |
| 225 | + return false; |
225 | 226 | }
|
226 | 227 | this.currentIndex++;
|
227 |
| - this.progress("Going to chunk " + (this.currentIndex + 1) + "/" + this.$changes.length) |
| 228 | + this.progress("Going to chunk " + (this.currentIndex + 1) + "/" + this.$changes.length); |
228 | 229 | this.scrollTop($current);
|
229 |
| - this.$window.update() |
230 |
| - return false |
231 |
| - }, |
| 230 | + this.$window.update(); |
| 231 | + return false; |
| 232 | + } |
232 | 233 | }, context || {}));
|
233 |
| - } |
| 234 | + return $.diffWindow; |
| 235 | + }; |
234 | 236 | };
|
235 |
| - $.diffWindow = new ($.extend(diffWindow, $.diffWindow ? $.diffWindow : {})); |
| 237 | + $.diffWindow = new ($.extend(diffWindow, $.diffWindow ? $.diffWindow : {}))(); |
236 | 238 | }(window, $.window));
|
237 | 239 |
|
238 | 240 | // Code to be called when the DOM for diff.jsp is ready.
|
|
0 commit comments