1OW_DataModel = function( data ) 2{ 3 this.data = data || {}; 4 this.observers = []; 5}; 6 7OW_DataModel.PROTO = function() 8{ 9 var isEqual = function( x, y ) 10 { 11 if ( x === y ) return true; 12 if ( ! ( x instanceof Object ) || ! ( y instanceof Object ) ) return false; 13 if ( x.constructor !== y.constructor ) return false; 14 15 for ( var p in x ) 16 { 17 if ( ! x.hasOwnProperty( p ) ) continue; 18 if ( ! y.hasOwnProperty( p ) ) return false; 19 if ( x[ p ] === y[ p ] ) continue; 20 if ( typeof( x[ p ] ) !== "object" ) return false; 21 if ( !isEqual( x[ p ], y[ p ] ) ) return false; 22 } 23 24 for ( p in y ) 25 { 26 if ( y.hasOwnProperty( p ) && ! x.hasOwnProperty( p ) ) return false; 27 } 28 29 return true; 30 }; 31 32 this.get = function( key ) 33 { 34 if ( !key ) 35 { 36 return this.data; 37 } 38 39 var dataBranch = this.data, dataPath, out = null; 40 41 dataPath = key.split('.'); 42 43 for ( var i = 0; i < dataPath.length; i++ ) 44 { 45 if ( dataPath[i] in dataBranch ) 46 { 47 out = dataBranch[dataPath[i]]; 48 dataBranch = dataBranch[dataPath[i]]; 49 } 50 } 51 52 return out; 53 }; 54 55 this.set = function( key, value, notifyObservers ) 56 { 57 var self = this; 58 var notify = notifyObservers || true; 59 var changed = false; 60 61 if ( value === undefined && key ) 62 { 63 changed = changed || !isEqual(this.data, key); 64 this.data = key; 65 } 66 else 67 { 68 var i = 0, dataBranch = this.data, dataPath; 69 70 dataPath = key ? key.split('.') : []; 71 72 for ( i = 0; i < dataPath.length - 1; i++ ) 73 { 74 if ( !$.isPlainObject(dataBranch[dataPath[i]]) ) 75 { 76 dataBranch[dataPath[i]] = {}; 77 } 78 79 dataBranch = dataBranch[dataPath[i]]; 80 } 81 82 changed = changed || !isEqual(dataBranch[dataPath[i]], value); 83 dataBranch[dataPath[i]] = value; 84 } 85 86 if ( notify && changed ) 87 { 88 window.setTimeout(function() 89 { 90 self.notifyObservers(); 91 }); 92 } 93 }; 94 95 this.addObserver = function( observer, method ) 96 { 97 method = method || 'onDataChange'; 98 99 var _observer, self = this; 100 101 if ( $.isFunction(observer) ) 102 { 103 _observer = function() { 104 observer.call(self, self); 105 }; 106 } 107 else 108 { 109 _observer = function() { 110 observer[method].call(observer, self); 111 }; 112 } 113 114 this.observers.push(_observer); 115 }; 116 117 this.onChange = function(){}; 118 119 this.notifyObservers = function() 120 { 121 this.onChange(this); 122 123 $.each(this.observers, function(i, obs) 124 { 125 obs.call(); 126 }); 127 }; 128}; 129 130OW_DataModel.prototype = new OW_DataModel.PROTO(); 131 132 133OW_Console = function( params, modelsData ) 134{ 135 modelsData = modelsData || {}; 136 params = params || {}; 137 138 var self = this; 139 var _models = {}; 140 141 this.items = {}; 142 143 this.addItem = function( item, key ) 144 { 145 key = key || item.uniqId; 146 this.items[key] = item; 147 }; 148 149 this.getItem = function( key ) 150 { 151 return this.items[key]; 152 }; 153 154 this.getData = function( key ) 155 { 156 _models[key] = _models[key] || new OW_DataModel(); 157 158 return _models[key]; 159 }; 160 161 this.hideOtherContents = function( item ) 162 { 163 $.each(this.items, function(i, o) 164 { 165 if ( item != o ) 166 { 167 o.hideContent(); 168 } 169 }); 170 }; 171 172 this.hideAllContents = function() 173 { 174 $.each(this.items, function(i, o) 175 { 176 o.hideContent(); 177 }); 178 }; 179 180 $.each( modelsData, function (key, data) 181 { 182 self.getData(key).set(data); 183 }); 184 185 var command = OW.getPing().addCommand('consoleUpdate', 186 { 187 before: function() 188 { 189 var c = this; 190 191 $.each( _models, function (key, model) 192 { 193 c.params[key] = model.get(); 194 }); 195 }, 196 after: function( dataList ) 197 { 198 $.each( dataList, function (key, data) 199 { 200 self.getData(key).set(data); 201 }); 202 203 } 204 }); 205 206 window.setTimeout(function() 207 { 208 command.start(params.pingInterval); 209 }, params.pingInterval); 210}; 211 212 213 214 215 216 217 218 219 220 221OW_ConsoleItem = 222{ 223 animate: false, 224 opened: false, 225 226 init: function( uniqId, contentUniqId ) 227 { 228 var self = this; 229 230 this.uniqId = uniqId; 231 this.contentUniqId = contentUniqId; 232 233 this.$node = $('#' + this.uniqId); 234 this.$contentNode = $('#' + this.contentUniqId); 235 this._$tooltip = this.$contentNode.find('.console_tooltip'); 236 237 this.observers = []; 238 this.observers.notify = function(method) 239 { 240 for ( var i = 0; i < this.length; i++ ) 241 { 242 if ( this[i][method] ) 243 { 244 this[i][method].call(this[i], self); 245 } 246 } 247 }; 248 }, 249 250 getKey: function() 251 { 252 return this.uniqId; 253 }, 254 255 showItem: function() 256 { 257 this.$node.show(); 258 }, 259 260 hideItem: function() 261 { 262 if ( this.opened ) 263 { 264 this.hideContent(); 265 } 266 267 this.$node.hide(); 268 }, 269 270 showContent: function() 271 { 272 var self = this; 273 274 OW.Console.hideOtherContents(this); 275 276 if ( this.opened ) 277 { 278 return; 279 } 280 281 this.$contentNode.show(); 282 283 this.animate = true;
284 this._$tooltip.css({opacity: 0, top: this.$node.height() - 12}).stop(true, true).animate({top: this.$node.height(), opacity: 1}, 'fast', function() 285 { 286 self.animate = false; 287 OW.addScrolls(self.$contentNode); 288 self.observers.notify('afterShow'); 289 }); 290 291 this.opened = true; 292 this.observers.notify('beforeShow'); 293 294 295 this.onShow(); 296 this._onShow(); 297 }, 298 299 hideContent: function() 300 { 301 var self = this; 302 303 if ( !this.opened ) 304 { 305 return; 306 } 307 308 this.animate = true; 309 310 this.observers.notify('beforeHide'); 311 this._$tooltip.stop(true, true).animate({top: this.$node.height() - 12, opacity: 0}, 'fast', function() 312 { 313 self.animate = false; 314 self.observers.notify('afterHide'); 315 316 self.onHide(); 317 self._onHide(); 318 319 self.$contentNode.hide(); 320 }); 321 322 this.opened = false; 323 }, 324 325 //TODO replace this with bind 326 onShow: function() {}, 327 _onShow: function() {}, 328 onHide: function() {}, 329 _onHide: function() {}, 330 331 addObserver: function( observer ) 332 { 333 this.observers.push(observer); 334 } 335}; 336 337 338 339 340OW_ConsoleDropdownHover = function( uniqId, contentUniqId ) 341{ 342 this.init( uniqId, contentUniqId ); 343 344 var self = this; 345 var hideTimeout; 346 347 this.$node.hover(function() 348 { 349 if (self.animate) 350 { 351 return false; 352 } 353 354 if ( hideTimeout ) 355 { 356 window.clearTimeout(hideTimeout); 357 } 358 359 self.showContent(); 360 }, 361 function() 362 { 363 hideTimeout = window.setTimeout(function() 364 { 365 self.hideContent(); 366 }, 300); 367 }); 368} 369OW_ConsoleDropdownHover.prototype = OW_ConsoleItem; 370 371 372OW_ConsoleDropdownClick = function( uniqId, contentUniqId ) 373{ 374 this.init( uniqId, contentUniqId ); 375 376 this.initDropdown(); 377} 378$.extend(OW_ConsoleDropdownClick.prototype, OW_ConsoleItem, 379{ 380 initDropdown: function() 381 { 382 var self = this; 383 384 this.addObserver({ 385 beforeShow: function() 386 { 387 self.$node.addClass('ow_console_dropdown_pressed'); 388 }, 389 390 beforeHide: function() 391 { 392 self.$node.removeClass('ow_console_dropdown_pressed'); 393 } 394 }); 395 396 $(document).click(function( e ) 397 { 398 if ( !$(e.target).is(':visible') ) 399 { 400 return; 401 } 402 403 var isContent = self.$contentNode.find(e.target).length; 404 var isTarget = self.$node.is(e.target) || self.$node.find(e.target).length; 405 406 if ( isTarget && !isContent ) 407 { 408 if ( self.opened ) 409 { 410 self.hideContent(); 411 412 } 413 else 414 { 415 self.showContent(); 416 417 } 418 } 419 else if ( !isContent ) 420 { 421 self.hideContent(); 422 } 423 }); 424 } 425}); 426 427 428 429 430OW_ConsoleDropdownList = function( uniqId, contentUniqId ) 431{ 432 this.init( uniqId, contentUniqId ); 433 this.initDropdown(); 434 435 var $counter = $('.OW_ConsoleItemCounter', this.$node), 436 $number = $counter.find('.OW_ConsoleItemCounterNumber'), 437 $place = $counter.find('.OW_ConsoleItemCounterPlace'); 438 439 var shown = false, 440 currentNumber = null; 441 442 var numberSetActive = function( active ) 443 { 444 active = active === false ? false : true; 445 $place[ active ? 'addClass' : 'removeClass' ]('ow_count_active'); 446 } 447 448 var numberShow = function( number, animate ) 449 { 450 animate = animate === false ? false : true; 451 452 var placeWidth = $place.width(); 453 454 $number.text(number); 455 $number.css({visibility: "visible"}); 456 currentNumber = number; 457 458 var numberWidth = $number.outerWidth(); 459 $place.animate({width: numberWidth}, 'fast'); 460 461 if ( animate ) 462 { 463 $number.css({right: -placeWidth}).animate({right: 0}, 'fast'); 464 } 465 }; 466 467 var numberHide = function( callBack ) 468 { 469 var placeWidth = $place.width(); 470 471 $number.animate({right: placeWidth}, 'fast', callBack); 472 }; 473 474 var counterShow = function( callBack ) 475 { 476 var placeWidth; 477 478 $counter.show(); 479 placeWidth = $place.width(); 480 $place.css({width: 2}).animate({width: placeWidth}, 'fast', callBack); 481 482 shown = true; 483 }; 484 485 var counterHide = function( callBack ) 486 { 487 numberHide(function() 488 { 489 $place.animate({width: 0}, 'fast', function() 490 { 491 $number.text(0); 492 $place.css({width: 'auto'}); 493 $counter.hide(); 494 if ( $.isFunction(callBack) ) callBack.apply($counter.get(0)); 495 }); 496 }); 497 498 shown = false;
499 }; 500 501 // Public Methods 502 503 this.setCounter = function( number, active ) 504 { 505 var intNumber = parseInt(number); 506 intNumber = isNaN(intNumber) ? 0 : intNumber; 507 508 if ( intNumber <= 0 ) 509 { 510 counterHide(); 511 512 return; 513 } 514 515 if ( !shown ) 516 { 517 counterShow(function() 518 { 519 numberShow(number); 520 numberSetActive(active); 521 }); 522 } 523 else if ( number == currentNumber ) 524 { 525 numberSetActive(active); 526 } 527 else 528 { 529 numberHide(function() 530 { 531 numberShow(number); 532 numberSetActive(active); 533 }); 534 } 535 }; 536} 537OW_ConsoleDropdownList.prototype = OW_ConsoleDropdownClick.prototype; 538 539 540 541OW_ConsoleList = 542{ 543 construct: function( params ) 544 { 545 var self = this; 546 547 this.rsp = params.rsp; 548 this.key = params.key; 549 this.data = OW.Console.getData(this.key); 550 this.item = OW.Console.getItem(this.key); 551 552 this.$container = function() { 553 return $('.OW_ConsoleListContainer', self.$contentNode); 554 }; 555 556 this.$list = function() { 557 return $('.OW_ConsoleList', self.$container()); 558 }; 559 560 this.$preloader = function() { 561 return $('.OW_ConsoleListPreloader', self.$container()); 562 }; 563 564 this.$noContent = function() { 565 return $('.OW_ConsoleListNoContent', self.$container()); 566 }; 567 568 this.isListFull = false; 569 this.isListLoading = false; 570 this.isListLoaded = false; 571 572 this.item.onShow = function() 573 { 574 this.loadList(); 575 }; 576 577 this.item._onShow = function() 578 { 579 if ( this.isListLoaded ) 580 { 581 this.updateScroll(true); 582 } 583 }; 584 585 this.item._onHide = function() 586 { 587 OW.removeScroll(this.$container().get(0)); 588 }; 589 }, 590 591 clearList: function() 592 { 593 OW.removeScroll(this.$container().get(0)); 594 595 this.$list().empty(); 596 this.setIsListFull(false); 597 }, 598 599 loadList: function() 600 { 601 this.clearList(); 602 this.showPreloader(); 603 604 this.isListLoaded = false; 605 606 this._loadList(); 607 }, 608 609 _loadList: function() 610 { 611 if ( this.isListLoading ) 612 { 613 return; 614 } 615 616 var target = this.key; 617 var request = JSON.stringify({ 618 console: OW.Console.getData('console').get(), 619 data: this.data.get(), 620 target: target, 621 offset: this.getItemsCount(), 622 ids: this._getItemIds() 623 }); 624 625 this._ajaxStart(); 626 627 $.ajax({ 628 type: 'post', 629 url: this.rsp, 630 context: this, 631 dataType: 'json', 632 data: { 633 request: request 634 }, 635 success: this._ajaxSuccess, 636 complete: this._ajaxComplete 637 }); 638 }, 639 640 getItemsCount: function() 641 { 642 return this.getItems().length; 643 }, 644 645 _getItemIds: function() 646 { 647 var ids = []; 648 649 this.getItems().each(function() 650 { 651 var id = $(this).data('id'); 652 if ( id ) 653 { 654 ids.push(id); 655 } 656 }); 657 658 return ids; 659 }, 660 661 getItems: function() 662 { 663 return this.$list().children(); 664 }, 665 666 getItem: function( itemId ) 667 { 668 return $('#' + itemId, this.$list()); 669 }, 670 671 removeItem: function( item ) 672 { 673 var itemObject = $.type(item) == 'object' ? item : this.getItem(item); 674 itemObject.remove(); 675 676 if ( this.getItemsCount() == 0 ) 677 { 678 this.showNoContent(); 679 } 680 681 this.updateScroll(); 682 }, 683 684 addItems: function( items, updateScrooll ) 685 { 686 var self = this; 687 688 $.each(items, function(i, item) 689 { 690 var $item = $(item.html).data('id', item.id); 691 692 $item.find('.console_item_with_url').click(function( e ) 693 { 694 if ( !$(e.target).is('a') ) 695 { 696 //window.open($(this).data('url')); 697 window.location.href = $(this).data('url'); 698 } 699 }); 700 701 self.$list().append($item); 702 OW.trigger('base.onAddConsoleItem', [], $item); 703 }); 704 705 if ( updateScrooll !== false ) 706 { 707 this.updateScroll(); 708 } 709 710 }, 711 712 showPreloader: function() 713 { 714 this.$preloader().css({'visibility': 'visible'}); 715 this.$noContent().hide(); 716 }, 717 718 hidePreloader: function() 719 { 720 this.$preloader().css({'visibility': 'hidden'}); 721 }, 722 723 showNoContent: function() 724 { 725 this.$list().hide(); 726 this.$preloader().hide(); 727 this.$noContent().show(); 728 }, 729 730 hideNoContent: function() 731 { 732 this.$noContent().hide(); 733 this.$list().show(); 734 }, 735 736 updateScroll: function( toTop ) 737 { 738 var self = this; 739 740 toTop = toTop || false; 741 742 if ( this.opened ) 743 { 744 var hasScroll = false;
745 if ( this.$container().data().jsp ) 746 { 747 hasScroll = this.$container().data().jsp.getIsScrollableV(); 748 } 749 else 750 { 751 hasScroll = this.$container().innerHeight() < this.$container().get(0).scrollHeight 752 } 753 754 OW.removeScroll(this.$container().get(0)); 755 756 if ( !hasScroll ) 757 { 758 this.setIsListFull(true); 759 760 return; 761 } 762 763 var jsp = OW.addScroll(this.$container().get(0)); 764 765 if ( toTop ) 766 { 767 jsp.scrollToY(0, false); 768 } 769 770 this.$container().on('jsp-arrow-change', function( event, isAtTop, isAtBottom, isAtLeft, isAtRight ) 771 { 772 if ( self.isListFull ) 773 { 774 return; 775 } 776 777 if ( isAtBottom ) 778 { 779 self.showPreloader(); 780 self._loadList(); 781 } 782 }); 783 } 784 }, 785 786 setIsListFull: function( full ) 787 { 788 this.isListFull = full; 789 if ( full ) 790 { 791 this.$preloader().hide(); 792 } 793 else 794 { 795 this.$preloader().show(); 796 } 797 }, 798 799 _ajaxStart: function() 800 { 801 this.isListLoading = true; 802 }, 803 804 _ajaxComplete: function() 805 { 806 this.isListLoading = false; 807 this.hidePreloader(); 808 }, 809 810 _ajaxSuccess: function( resp ) 811 { 812 var self = this; 813 814 if ( resp && resp.data ) 815 { 816 this.data.set(resp.data); 817 } 818 819 if ( resp && resp.items.length ) 820 { 821 this.addItems(resp.items, false); 822 } 823 else 824 { 825 this.setIsListFull(true); 826 } 827 828 if( this.getItemsCount() == 0 ) 829 { 830 this.showNoContent(); 831 } 832 else 833 { 834 this.hideNoContent(); 835 } 836 837 if ( resp && resp.markup ) 838 { 839 if (resp.markup.styleSheets) 840 { 841 $.each(resp.markup.styleSheets, function(i, o) 842 { 843 OW.addCssFile(o); 844 }); 845 } 846 847 if (resp.markup.styleDeclarations) 848 { 849 OW.addCss(resp.markup.styleDeclarations); 850 } 851 852 if (resp.markup.beforeIncludes) 853 { 854 OW.addScript(resp.markup.beforeIncludes); 855 } 856 857 if (resp.markup.scriptFiles) 858 { 859 OW.addScriptFiles(resp.markup.scriptFiles, function() 860 { 861 if (resp.markup.onloadScript) 862 { 863 OW.addScript(resp.markup.onloadScript); 864 } 865 }); 866 } 867 else 868 { 869 if (resp.markup.onloadScript) 870 { 871 OW.addScript(markup.onloadScript); 872 } 873 } 874 } 875 876 var scrollToTop = !this.isListLoaded; 877 878 window.setTimeout(function() { 879 self.updateScroll(scrollToTop); 880 }); 881 882 883 this.isListLoaded = true; 884 } 885}; 886 887 888 889OW_Invitation = function( itemKey, params ) 890{ 891 var listLoaded = false; 892 893 var listLoaded = false; 894 var model, list, counter; 895 896 //public methods 897 898 this.removeItem = function( invitationKey ) 899 { 900 var item = list.getItem(invitationKey); 901 var c = {}; 902 903 if ( item.hasClass('ow_console_new_message') ) 904 { 905 c["new"] = counter.get("new") - 1; 906 } 907 c["all"] = counter.get("all") - 1; 908 counter.set(c); 909 910 list.removeItem(item); 911 912 return this; 913 }; 914 915 this.send = function( command, data ) 916 { 917 var request = $.ajax({ 918 url: params.rsp, 919 type: "POST", 920 data: { 921 "command": command, 922 "data": JSON.stringify(data) 923 }, 924 dataType: "json" 925 }); 926 927 request.done(function( res ) 928 { 929 if ( res && res.script ) 930 { 931 OW.addScript(res.script); 932 } 933 }); 934 935 return this; 936 }; 937 938 //code 939 940 model = OW.Console.getData(itemKey); 941 list = OW.Console.getItem(itemKey); 942 counter = new OW_DataModel(); 943 944 counter.addObserver(function() 945 { 946 var counterNumber = 0, 947 newCount = counter.get('new'); 948 counterNumber = newCount > 0 ? newCount : counter.get('all'); 949 950 list.setCounter(counterNumber, newCount > 0); 951 952 if ( counterNumber > 0 ) 953 { 954 list.showItem(); 955 } 956 }); 957 958 model.addObserver(function() 959 { 960 if ( !list.opened ) 961 { 962 counter.set(model.get('counter')); 963 } 964 965 if ( model.get('listFull') ) 966 { 967 list.setIsListFull(true); 968 } 969 }); 970 971 list.onHide = function() 972 { 973 list.getItems().removeClass('ow_console_new_message'); 974 counter.set('new', 0); 975 model.set('counter', counter.get()); 976 }; 977 978 list.onShow = function() 979 { 980 if ( counter.get('all') <= 0 ) 981 { 982 this.showNoContent(); 983 984 return; 985 } 986 987 if ( counter.get('new') > 0 || !listLoaded ) 988 { 989 this.loadList(); 990 listLoaded = true; 991 } 992 }; 993} 994 995OW.Invitation = null;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.