├── README.md ├── example ├── css │ ├── bootstrap-responsive.css │ ├── bootstrap-responsive.min.css │ ├── bootstrap.css │ └── bootstrap.min.css ├── img │ ├── glyphicons-halflings-white.png │ └── glyphicons-halflings.png ├── index.html └── js │ ├── bootstrap.js │ ├── bootstrap.min.js │ ├── brain-socket.min.js │ └── modernizr-2.6.2.min.js └── lib ├── BrainSocket.js ├── BrainSocketPubSub.js ├── brain-socket.min.js └── example.js /README.md: -------------------------------------------------------------------------------- 1 | BrainSocket.js 2 | ============ 3 | 4 | WebSockets for realtime event-driven js apps. 5 | 6 | This js library is a helper class that pairs nicely with the [BrainSocket.php](https://github.com/BrainBoxLabs/brain-socket) Laravel package. 7 | 8 | Load the script into your app: 9 | 10 | ```html 11 | 15 | 16 | 17 |
18 |
19 |
20 |

21 | BrainSocket.js Example Chat App 22 |

23 |
24 | 25 |
26 |
27 | 28 |
29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /example/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | /* =================================================== 2 | * bootstrap-transition.js v2.3.2 3 | * http://getbootstrap.com/2.3.2/javascript.html#transitions 4 | * =================================================== 5 | * Copyright 2013 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ========================================================== */ 19 | 20 | 21 | !function ($) { 22 | 23 | "use strict"; // jshint ;_; 24 | 25 | 26 | /* CSS TRANSITION SUPPORT (http://www.modernizr.com/) 27 | * ======================================================= */ 28 | 29 | $(function () { 30 | 31 | $.support.transition = (function () { 32 | 33 | var transitionEnd = (function () { 34 | 35 | var el = document.createElement('bootstrap') 36 | , transEndEventNames = { 37 | 'WebkitTransition' : 'webkitTransitionEnd' 38 | , 'MozTransition' : 'transitionend' 39 | , 'OTransition' : 'oTransitionEnd otransitionend' 40 | , 'transition' : 'transitionend' 41 | } 42 | , name 43 | 44 | for (name in transEndEventNames){ 45 | if (el.style[name] !== undefined) { 46 | return transEndEventNames[name] 47 | } 48 | } 49 | 50 | }()) 51 | 52 | return transitionEnd && { 53 | end: transitionEnd 54 | } 55 | 56 | })() 57 | 58 | }) 59 | 60 | }(window.jQuery);/* ========================================================== 61 | * bootstrap-alert.js v2.3.2 62 | * http://getbootstrap.com/2.3.2/javascript.html#alerts 63 | * ========================================================== 64 | * Copyright 2013 Twitter, Inc. 65 | * 66 | * Licensed under the Apache License, Version 2.0 (the "License"); 67 | * you may not use this file except in compliance with the License. 68 | * You may obtain a copy of the License at 69 | * 70 | * http://www.apache.org/licenses/LICENSE-2.0 71 | * 72 | * Unless required by applicable law or agreed to in writing, software 73 | * distributed under the License is distributed on an "AS IS" BASIS, 74 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 75 | * See the License for the specific language governing permissions and 76 | * limitations under the License. 77 | * ========================================================== */ 78 | 79 | 80 | !function ($) { 81 | 82 | "use strict"; // jshint ;_; 83 | 84 | 85 | /* ALERT CLASS DEFINITION 86 | * ====================== */ 87 | 88 | var dismiss = '[data-dismiss="alert"]' 89 | , Alert = function (el) { 90 | $(el).on('click', dismiss, this.close) 91 | } 92 | 93 | Alert.prototype.close = function (e) { 94 | var $this = $(this) 95 | , selector = $this.attr('data-target') 96 | , $parent 97 | 98 | if (!selector) { 99 | selector = $this.attr('href') 100 | selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 101 | } 102 | 103 | $parent = $(selector) 104 | 105 | e && e.preventDefault() 106 | 107 | $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent()) 108 | 109 | $parent.trigger(e = $.Event('close')) 110 | 111 | if (e.isDefaultPrevented()) return 112 | 113 | $parent.removeClass('in') 114 | 115 | function removeElement() { 116 | $parent 117 | .trigger('closed') 118 | .remove() 119 | } 120 | 121 | $.support.transition && $parent.hasClass('fade') ? 122 | $parent.on($.support.transition.end, removeElement) : 123 | removeElement() 124 | } 125 | 126 | 127 | /* ALERT PLUGIN DEFINITION 128 | * ======================= */ 129 | 130 | var old = $.fn.alert 131 | 132 | $.fn.alert = function (option) { 133 | return this.each(function () { 134 | var $this = $(this) 135 | , data = $this.data('alert') 136 | if (!data) $this.data('alert', (data = new Alert(this))) 137 | if (typeof option == 'string') data[option].call($this) 138 | }) 139 | } 140 | 141 | $.fn.alert.Constructor = Alert 142 | 143 | 144 | /* ALERT NO CONFLICT 145 | * ================= */ 146 | 147 | $.fn.alert.noConflict = function () { 148 | $.fn.alert = old 149 | return this 150 | } 151 | 152 | 153 | /* ALERT DATA-API 154 | * ============== */ 155 | 156 | $(document).on('click.alert.data-api', dismiss, Alert.prototype.close) 157 | 158 | }(window.jQuery);/* ============================================================ 159 | * bootstrap-button.js v2.3.2 160 | * http://getbootstrap.com/2.3.2/javascript.html#buttons 161 | * ============================================================ 162 | * Copyright 2013 Twitter, Inc. 163 | * 164 | * Licensed under the Apache License, Version 2.0 (the "License"); 165 | * you may not use this file except in compliance with the License. 166 | * You may obtain a copy of the License at 167 | * 168 | * http://www.apache.org/licenses/LICENSE-2.0 169 | * 170 | * Unless required by applicable law or agreed to in writing, software 171 | * distributed under the License is distributed on an "AS IS" BASIS, 172 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 173 | * See the License for the specific language governing permissions and 174 | * limitations under the License. 175 | * ============================================================ */ 176 | 177 | 178 | !function ($) { 179 | 180 | "use strict"; // jshint ;_; 181 | 182 | 183 | /* BUTTON PUBLIC CLASS DEFINITION 184 | * ============================== */ 185 | 186 | var Button = function (element, options) { 187 | this.$element = $(element) 188 | this.options = $.extend({}, $.fn.button.defaults, options) 189 | } 190 | 191 | Button.prototype.setState = function (state) { 192 | var d = 'disabled' 193 | , $el = this.$element 194 | , data = $el.data() 195 | , val = $el.is('input') ? 'val' : 'html' 196 | 197 | state = state + 'Text' 198 | data.resetText || $el.data('resetText', $el[val]()) 199 | 200 | $el[val](data[state] || this.options[state]) 201 | 202 | // push to event loop to allow forms to submit 203 | setTimeout(function () { 204 | state == 'loadingText' ? 205 | $el.addClass(d).attr(d, d) : 206 | $el.removeClass(d).removeAttr(d) 207 | }, 0) 208 | } 209 | 210 | Button.prototype.toggle = function () { 211 | var $parent = this.$element.closest('[data-toggle="buttons-radio"]') 212 | 213 | $parent && $parent 214 | .find('.active') 215 | .removeClass('active') 216 | 217 | this.$element.toggleClass('active') 218 | } 219 | 220 | 221 | /* BUTTON PLUGIN DEFINITION 222 | * ======================== */ 223 | 224 | var old = $.fn.button 225 | 226 | $.fn.button = function (option) { 227 | return this.each(function () { 228 | var $this = $(this) 229 | , data = $this.data('button') 230 | , options = typeof option == 'object' && option 231 | if (!data) $this.data('button', (data = new Button(this, options))) 232 | if (option == 'toggle') data.toggle() 233 | else if (option) data.setState(option) 234 | }) 235 | } 236 | 237 | $.fn.button.defaults = { 238 | loadingText: 'loading...' 239 | } 240 | 241 | $.fn.button.Constructor = Button 242 | 243 | 244 | /* BUTTON NO CONFLICT 245 | * ================== */ 246 | 247 | $.fn.button.noConflict = function () { 248 | $.fn.button = old 249 | return this 250 | } 251 | 252 | 253 | /* BUTTON DATA-API 254 | * =============== */ 255 | 256 | $(document).on('click.button.data-api', '[data-toggle^=button]', function (e) { 257 | var $btn = $(e.target) 258 | if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') 259 | $btn.button('toggle') 260 | }) 261 | 262 | }(window.jQuery);/* ========================================================== 263 | * bootstrap-carousel.js v2.3.2 264 | * http://getbootstrap.com/2.3.2/javascript.html#carousel 265 | * ========================================================== 266 | * Copyright 2013 Twitter, Inc. 267 | * 268 | * Licensed under the Apache License, Version 2.0 (the "License"); 269 | * you may not use this file except in compliance with the License. 270 | * You may obtain a copy of the License at 271 | * 272 | * http://www.apache.org/licenses/LICENSE-2.0 273 | * 274 | * Unless required by applicable law or agreed to in writing, software 275 | * distributed under the License is distributed on an "AS IS" BASIS, 276 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 277 | * See the License for the specific language governing permissions and 278 | * limitations under the License. 279 | * ========================================================== */ 280 | 281 | 282 | !function ($) { 283 | 284 | "use strict"; // jshint ;_; 285 | 286 | 287 | /* CAROUSEL CLASS DEFINITION 288 | * ========================= */ 289 | 290 | var Carousel = function (element, options) { 291 | this.$element = $(element) 292 | this.$indicators = this.$element.find('.carousel-indicators') 293 | this.options = options 294 | this.options.pause == 'hover' && this.$element 295 | .on('mouseenter', $.proxy(this.pause, this)) 296 | .on('mouseleave', $.proxy(this.cycle, this)) 297 | } 298 | 299 | Carousel.prototype = { 300 | 301 | cycle: function (e) { 302 | if (!e) this.paused = false 303 | if (this.interval) clearInterval(this.interval); 304 | this.options.interval 305 | && !this.paused 306 | && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) 307 | return this 308 | } 309 | 310 | , getActiveIndex: function () { 311 | this.$active = this.$element.find('.item.active') 312 | this.$items = this.$active.parent().children() 313 | return this.$items.index(this.$active) 314 | } 315 | 316 | , to: function (pos) { 317 | var activeIndex = this.getActiveIndex() 318 | , that = this 319 | 320 | if (pos > (this.$items.length - 1) || pos < 0) return 321 | 322 | if (this.sliding) { 323 | return this.$element.one('slid', function () { 324 | that.to(pos) 325 | }) 326 | } 327 | 328 | if (activeIndex == pos) { 329 | return this.pause().cycle() 330 | } 331 | 332 | return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos])) 333 | } 334 | 335 | , pause: function (e) { 336 | if (!e) this.paused = true 337 | if (this.$element.find('.next, .prev').length && $.support.transition.end) { 338 | this.$element.trigger($.support.transition.end) 339 | this.cycle(true) 340 | } 341 | clearInterval(this.interval) 342 | this.interval = null 343 | return this 344 | } 345 | 346 | , next: function () { 347 | if (this.sliding) return 348 | return this.slide('next') 349 | } 350 | 351 | , prev: function () { 352 | if (this.sliding) return 353 | return this.slide('prev') 354 | } 355 | 356 | , slide: function (type, next) { 357 | var $active = this.$element.find('.item.active') 358 | , $next = next || $active[type]() 359 | , isCycling = this.interval 360 | , direction = type == 'next' ? 'left' : 'right' 361 | , fallback = type == 'next' ? 'first' : 'last' 362 | , that = this 363 | , e 364 | 365 | this.sliding = true 366 | 367 | isCycling && this.pause() 368 | 369 | $next = $next.length ? $next : this.$element.find('.item')[fallback]() 370 | 371 | e = $.Event('slide', { 372 | relatedTarget: $next[0] 373 | , direction: direction 374 | }) 375 | 376 | if ($next.hasClass('active')) return 377 | 378 | if (this.$indicators.length) { 379 | this.$indicators.find('.active').removeClass('active') 380 | this.$element.one('slid', function () { 381 | var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()]) 382 | $nextIndicator && $nextIndicator.addClass('active') 383 | }) 384 | } 385 | 386 | if ($.support.transition && this.$element.hasClass('slide')) { 387 | this.$element.trigger(e) 388 | if (e.isDefaultPrevented()) return 389 | $next.addClass(type) 390 | $next[0].offsetWidth // force reflow 391 | $active.addClass(direction) 392 | $next.addClass(direction) 393 | this.$element.one($.support.transition.end, function () { 394 | $next.removeClass([type, direction].join(' ')).addClass('active') 395 | $active.removeClass(['active', direction].join(' ')) 396 | that.sliding = false 397 | setTimeout(function () { that.$element.trigger('slid') }, 0) 398 | }) 399 | } else { 400 | this.$element.trigger(e) 401 | if (e.isDefaultPrevented()) return 402 | $active.removeClass('active') 403 | $next.addClass('active') 404 | this.sliding = false 405 | this.$element.trigger('slid') 406 | } 407 | 408 | isCycling && this.cycle() 409 | 410 | return this 411 | } 412 | 413 | } 414 | 415 | 416 | /* CAROUSEL PLUGIN DEFINITION 417 | * ========================== */ 418 | 419 | var old = $.fn.carousel 420 | 421 | $.fn.carousel = function (option) { 422 | return this.each(function () { 423 | var $this = $(this) 424 | , data = $this.data('carousel') 425 | , options = $.extend({}, $.fn.carousel.defaults, typeof option == 'object' && option) 426 | , action = typeof option == 'string' ? option : options.slide 427 | if (!data) $this.data('carousel', (data = new Carousel(this, options))) 428 | if (typeof option == 'number') data.to(option) 429 | else if (action) data[action]() 430 | else if (options.interval) data.pause().cycle() 431 | }) 432 | } 433 | 434 | $.fn.carousel.defaults = { 435 | interval: 5000 436 | , pause: 'hover' 437 | } 438 | 439 | $.fn.carousel.Constructor = Carousel 440 | 441 | 442 | /* CAROUSEL NO CONFLICT 443 | * ==================== */ 444 | 445 | $.fn.carousel.noConflict = function () { 446 | $.fn.carousel = old 447 | return this 448 | } 449 | 450 | /* CAROUSEL DATA-API 451 | * ================= */ 452 | 453 | $(document).on('click.carousel.data-api', '[data-slide], [data-slide-to]', function (e) { 454 | var $this = $(this), href 455 | , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 456 | , options = $.extend({}, $target.data(), $this.data()) 457 | , slideIndex 458 | 459 | $target.carousel(options) 460 | 461 | if (slideIndex = $this.attr('data-slide-to')) { 462 | $target.data('carousel').pause().to(slideIndex).cycle() 463 | } 464 | 465 | e.preventDefault() 466 | }) 467 | 468 | }(window.jQuery);/* ============================================================= 469 | * bootstrap-collapse.js v2.3.2 470 | * http://getbootstrap.com/2.3.2/javascript.html#collapse 471 | * ============================================================= 472 | * Copyright 2013 Twitter, Inc. 473 | * 474 | * Licensed under the Apache License, Version 2.0 (the "License"); 475 | * you may not use this file except in compliance with the License. 476 | * You may obtain a copy of the License at 477 | * 478 | * http://www.apache.org/licenses/LICENSE-2.0 479 | * 480 | * Unless required by applicable law or agreed to in writing, software 481 | * distributed under the License is distributed on an "AS IS" BASIS, 482 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 483 | * See the License for the specific language governing permissions and 484 | * limitations under the License. 485 | * ============================================================ */ 486 | 487 | 488 | !function ($) { 489 | 490 | "use strict"; // jshint ;_; 491 | 492 | 493 | /* COLLAPSE PUBLIC CLASS DEFINITION 494 | * ================================ */ 495 | 496 | var Collapse = function (element, options) { 497 | this.$element = $(element) 498 | this.options = $.extend({}, $.fn.collapse.defaults, options) 499 | 500 | if (this.options.parent) { 501 | this.$parent = $(this.options.parent) 502 | } 503 | 504 | this.options.toggle && this.toggle() 505 | } 506 | 507 | Collapse.prototype = { 508 | 509 | constructor: Collapse 510 | 511 | , dimension: function () { 512 | var hasWidth = this.$element.hasClass('width') 513 | return hasWidth ? 'width' : 'height' 514 | } 515 | 516 | , show: function () { 517 | var dimension 518 | , scroll 519 | , actives 520 | , hasData 521 | 522 | if (this.transitioning || this.$element.hasClass('in')) return 523 | 524 | dimension = this.dimension() 525 | scroll = $.camelCase(['scroll', dimension].join('-')) 526 | actives = this.$parent && this.$parent.find('> .accordion-group > .in') 527 | 528 | if (actives && actives.length) { 529 | hasData = actives.data('collapse') 530 | if (hasData && hasData.transitioning) return 531 | actives.collapse('hide') 532 | hasData || actives.data('collapse', null) 533 | } 534 | 535 | this.$element[dimension](0) 536 | this.transition('addClass', $.Event('show'), 'shown') 537 | $.support.transition && this.$element[dimension](this.$element[0][scroll]) 538 | } 539 | 540 | , hide: function () { 541 | var dimension 542 | if (this.transitioning || !this.$element.hasClass('in')) return 543 | dimension = this.dimension() 544 | this.reset(this.$element[dimension]()) 545 | this.transition('removeClass', $.Event('hide'), 'hidden') 546 | this.$element[dimension](0) 547 | } 548 | 549 | , reset: function (size) { 550 | var dimension = this.dimension() 551 | 552 | this.$element 553 | .removeClass('collapse') 554 | [dimension](size || 'auto') 555 | [0].offsetWidth 556 | 557 | this.$element[size !== null ? 'addClass' : 'removeClass']('collapse') 558 | 559 | return this 560 | } 561 | 562 | , transition: function (method, startEvent, completeEvent) { 563 | var that = this 564 | , complete = function () { 565 | if (startEvent.type == 'show') that.reset() 566 | that.transitioning = 0 567 | that.$element.trigger(completeEvent) 568 | } 569 | 570 | this.$element.trigger(startEvent) 571 | 572 | if (startEvent.isDefaultPrevented()) return 573 | 574 | this.transitioning = 1 575 | 576 | this.$element[method]('in') 577 | 578 | $.support.transition && this.$element.hasClass('collapse') ? 579 | this.$element.one($.support.transition.end, complete) : 580 | complete() 581 | } 582 | 583 | , toggle: function () { 584 | this[this.$element.hasClass('in') ? 'hide' : 'show']() 585 | } 586 | 587 | } 588 | 589 | 590 | /* COLLAPSE PLUGIN DEFINITION 591 | * ========================== */ 592 | 593 | var old = $.fn.collapse 594 | 595 | $.fn.collapse = function (option) { 596 | return this.each(function () { 597 | var $this = $(this) 598 | , data = $this.data('collapse') 599 | , options = $.extend({}, $.fn.collapse.defaults, $this.data(), typeof option == 'object' && option) 600 | if (!data) $this.data('collapse', (data = new Collapse(this, options))) 601 | if (typeof option == 'string') data[option]() 602 | }) 603 | } 604 | 605 | $.fn.collapse.defaults = { 606 | toggle: true 607 | } 608 | 609 | $.fn.collapse.Constructor = Collapse 610 | 611 | 612 | /* COLLAPSE NO CONFLICT 613 | * ==================== */ 614 | 615 | $.fn.collapse.noConflict = function () { 616 | $.fn.collapse = old 617 | return this 618 | } 619 | 620 | 621 | /* COLLAPSE DATA-API 622 | * ================= */ 623 | 624 | $(document).on('click.collapse.data-api', '[data-toggle=collapse]', function (e) { 625 | var $this = $(this), href 626 | , target = $this.attr('data-target') 627 | || e.preventDefault() 628 | || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 629 | , option = $(target).data('collapse') ? 'toggle' : $this.data() 630 | $this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed') 631 | $(target).collapse(option) 632 | }) 633 | 634 | }(window.jQuery);/* ============================================================ 635 | * bootstrap-dropdown.js v2.3.2 636 | * http://getbootstrap.com/2.3.2/javascript.html#dropdowns 637 | * ============================================================ 638 | * Copyright 2013 Twitter, Inc. 639 | * 640 | * Licensed under the Apache License, Version 2.0 (the "License"); 641 | * you may not use this file except in compliance with the License. 642 | * You may obtain a copy of the License at 643 | * 644 | * http://www.apache.org/licenses/LICENSE-2.0 645 | * 646 | * Unless required by applicable law or agreed to in writing, software 647 | * distributed under the License is distributed on an "AS IS" BASIS, 648 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 649 | * See the License for the specific language governing permissions and 650 | * limitations under the License. 651 | * ============================================================ */ 652 | 653 | 654 | !function ($) { 655 | 656 | "use strict"; // jshint ;_; 657 | 658 | 659 | /* DROPDOWN CLASS DEFINITION 660 | * ========================= */ 661 | 662 | var toggle = '[data-toggle=dropdown]' 663 | , Dropdown = function (element) { 664 | var $el = $(element).on('click.dropdown.data-api', this.toggle) 665 | $('html').on('click.dropdown.data-api', function () { 666 | $el.parent().removeClass('open') 667 | }) 668 | } 669 | 670 | Dropdown.prototype = { 671 | 672 | constructor: Dropdown 673 | 674 | , toggle: function (e) { 675 | var $this = $(this) 676 | , $parent 677 | , isActive 678 | 679 | if ($this.is('.disabled, :disabled')) return 680 | 681 | $parent = getParent($this) 682 | 683 | isActive = $parent.hasClass('open') 684 | 685 | clearMenus() 686 | 687 | if (!isActive) { 688 | if ('ontouchstart' in document.documentElement) { 689 | // if mobile we we use a backdrop because click events don't delegate 690 | $('