Update upstream source from tag 'upstream/3.8.3+dfsg'
Update to upstream version '3.8.3+dfsg'
with Debian dir 2698e18241bca7699b578dd61876d749f0632a5e
Pirate Praveen
5 years ago
0 | (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | |
1 | (function() { | |
2 | var Connector, PROTOCOL_6, PROTOCOL_7, Parser, Version, _ref; | |
3 | ||
4 | _ref = require('./protocol'), Parser = _ref.Parser, PROTOCOL_6 = _ref.PROTOCOL_6, PROTOCOL_7 = _ref.PROTOCOL_7; | |
5 | ||
6 | Version = '2.2.2'; | |
7 | ||
8 | exports.Connector = Connector = (function() { | |
9 | function Connector(options, WebSocket, Timer, handlers) { | |
10 | this.options = options; | |
11 | this.WebSocket = WebSocket; | |
12 | this.Timer = Timer; | |
13 | this.handlers = handlers; | |
14 | this._uri = "ws" + (this.options.https ? "s" : "") + "://" + this.options.host + ":" + this.options.port + "/livereload"; | |
15 | this._nextDelay = this.options.mindelay; | |
16 | this._connectionDesired = false; | |
17 | this.protocol = 0; | |
18 | this.protocolParser = new Parser({ | |
19 | connected: (function(_this) { | |
20 | return function(protocol) { | |
21 | _this.protocol = protocol; | |
22 | _this._handshakeTimeout.stop(); | |
23 | _this._nextDelay = _this.options.mindelay; | |
24 | _this._disconnectionReason = 'broken'; | |
25 | return _this.handlers.connected(protocol); | |
26 | }; | |
27 | })(this), | |
28 | error: (function(_this) { | |
29 | return function(e) { | |
30 | _this.handlers.error(e); | |
31 | return _this._closeOnError(); | |
32 | }; | |
33 | })(this), | |
34 | message: (function(_this) { | |
35 | return function(message) { | |
36 | return _this.handlers.message(message); | |
37 | }; | |
38 | })(this) | |
39 | }); | |
40 | this._handshakeTimeout = new Timer((function(_this) { | |
41 | return function() { | |
42 | if (!_this._isSocketConnected()) { | |
43 | return; | |
44 | } | |
45 | _this._disconnectionReason = 'handshake-timeout'; | |
46 | return _this.socket.close(); | |
47 | }; | |
48 | })(this)); | |
49 | this._reconnectTimer = new Timer((function(_this) { | |
50 | return function() { | |
51 | if (!_this._connectionDesired) { | |
52 | return; | |
53 | } | |
54 | return _this.connect(); | |
55 | }; | |
56 | })(this)); | |
57 | this.connect(); | |
58 | } | |
59 | ||
60 | Connector.prototype._isSocketConnected = function() { | |
61 | return this.socket && this.socket.readyState === this.WebSocket.OPEN; | |
62 | }; | |
63 | ||
64 | Connector.prototype.connect = function() { | |
65 | this._connectionDesired = true; | |
66 | if (this._isSocketConnected()) { | |
67 | return; | |
68 | } | |
69 | this._reconnectTimer.stop(); | |
70 | this._disconnectionReason = 'cannot-connect'; | |
71 | this.protocolParser.reset(); | |
72 | this.handlers.connecting(); | |
73 | this.socket = new this.WebSocket(this._uri); | |
74 | this.socket.onopen = (function(_this) { | |
75 | return function(e) { | |
76 | return _this._onopen(e); | |
77 | }; | |
78 | })(this); | |
79 | this.socket.onclose = (function(_this) { | |
80 | return function(e) { | |
81 | return _this._onclose(e); | |
82 | }; | |
83 | })(this); | |
84 | this.socket.onmessage = (function(_this) { | |
85 | return function(e) { | |
86 | return _this._onmessage(e); | |
87 | }; | |
88 | })(this); | |
89 | return this.socket.onerror = (function(_this) { | |
90 | return function(e) { | |
91 | return _this._onerror(e); | |
92 | }; | |
93 | })(this); | |
94 | }; | |
95 | ||
96 | Connector.prototype.disconnect = function() { | |
97 | this._connectionDesired = false; | |
98 | this._reconnectTimer.stop(); | |
99 | if (!this._isSocketConnected()) { | |
100 | return; | |
101 | } | |
102 | this._disconnectionReason = 'manual'; | |
103 | return this.socket.close(); | |
104 | }; | |
105 | ||
106 | Connector.prototype._scheduleReconnection = function() { | |
107 | if (!this._connectionDesired) { | |
108 | return; | |
109 | } | |
110 | if (!this._reconnectTimer.running) { | |
111 | this._reconnectTimer.start(this._nextDelay); | |
112 | return this._nextDelay = Math.min(this.options.maxdelay, this._nextDelay * 2); | |
113 | } | |
114 | }; | |
115 | ||
116 | Connector.prototype.sendCommand = function(command) { | |
117 | if (this.protocol == null) { | |
118 | return; | |
119 | } | |
120 | return this._sendCommand(command); | |
121 | }; | |
122 | ||
123 | Connector.prototype._sendCommand = function(command) { | |
124 | return this.socket.send(JSON.stringify(command)); | |
125 | }; | |
126 | ||
127 | Connector.prototype._closeOnError = function() { | |
128 | this._handshakeTimeout.stop(); | |
129 | this._disconnectionReason = 'error'; | |
130 | return this.socket.close(); | |
131 | }; | |
132 | ||
133 | Connector.prototype._onopen = function(e) { | |
134 | var hello; | |
135 | this.handlers.socketConnected(); | |
136 | this._disconnectionReason = 'handshake-failed'; | |
137 | hello = { | |
138 | command: 'hello', | |
139 | protocols: [PROTOCOL_6, PROTOCOL_7] | |
140 | }; | |
141 | hello.ver = Version; | |
142 | if (this.options.ext) { | |
143 | hello.ext = this.options.ext; | |
144 | } | |
145 | if (this.options.extver) { | |
146 | hello.extver = this.options.extver; | |
147 | } | |
148 | if (this.options.snipver) { | |
149 | hello.snipver = this.options.snipver; | |
150 | } | |
151 | this._sendCommand(hello); | |
152 | return this._handshakeTimeout.start(this.options.handshake_timeout); | |
153 | }; | |
154 | ||
155 | Connector.prototype._onclose = function(e) { | |
156 | this.protocol = 0; | |
157 | this.handlers.disconnected(this._disconnectionReason, this._nextDelay); | |
158 | return this._scheduleReconnection(); | |
159 | }; | |
160 | ||
161 | Connector.prototype._onerror = function(e) {}; | |
162 | ||
163 | Connector.prototype._onmessage = function(e) { | |
164 | return this.protocolParser.process(e.data); | |
165 | }; | |
166 | ||
167 | return Connector; | |
168 | ||
169 | })(); | |
170 | ||
171 | }).call(this); | |
172 | ||
173 | },{"./protocol":6}],2:[function(require,module,exports){ | |
174 | (function() { | |
175 | var CustomEvents; | |
176 | ||
177 | CustomEvents = { | |
178 | bind: function(element, eventName, handler) { | |
179 | if (element.addEventListener) { | |
180 | return element.addEventListener(eventName, handler, false); | |
181 | } else if (element.attachEvent) { | |
182 | element[eventName] = 1; | |
183 | return element.attachEvent('onpropertychange', function(event) { | |
184 | if (event.propertyName === eventName) { | |
185 | return handler(); | |
186 | } | |
187 | }); | |
188 | } else { | |
189 | throw new Error("Attempt to attach custom event " + eventName + " to something which isn't a DOMElement"); | |
190 | } | |
191 | }, | |
192 | fire: function(element, eventName) { | |
193 | var event; | |
194 | if (element.addEventListener) { | |
195 | event = document.createEvent('HTMLEvents'); | |
196 | event.initEvent(eventName, true, true); | |
197 | return document.dispatchEvent(event); | |
198 | } else if (element.attachEvent) { | |
199 | if (element[eventName]) { | |
200 | return element[eventName]++; | |
201 | } | |
202 | } else { | |
203 | throw new Error("Attempt to fire custom event " + eventName + " on something which isn't a DOMElement"); | |
204 | } | |
205 | } | |
206 | }; | |
207 | ||
208 | exports.bind = CustomEvents.bind; | |
209 | ||
210 | exports.fire = CustomEvents.fire; | |
211 | ||
212 | }).call(this); | |
213 | ||
214 | },{}],3:[function(require,module,exports){ | |
215 | (function() { | |
216 | var LessPlugin; | |
217 | ||
218 | module.exports = LessPlugin = (function() { | |
219 | LessPlugin.identifier = 'less'; | |
220 | ||
221 | LessPlugin.version = '1.0'; | |
222 | ||
223 | function LessPlugin(window, host) { | |
224 | this.window = window; | |
225 | this.host = host; | |
226 | } | |
227 | ||
228 | LessPlugin.prototype.reload = function(path, options) { | |
229 | if (this.window.less && this.window.less.refresh) { | |
230 | if (path.match(/\.less$/i)) { | |
231 | return this.reloadLess(path); | |
232 | } | |
233 | if (options.originalPath.match(/\.less$/i)) { | |
234 | return this.reloadLess(options.originalPath); | |
235 | } | |
236 | } | |
237 | return false; | |
238 | }; | |
239 | ||
240 | LessPlugin.prototype.reloadLess = function(path) { | |
241 | var link, links, _i, _len; | |
242 | links = (function() { | |
243 | var _i, _len, _ref, _results; | |
244 | _ref = document.getElementsByTagName('link'); | |
245 | _results = []; | |
246 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
247 | link = _ref[_i]; | |
248 | if (link.href && link.rel.match(/^stylesheet\/less$/i) || (link.rel.match(/stylesheet/i) && link.type.match(/^text\/(x-)?less$/i))) { | |
249 | _results.push(link); | |
250 | } | |
251 | } | |
252 | return _results; | |
253 | })(); | |
254 | if (links.length === 0) { | |
255 | return false; | |
256 | } | |
257 | for (_i = 0, _len = links.length; _i < _len; _i++) { | |
258 | link = links[_i]; | |
259 | link.href = this.host.generateCacheBustUrl(link.href); | |
260 | } | |
261 | this.host.console.log("LiveReload is asking LESS to recompile all stylesheets"); | |
262 | this.window.less.refresh(true); | |
263 | return true; | |
264 | }; | |
265 | ||
266 | LessPlugin.prototype.analyze = function() { | |
267 | return { | |
268 | disable: !!(this.window.less && this.window.less.refresh) | |
269 | }; | |
270 | }; | |
271 | ||
272 | return LessPlugin; | |
273 | ||
274 | })(); | |
275 | ||
276 | }).call(this); | |
277 | ||
278 | },{}],4:[function(require,module,exports){ | |
279 | (function() { | |
280 | var Connector, LiveReload, Options, Reloader, Timer, | |
281 | __hasProp = {}.hasOwnProperty; | |
282 | ||
283 | Connector = require('./connector').Connector; | |
284 | ||
285 | Timer = require('./timer').Timer; | |
286 | ||
287 | Options = require('./options').Options; | |
288 | ||
289 | Reloader = require('./reloader').Reloader; | |
290 | ||
291 | exports.LiveReload = LiveReload = (function() { | |
292 | function LiveReload(window) { | |
293 | var k, v, _ref; | |
294 | this.window = window; | |
295 | this.listeners = {}; | |
296 | this.plugins = []; | |
297 | this.pluginIdentifiers = {}; | |
298 | this.console = this.window.console && this.window.console.log && this.window.console.error ? this.window.location.href.match(/LR-verbose/) ? this.window.console : { | |
299 | log: function() {}, | |
300 | error: this.window.console.error.bind(this.window.console) | |
301 | } : { | |
302 | log: function() {}, | |
303 | error: function() {} | |
304 | }; | |
305 | if (!(this.WebSocket = this.window.WebSocket || this.window.MozWebSocket)) { | |
306 | this.console.error("LiveReload disabled because the browser does not seem to support web sockets"); | |
307 | return; | |
308 | } | |
309 | if ('LiveReloadOptions' in window) { | |
310 | this.options = new Options(); | |
311 | _ref = window['LiveReloadOptions']; | |
312 | for (k in _ref) { | |
313 | if (!__hasProp.call(_ref, k)) continue; | |
314 | v = _ref[k]; | |
315 | this.options.set(k, v); | |
316 | } | |
317 | } else { | |
318 | this.options = Options.extract(this.window.document); | |
319 | if (!this.options) { | |
320 | this.console.error("LiveReload disabled because it could not find its own <SCRIPT> tag"); | |
321 | return; | |
322 | } | |
323 | } | |
324 | this.reloader = new Reloader(this.window, this.console, Timer); | |
325 | this.connector = new Connector(this.options, this.WebSocket, Timer, { | |
326 | connecting: (function(_this) { | |
327 | return function() {}; | |
328 | })(this), | |
329 | socketConnected: (function(_this) { | |
330 | return function() {}; | |
331 | })(this), | |
332 | connected: (function(_this) { | |
333 | return function(protocol) { | |
334 | var _base; | |
335 | if (typeof (_base = _this.listeners).connect === "function") { | |
336 | _base.connect(); | |
337 | } | |
338 | _this.log("LiveReload is connected to " + _this.options.host + ":" + _this.options.port + " (protocol v" + protocol + ")."); | |
339 | return _this.analyze(); | |
340 | }; | |
341 | })(this), | |
342 | error: (function(_this) { | |
343 | return function(e) { | |
344 | if (e instanceof ProtocolError) { | |
345 | if (typeof console !== "undefined" && console !== null) { | |
346 | return console.log("" + e.message + "."); | |
347 | } | |
348 | } else { | |
349 | if (typeof console !== "undefined" && console !== null) { | |
350 | return console.log("LiveReload internal error: " + e.message); | |
351 | } | |
352 | } | |
353 | }; | |
354 | })(this), | |
355 | disconnected: (function(_this) { | |
356 | return function(reason, nextDelay) { | |
357 | var _base; | |
358 | if (typeof (_base = _this.listeners).disconnect === "function") { | |
359 | _base.disconnect(); | |
360 | } | |
361 | switch (reason) { | |
362 | case 'cannot-connect': | |
363 | return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + ", will retry in " + nextDelay + " sec."); | |
364 | case 'broken': | |
365 | return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + ", reconnecting in " + nextDelay + " sec."); | |
366 | case 'handshake-timeout': | |
367 | return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake timeout), will retry in " + nextDelay + " sec."); | |
368 | case 'handshake-failed': | |
369 | return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake failed), will retry in " + nextDelay + " sec."); | |
370 | case 'manual': | |
371 | break; | |
372 | case 'error': | |
373 | break; | |
374 | default: | |
375 | return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + " (" + reason + "), reconnecting in " + nextDelay + " sec."); | |
376 | } | |
377 | }; | |
378 | })(this), | |
379 | message: (function(_this) { | |
380 | return function(message) { | |
381 | switch (message.command) { | |
382 | case 'reload': | |
383 | return _this.performReload(message); | |
384 | case 'alert': | |
385 | return _this.performAlert(message); | |
386 | } | |
387 | }; | |
388 | })(this) | |
389 | }); | |
390 | this.initialized = true; | |
391 | } | |
392 | ||
393 | LiveReload.prototype.on = function(eventName, handler) { | |
394 | return this.listeners[eventName] = handler; | |
395 | }; | |
396 | ||
397 | LiveReload.prototype.log = function(message) { | |
398 | return this.console.log("" + message); | |
399 | }; | |
400 | ||
401 | LiveReload.prototype.performReload = function(message) { | |
402 | var _ref, _ref1; | |
403 | this.log("LiveReload received reload request: " + (JSON.stringify(message, null, 2))); | |
404 | return this.reloader.reload(message.path, { | |
405 | liveCSS: (_ref = message.liveCSS) != null ? _ref : true, | |
406 | liveImg: (_ref1 = message.liveImg) != null ? _ref1 : true, | |
407 | originalPath: message.originalPath || '', | |
408 | overrideURL: message.overrideURL || '', | |
409 | serverURL: "http://" + this.options.host + ":" + this.options.port | |
410 | }); | |
411 | }; | |
412 | ||
413 | LiveReload.prototype.performAlert = function(message) { | |
414 | return alert(message.message); | |
415 | }; | |
416 | ||
417 | LiveReload.prototype.shutDown = function() { | |
418 | var _base; | |
419 | if (!this.initialized) { | |
420 | return; | |
421 | } | |
422 | this.connector.disconnect(); | |
423 | this.log("LiveReload disconnected."); | |
424 | return typeof (_base = this.listeners).shutdown === "function" ? _base.shutdown() : void 0; | |
425 | }; | |
426 | ||
427 | LiveReload.prototype.hasPlugin = function(identifier) { | |
428 | return !!this.pluginIdentifiers[identifier]; | |
429 | }; | |
430 | ||
431 | LiveReload.prototype.addPlugin = function(pluginClass) { | |
432 | var plugin; | |
433 | if (!this.initialized) { | |
434 | return; | |
435 | } | |
436 | if (this.hasPlugin(pluginClass.identifier)) { | |
437 | return; | |
438 | } | |
439 | this.pluginIdentifiers[pluginClass.identifier] = true; | |
440 | plugin = new pluginClass(this.window, { | |
441 | _livereload: this, | |
442 | _reloader: this.reloader, | |
443 | _connector: this.connector, | |
444 | console: this.console, | |
445 | Timer: Timer, | |
446 | generateCacheBustUrl: (function(_this) { | |
447 | return function(url) { | |
448 | return _this.reloader.generateCacheBustUrl(url); | |
449 | }; | |
450 | })(this) | |
451 | }); | |
452 | this.plugins.push(plugin); | |
453 | this.reloader.addPlugin(plugin); | |
454 | }; | |
455 | ||
456 | LiveReload.prototype.analyze = function() { | |
457 | var plugin, pluginData, pluginsData, _i, _len, _ref; | |
458 | if (!this.initialized) { | |
459 | return; | |
460 | } | |
461 | if (!(this.connector.protocol >= 7)) { | |
462 | return; | |
463 | } | |
464 | pluginsData = {}; | |
465 | _ref = this.plugins; | |
466 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
467 | plugin = _ref[_i]; | |
468 | pluginsData[plugin.constructor.identifier] = pluginData = (typeof plugin.analyze === "function" ? plugin.analyze() : void 0) || {}; | |
469 | pluginData.version = plugin.constructor.version; | |
470 | } | |
471 | this.connector.sendCommand({ | |
472 | command: 'info', | |
473 | plugins: pluginsData, | |
474 | url: this.window.location.href | |
475 | }); | |
476 | }; | |
477 | ||
478 | return LiveReload; | |
479 | ||
480 | })(); | |
481 | ||
482 | }).call(this); | |
483 | ||
484 | },{"./connector":1,"./options":5,"./reloader":7,"./timer":9}],5:[function(require,module,exports){ | |
485 | (function() { | |
486 | var Options; | |
487 | ||
488 | exports.Options = Options = (function() { | |
489 | function Options() { | |
490 | this.https = false; | |
491 | this.host = null; | |
492 | this.port = 35729; | |
493 | this.snipver = null; | |
494 | this.ext = null; | |
495 | this.extver = null; | |
496 | this.mindelay = 1000; | |
497 | this.maxdelay = 60000; | |
498 | this.handshake_timeout = 5000; | |
499 | } | |
500 | ||
501 | Options.prototype.set = function(name, value) { | |
502 | if (typeof value === 'undefined') { | |
503 | return; | |
504 | } | |
505 | if (!isNaN(+value)) { | |
506 | value = +value; | |
507 | } | |
508 | return this[name] = value; | |
509 | }; | |
510 | ||
511 | return Options; | |
512 | ||
513 | })(); | |
514 | ||
515 | Options.extract = function(document) { | |
516 | var element, keyAndValue, m, mm, options, pair, src, _i, _j, _len, _len1, _ref, _ref1; | |
517 | _ref = document.getElementsByTagName('script'); | |
518 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
519 | element = _ref[_i]; | |
520 | if ((src = element.src) && (m = src.match(/^[^:]+:\/\/(.*)\/z?livereload\.js(?:\?(.*))?$/))) { | |
521 | options = new Options(); | |
522 | options.https = src.indexOf("https") === 0; | |
523 | if (mm = m[1].match(/^([^\/:]+)(?::(\d+))?$/)) { | |
524 | options.host = mm[1]; | |
525 | if (mm[2]) { | |
526 | options.port = parseInt(mm[2], 10); | |
527 | } | |
528 | } | |
529 | if (m[2]) { | |
530 | _ref1 = m[2].split('&'); | |
531 | for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | |
532 | pair = _ref1[_j]; | |
533 | if ((keyAndValue = pair.split('=')).length > 1) { | |
534 | options.set(keyAndValue[0].replace(/-/g, '_'), keyAndValue.slice(1).join('=')); | |
535 | } | |
536 | } | |
537 | } | |
538 | return options; | |
539 | } | |
540 | } | |
541 | return null; | |
542 | }; | |
543 | ||
544 | }).call(this); | |
545 | ||
546 | },{}],6:[function(require,module,exports){ | |
547 | (function() { | |
548 | var PROTOCOL_6, PROTOCOL_7, Parser, ProtocolError, | |
549 | __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | |
550 | ||
551 | exports.PROTOCOL_6 = PROTOCOL_6 = 'http://livereload.com/protocols/official-6'; | |
552 | ||
553 | exports.PROTOCOL_7 = PROTOCOL_7 = 'http://livereload.com/protocols/official-7'; | |
554 | ||
555 | exports.ProtocolError = ProtocolError = (function() { | |
556 | function ProtocolError(reason, data) { | |
557 | this.message = "LiveReload protocol error (" + reason + ") after receiving data: \"" + data + "\"."; | |
558 | } | |
559 | ||
560 | return ProtocolError; | |
561 | ||
562 | })(); | |
563 | ||
564 | exports.Parser = Parser = (function() { | |
565 | function Parser(handlers) { | |
566 | this.handlers = handlers; | |
567 | this.reset(); | |
568 | } | |
569 | ||
570 | Parser.prototype.reset = function() { | |
571 | return this.protocol = null; | |
572 | }; | |
573 | ||
574 | Parser.prototype.process = function(data) { | |
575 | var command, e, message, options, _ref; | |
576 | try { | |
577 | if (this.protocol == null) { | |
578 | if (data.match(/^!!ver:([\d.]+)$/)) { | |
579 | this.protocol = 6; | |
580 | } else if (message = this._parseMessage(data, ['hello'])) { | |
581 | if (!message.protocols.length) { | |
582 | throw new ProtocolError("no protocols specified in handshake message"); | |
583 | } else if (__indexOf.call(message.protocols, PROTOCOL_7) >= 0) { | |
584 | this.protocol = 7; | |
585 | } else if (__indexOf.call(message.protocols, PROTOCOL_6) >= 0) { | |
586 | this.protocol = 6; | |
587 | } else { | |
588 | throw new ProtocolError("no supported protocols found"); | |
589 | } | |
590 | } | |
591 | return this.handlers.connected(this.protocol); | |
592 | } else if (this.protocol === 6) { | |
593 | message = JSON.parse(data); | |
594 | if (!message.length) { | |
595 | throw new ProtocolError("protocol 6 messages must be arrays"); | |
596 | } | |
597 | command = message[0], options = message[1]; | |
598 | if (command !== 'refresh') { | |
599 | throw new ProtocolError("unknown protocol 6 command"); | |
600 | } | |
601 | return this.handlers.message({ | |
602 | command: 'reload', | |
603 | path: options.path, | |
604 | liveCSS: (_ref = options.apply_css_live) != null ? _ref : true | |
605 | }); | |
606 | } else { | |
607 | message = this._parseMessage(data, ['reload', 'alert']); | |
608 | return this.handlers.message(message); | |
609 | } | |
610 | } catch (_error) { | |
611 | e = _error; | |
612 | if (e instanceof ProtocolError) { | |
613 | return this.handlers.error(e); | |
614 | } else { | |
615 | throw e; | |
616 | } | |
617 | } | |
618 | }; | |
619 | ||
620 | Parser.prototype._parseMessage = function(data, validCommands) { | |
621 | var e, message, _ref; | |
622 | try { | |
623 | message = JSON.parse(data); | |
624 | } catch (_error) { | |
625 | e = _error; | |
626 | throw new ProtocolError('unparsable JSON', data); | |
627 | } | |
628 | if (!message.command) { | |
629 | throw new ProtocolError('missing "command" key', data); | |
630 | } | |
631 | if (_ref = message.command, __indexOf.call(validCommands, _ref) < 0) { | |
632 | throw new ProtocolError("invalid command '" + message.command + "', only valid commands are: " + (validCommands.join(', ')) + ")", data); | |
633 | } | |
634 | return message; | |
635 | }; | |
636 | ||
637 | return Parser; | |
638 | ||
639 | })(); | |
640 | ||
641 | }).call(this); | |
642 | ||
643 | },{}],7:[function(require,module,exports){ | |
644 | (function() { | |
645 | var IMAGE_STYLES, Reloader, numberOfMatchingSegments, pathFromUrl, pathsMatch, pickBestMatch, splitUrl; | |
646 | ||
647 | splitUrl = function(url) { | |
648 | var hash, index, params; | |
649 | if ((index = url.indexOf('#')) >= 0) { | |
650 | hash = url.slice(index); | |
651 | url = url.slice(0, index); | |
652 | } else { | |
653 | hash = ''; | |
654 | } | |
655 | if ((index = url.indexOf('?')) >= 0) { | |
656 | params = url.slice(index); | |
657 | url = url.slice(0, index); | |
658 | } else { | |
659 | params = ''; | |
660 | } | |
661 | return { | |
662 | url: url, | |
663 | params: params, | |
664 | hash: hash | |
665 | }; | |
666 | }; | |
667 | ||
668 | pathFromUrl = function(url) { | |
669 | var path; | |
670 | url = splitUrl(url).url; | |
671 | if (url.indexOf('file://') === 0) { | |
672 | path = url.replace(/^file:\/\/(localhost)?/, ''); | |
673 | } else { | |
674 | path = url.replace(/^([^:]+:)?\/\/([^:\/]+)(:\d*)?\//, '/'); | |
675 | } | |
676 | return decodeURIComponent(path); | |
677 | }; | |
678 | ||
679 | pickBestMatch = function(path, objects, pathFunc) { | |
680 | var bestMatch, object, score, _i, _len; | |
681 | bestMatch = { | |
682 | score: 0 | |
683 | }; | |
684 | for (_i = 0, _len = objects.length; _i < _len; _i++) { | |
685 | object = objects[_i]; | |
686 | score = numberOfMatchingSegments(path, pathFunc(object)); | |
687 | if (score > bestMatch.score) { | |
688 | bestMatch = { | |
689 | object: object, | |
690 | score: score | |
691 | }; | |
692 | } | |
693 | } | |
694 | if (bestMatch.score > 0) { | |
695 | return bestMatch; | |
696 | } else { | |
697 | return null; | |
698 | } | |
699 | }; | |
700 | ||
701 | numberOfMatchingSegments = function(path1, path2) { | |
702 | var comps1, comps2, eqCount, len; | |
703 | path1 = path1.replace(/^\/+/, '').toLowerCase(); | |
704 | path2 = path2.replace(/^\/+/, '').toLowerCase(); | |
705 | if (path1 === path2) { | |
706 | return 10000; | |
707 | } | |
708 | comps1 = path1.split('/').reverse(); | |
709 | comps2 = path2.split('/').reverse(); | |
710 | len = Math.min(comps1.length, comps2.length); | |
711 | eqCount = 0; | |
712 | while (eqCount < len && comps1[eqCount] === comps2[eqCount]) { | |
713 | ++eqCount; | |
714 | } | |
715 | return eqCount; | |
716 | }; | |
717 | ||
718 | pathsMatch = function(path1, path2) { | |
719 | return numberOfMatchingSegments(path1, path2) > 0; | |
720 | }; | |
721 | ||
722 | IMAGE_STYLES = [ | |
723 | { | |
724 | selector: 'background', | |
725 | styleNames: ['backgroundImage'] | |
726 | }, { | |
727 | selector: 'border', | |
728 | styleNames: ['borderImage', 'webkitBorderImage', 'MozBorderImage'] | |
729 | } | |
730 | ]; | |
731 | ||
732 | exports.Reloader = Reloader = (function() { | |
733 | function Reloader(window, console, Timer) { | |
734 | this.window = window; | |
735 | this.console = console; | |
736 | this.Timer = Timer; | |
737 | this.document = this.window.document; | |
738 | this.importCacheWaitPeriod = 200; | |
739 | this.plugins = []; | |
740 | } | |
741 | ||
742 | Reloader.prototype.addPlugin = function(plugin) { | |
743 | return this.plugins.push(plugin); | |
744 | }; | |
745 | ||
746 | Reloader.prototype.analyze = function(callback) { | |
747 | return results; | |
748 | }; | |
749 | ||
750 | Reloader.prototype.reload = function(path, options) { | |
751 | var plugin, _base, _i, _len, _ref; | |
752 | this.options = options; | |
753 | if ((_base = this.options).stylesheetReloadTimeout == null) { | |
754 | _base.stylesheetReloadTimeout = 15000; | |
755 | } | |
756 | _ref = this.plugins; | |
757 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
758 | plugin = _ref[_i]; | |
759 | if (plugin.reload && plugin.reload(path, options)) { | |
760 | return; | |
761 | } | |
762 | } | |
763 | if (options.liveCSS) { | |
764 | if (path.match(/\.css$/i)) { | |
765 | if (this.reloadStylesheet(path)) { | |
766 | return; | |
767 | } | |
768 | } | |
769 | } | |
770 | if (options.liveImg) { | |
771 | if (path.match(/\.(jpe?g|png|gif)$/i)) { | |
772 | this.reloadImages(path); | |
773 | return; | |
774 | } | |
775 | } | |
776 | return this.reloadPage(); | |
777 | }; | |
778 | ||
779 | Reloader.prototype.reloadPage = function() { | |
780 | return this.window.document.location.reload(); | |
781 | }; | |
782 | ||
783 | Reloader.prototype.reloadImages = function(path) { | |
784 | var expando, img, selector, styleNames, styleSheet, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3, _results; | |
785 | expando = this.generateUniqueString(); | |
786 | _ref = this.document.images; | |
787 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
788 | img = _ref[_i]; | |
789 | if (pathsMatch(path, pathFromUrl(img.src))) { | |
790 | img.src = this.generateCacheBustUrl(img.src, expando); | |
791 | } | |
792 | } | |
793 | if (this.document.querySelectorAll) { | |
794 | for (_j = 0, _len1 = IMAGE_STYLES.length; _j < _len1; _j++) { | |
795 | _ref1 = IMAGE_STYLES[_j], selector = _ref1.selector, styleNames = _ref1.styleNames; | |
796 | _ref2 = this.document.querySelectorAll("[style*=" + selector + "]"); | |
797 | for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { | |
798 | img = _ref2[_k]; | |
799 | this.reloadStyleImages(img.style, styleNames, path, expando); | |
800 | } | |
801 | } | |
802 | } | |
803 | if (this.document.styleSheets) { | |
804 | _ref3 = this.document.styleSheets; | |
805 | _results = []; | |
806 | for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) { | |
807 | styleSheet = _ref3[_l]; | |
808 | _results.push(this.reloadStylesheetImages(styleSheet, path, expando)); | |
809 | } | |
810 | return _results; | |
811 | } | |
812 | }; | |
813 | ||
814 | Reloader.prototype.reloadStylesheetImages = function(styleSheet, path, expando) { | |
815 | var e, rule, rules, styleNames, _i, _j, _len, _len1; | |
816 | try { | |
817 | rules = styleSheet != null ? styleSheet.cssRules : void 0; | |
818 | } catch (_error) { | |
819 | e = _error; | |
820 | } | |
821 | if (!rules) { | |
822 | return; | |
823 | } | |
824 | for (_i = 0, _len = rules.length; _i < _len; _i++) { | |
825 | rule = rules[_i]; | |
826 | switch (rule.type) { | |
827 | case CSSRule.IMPORT_RULE: | |
828 | this.reloadStylesheetImages(rule.styleSheet, path, expando); | |
829 | break; | |
830 | case CSSRule.STYLE_RULE: | |
831 | for (_j = 0, _len1 = IMAGE_STYLES.length; _j < _len1; _j++) { | |
832 | styleNames = IMAGE_STYLES[_j].styleNames; | |
833 | this.reloadStyleImages(rule.style, styleNames, path, expando); | |
834 | } | |
835 | break; | |
836 | case CSSRule.MEDIA_RULE: | |
837 | this.reloadStylesheetImages(rule, path, expando); | |
838 | } | |
839 | } | |
840 | }; | |
841 | ||
842 | Reloader.prototype.reloadStyleImages = function(style, styleNames, path, expando) { | |
843 | var newValue, styleName, value, _i, _len; | |
844 | for (_i = 0, _len = styleNames.length; _i < _len; _i++) { | |
845 | styleName = styleNames[_i]; | |
846 | value = style[styleName]; | |
847 | if (typeof value === 'string') { | |
848 | newValue = value.replace(/\burl\s*\(([^)]*)\)/, (function(_this) { | |
849 | return function(match, src) { | |
850 | if (pathsMatch(path, pathFromUrl(src))) { | |
851 | return "url(" + (_this.generateCacheBustUrl(src, expando)) + ")"; | |
852 | } else { | |
853 | return match; | |
854 | } | |
855 | }; | |
856 | })(this)); | |
857 | if (newValue !== value) { | |
858 | style[styleName] = newValue; | |
859 | } | |
860 | } | |
861 | } | |
862 | }; | |
863 | ||
864 | Reloader.prototype.reloadStylesheet = function(path) { | |
865 | var imported, link, links, match, style, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1; | |
866 | links = (function() { | |
867 | var _i, _len, _ref, _results; | |
868 | _ref = this.document.getElementsByTagName('link'); | |
869 | _results = []; | |
870 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
871 | link = _ref[_i]; | |
872 | if (link.rel.match(/^stylesheet$/i) && !link.__LiveReload_pendingRemoval) { | |
873 | _results.push(link); | |
874 | } | |
875 | } | |
876 | return _results; | |
877 | }).call(this); | |
878 | imported = []; | |
879 | _ref = this.document.getElementsByTagName('style'); | |
880 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
881 | style = _ref[_i]; | |
882 | if (style.sheet) { | |
883 | this.collectImportedStylesheets(style, style.sheet, imported); | |
884 | } | |
885 | } | |
886 | for (_j = 0, _len1 = links.length; _j < _len1; _j++) { | |
887 | link = links[_j]; | |
888 | this.collectImportedStylesheets(link, link.sheet, imported); | |
889 | } | |
890 | if (this.window.StyleFix && this.document.querySelectorAll) { | |
891 | _ref1 = this.document.querySelectorAll('style[data-href]'); | |
892 | for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) { | |
893 | style = _ref1[_k]; | |
894 | links.push(style); | |
895 | } | |
896 | } | |
897 | this.console.log("LiveReload found " + links.length + " LINKed stylesheets, " + imported.length + " @imported stylesheets"); | |
898 | match = pickBestMatch(path, links.concat(imported), (function(_this) { | |
899 | return function(l) { | |
900 | return pathFromUrl(_this.linkHref(l)); | |
901 | }; | |
902 | })(this)); | |
903 | if (match) { | |
904 | if (match.object.rule) { | |
905 | this.console.log("LiveReload is reloading imported stylesheet: " + match.object.href); | |
906 | this.reattachImportedRule(match.object); | |
907 | } else { | |
908 | this.console.log("LiveReload is reloading stylesheet: " + (this.linkHref(match.object))); | |
909 | this.reattachStylesheetLink(match.object); | |
910 | } | |
911 | } else { | |
912 | this.console.log("LiveReload will reload all stylesheets because path '" + path + "' did not match any specific one"); | |
913 | for (_l = 0, _len3 = links.length; _l < _len3; _l++) { | |
914 | link = links[_l]; | |
915 | this.reattachStylesheetLink(link); | |
916 | } | |
917 | } | |
918 | return true; | |
919 | }; | |
920 | ||
921 | Reloader.prototype.collectImportedStylesheets = function(link, styleSheet, result) { | |
922 | var e, index, rule, rules, _i, _len; | |
923 | try { | |
924 | rules = styleSheet != null ? styleSheet.cssRules : void 0; | |
925 | } catch (_error) { | |
926 | e = _error; | |
927 | } | |
928 | if (rules && rules.length) { | |
929 | for (index = _i = 0, _len = rules.length; _i < _len; index = ++_i) { | |
930 | rule = rules[index]; | |
931 | switch (rule.type) { | |
932 | case CSSRule.CHARSET_RULE: | |
933 | continue; | |
934 | case CSSRule.IMPORT_RULE: | |
935 | result.push({ | |
936 | link: link, | |
937 | rule: rule, | |
938 | index: index, | |
939 | href: rule.href | |
940 | }); | |
941 | this.collectImportedStylesheets(link, rule.styleSheet, result); | |
942 | break; | |
943 | default: | |
944 | break; | |
945 | } | |
946 | } | |
947 | } | |
948 | }; | |
949 | ||
950 | Reloader.prototype.waitUntilCssLoads = function(clone, func) { | |
951 | var callbackExecuted, executeCallback, poll; | |
952 | callbackExecuted = false; | |
953 | executeCallback = (function(_this) { | |
954 | return function() { | |
955 | if (callbackExecuted) { | |
956 | return; | |
957 | } | |
958 | callbackExecuted = true; | |
959 | return func(); | |
960 | }; | |
961 | })(this); | |
962 | clone.onload = (function(_this) { | |
963 | return function() { | |
964 | _this.console.log("LiveReload: the new stylesheet has finished loading"); | |
965 | _this.knownToSupportCssOnLoad = true; | |
966 | return executeCallback(); | |
967 | }; | |
968 | })(this); | |
969 | if (!this.knownToSupportCssOnLoad) { | |
970 | (poll = (function(_this) { | |
971 | return function() { | |
972 | if (clone.sheet) { | |
973 | _this.console.log("LiveReload is polling until the new CSS finishes loading..."); | |
974 | return executeCallback(); | |
975 | } else { | |
976 | return _this.Timer.start(50, poll); | |
977 | } | |
978 | }; | |
979 | })(this))(); | |
980 | } | |
981 | return this.Timer.start(this.options.stylesheetReloadTimeout, executeCallback); | |
982 | }; | |
983 | ||
984 | Reloader.prototype.linkHref = function(link) { | |
985 | return link.href || link.getAttribute('data-href'); | |
986 | }; | |
987 | ||
988 | Reloader.prototype.reattachStylesheetLink = function(link) { | |
989 | var clone, parent; | |
990 | if (link.__LiveReload_pendingRemoval) { | |
991 | return; | |
992 | } | |
993 | link.__LiveReload_pendingRemoval = true; | |
994 | if (link.tagName === 'STYLE') { | |
995 | clone = this.document.createElement('link'); | |
996 | clone.rel = 'stylesheet'; | |
997 | clone.media = link.media; | |
998 | clone.disabled = link.disabled; | |
999 | } else { | |
1000 | clone = link.cloneNode(false); | |
1001 | } | |
1002 | clone.href = this.generateCacheBustUrl(this.linkHref(link)); | |
1003 | parent = link.parentNode; | |
1004 | if (parent.lastChild === link) { | |
1005 | parent.appendChild(clone); | |
1006 | } else { | |
1007 | parent.insertBefore(clone, link.nextSibling); | |
1008 | } | |
1009 | return this.waitUntilCssLoads(clone, (function(_this) { | |
1010 | return function() { | |
1011 | var additionalWaitingTime; | |
1012 | if (/AppleWebKit/.test(navigator.userAgent)) { | |
1013 | additionalWaitingTime = 5; | |
1014 | } else { | |
1015 | additionalWaitingTime = 200; | |
1016 | } | |
1017 | return _this.Timer.start(additionalWaitingTime, function() { | |
1018 | var _ref; | |
1019 | if (!link.parentNode) { | |
1020 | return; | |
1021 | } | |
1022 | link.parentNode.removeChild(link); | |
1023 | clone.onreadystatechange = null; | |
1024 | return (_ref = _this.window.StyleFix) != null ? _ref.link(clone) : void 0; | |
1025 | }); | |
1026 | }; | |
1027 | })(this)); | |
1028 | }; | |
1029 | ||
1030 | Reloader.prototype.reattachImportedRule = function(_arg) { | |
1031 | var href, index, link, media, newRule, parent, rule, tempLink; | |
1032 | rule = _arg.rule, index = _arg.index, link = _arg.link; | |
1033 | parent = rule.parentStyleSheet; | |
1034 | href = this.generateCacheBustUrl(rule.href); | |
1035 | media = rule.media.length ? [].join.call(rule.media, ', ') : ''; | |
1036 | newRule = "@import url(\"" + href + "\") " + media + ";"; | |
1037 | rule.__LiveReload_newHref = href; | |
1038 | tempLink = this.document.createElement("link"); | |
1039 | tempLink.rel = 'stylesheet'; | |
1040 | tempLink.href = href; | |
1041 | tempLink.__LiveReload_pendingRemoval = true; | |
1042 | if (link.parentNode) { | |
1043 | link.parentNode.insertBefore(tempLink, link); | |
1044 | } | |
1045 | return this.Timer.start(this.importCacheWaitPeriod, (function(_this) { | |
1046 | return function() { | |
1047 | if (tempLink.parentNode) { | |
1048 | tempLink.parentNode.removeChild(tempLink); | |
1049 | } | |
1050 | if (rule.__LiveReload_newHref !== href) { | |
1051 | return; | |
1052 | } | |
1053 | parent.insertRule(newRule, index); | |
1054 | parent.deleteRule(index + 1); | |
1055 | rule = parent.cssRules[index]; | |
1056 | rule.__LiveReload_newHref = href; | |
1057 | return _this.Timer.start(_this.importCacheWaitPeriod, function() { | |
1058 | if (rule.__LiveReload_newHref !== href) { | |
1059 | return; | |
1060 | } | |
1061 | parent.insertRule(newRule, index); | |
1062 | return parent.deleteRule(index + 1); | |
1063 | }); | |
1064 | }; | |
1065 | })(this)); | |
1066 | }; | |
1067 | ||
1068 | Reloader.prototype.generateUniqueString = function() { | |
1069 | return 'livereload=' + Date.now(); | |
1070 | }; | |
1071 | ||
1072 | Reloader.prototype.generateCacheBustUrl = function(url, expando) { | |
1073 | var hash, oldParams, originalUrl, params, _ref; | |
1074 | if (expando == null) { | |
1075 | expando = this.generateUniqueString(); | |
1076 | } | |
1077 | _ref = splitUrl(url), url = _ref.url, hash = _ref.hash, oldParams = _ref.params; | |
1078 | if (this.options.overrideURL) { | |
1079 | if (url.indexOf(this.options.serverURL) < 0) { | |
1080 | originalUrl = url; | |
1081 | url = this.options.serverURL + this.options.overrideURL + "?url=" + encodeURIComponent(url); | |
1082 | this.console.log("LiveReload is overriding source URL " + originalUrl + " with " + url); | |
1083 | } | |
1084 | } | |
1085 | params = oldParams.replace(/(\?|&)livereload=(\d+)/, function(match, sep) { | |
1086 | return "" + sep + expando; | |
1087 | }); | |
1088 | if (params === oldParams) { | |
1089 | if (oldParams.length === 0) { | |
1090 | params = "?" + expando; | |
1091 | } else { | |
1092 | params = "" + oldParams + "&" + expando; | |
1093 | } | |
1094 | } | |
1095 | return url + params + hash; | |
1096 | }; | |
1097 | ||
1098 | return Reloader; | |
1099 | ||
1100 | })(); | |
1101 | ||
1102 | }).call(this); | |
1103 | ||
1104 | },{}],8:[function(require,module,exports){ | |
1105 | (function() { | |
1106 | var CustomEvents, LiveReload, k; | |
1107 | ||
1108 | CustomEvents = require('./customevents'); | |
1109 | ||
1110 | LiveReload = window.LiveReload = new (require('./livereload').LiveReload)(window); | |
1111 | ||
1112 | for (k in window) { | |
1113 | if (k.match(/^LiveReloadPlugin/)) { | |
1114 | LiveReload.addPlugin(window[k]); | |
1115 | } | |
1116 | } | |
1117 | ||
1118 | LiveReload.addPlugin(require('./less')); | |
1119 | ||
1120 | LiveReload.on('shutdown', function() { | |
1121 | return delete window.LiveReload; | |
1122 | }); | |
1123 | ||
1124 | LiveReload.on('connect', function() { | |
1125 | return CustomEvents.fire(document, 'LiveReloadConnect'); | |
1126 | }); | |
1127 | ||
1128 | LiveReload.on('disconnect', function() { | |
1129 | return CustomEvents.fire(document, 'LiveReloadDisconnect'); | |
1130 | }); | |
1131 | ||
1132 | CustomEvents.bind(document, 'LiveReloadShutDown', function() { | |
1133 | return LiveReload.shutDown(); | |
1134 | }); | |
1135 | ||
1136 | }).call(this); | |
1137 | ||
1138 | },{"./customevents":2,"./less":3,"./livereload":4}],9:[function(require,module,exports){ | |
1139 | (function() { | |
1140 | var Timer; | |
1141 | ||
1142 | exports.Timer = Timer = (function() { | |
1143 | function Timer(func) { | |
1144 | this.func = func; | |
1145 | this.running = false; | |
1146 | this.id = null; | |
1147 | this._handler = (function(_this) { | |
1148 | return function() { | |
1149 | _this.running = false; | |
1150 | _this.id = null; | |
1151 | return _this.func(); | |
1152 | }; | |
1153 | })(this); | |
1154 | } | |
1155 | ||
1156 | Timer.prototype.start = function(timeout) { | |
1157 | if (this.running) { | |
1158 | clearTimeout(this.id); | |
1159 | } | |
1160 | this.id = setTimeout(this._handler, timeout); | |
1161 | return this.running = true; | |
1162 | }; | |
1163 | ||
1164 | Timer.prototype.stop = function() { | |
1165 | if (this.running) { | |
1166 | clearTimeout(this.id); | |
1167 | this.running = false; | |
1168 | return this.id = null; | |
1169 | } | |
1170 | }; | |
1171 | ||
1172 | return Timer; | |
1173 | ||
1174 | })(); | |
1175 | ||
1176 | Timer.start = function(timeout, func) { | |
1177 | return setTimeout(func, timeout); | |
1178 | }; | |
1179 | ||
1180 | }).call(this); | |
1181 | ||
1182 | },{}]},{},[8]); |