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