1 2/* 3 * Project: Mapper 1.0 4 * Description: Responsive html map area highlighter with area selection 5 * Author: 6 * License: 7 */ 8 9// the semi-colon before function invocation is a safety net against concatenated 10// scripts and/or other plugins which may not be closed properly. 11 12 13;(function ( $, window, document, undefined ) { 14 15 // undefined is used here as the undefined global variable in ECMAScript 3 is 16 // mutable (ie. it can be changed by someone else). undefined isn't really being 17 // passed in so we can ensure the value of it is truly undefined. In ES5, undefined 18 // can no longer be modified. 19 20 // window is passed through as local variable rather than global 21 // as this (slightly) quickens the resolution process and can be more efficiently 22 // minified (especially when both are regularly referenced in your plugin). 23 24 // Create the defaults once 25 var pluginName = 'mapoid', 26 defaults = { 27 propertyName: "value" 28 }; 29 30 // The actual plugin constructor 31 function mapoidPlugin( element, options ) { 32 //this.element = element; 33 34 // jQuery has an extend method which merges the contents of two or 35 // more objects, storing the result in the first object. The first object 36 // is generally empty as we don't want to alter the default options for 37 // future instances of the plugin 38 39 this.elem = element; 40 this.$elem = $(element); 41 this.$elem_original = this.$elem 42 this.options = options; 43 44 45 // This next line takes advantage of HTML5 data attributes 46 // to support customization of the plugin on a per-element 47 // basis. For example, 48 // <div class=item' data-plugin-options='{"message":"Goodbye World!"}'></div> 49 //this.metadata = this.$elem.data( 'plugin-options' ); 50 this.metadata = this.$elem.data( ); 51 52 this._init(); 53 54 55 } 56 57 58 59 //Plugin.prototype = 60 mapoidPlugin.prototype = 61 { 62 defaults: { 63 width : 600, 64 strokeColor: 'black', 65 strokeWidth: 1, 66 fillColor: 'black', 67 fillOpacity: 0.5, 68 fadeTime: 500, 69 selectedArea: false, 70 selectOnClick: true, 71 idtitulo: "#pueblo_titulo", 72 iddescripcion: "#pueblo_descripcion", 73 iddominio: "#pueblo_dominio", 74 75 click:false, 76 dblclick:false, 77 mousedown:false, 78 mouseup:false, 79 mouseover:false, 80 mouseout:false, 81 mousemove:false, 82 mouseenter:false, 83 mouseleave:false, 84 hoverIn:false, 85 hoverOut:false, 86 87 select:false, 88 deselect:false, 89 value: 0 90 }, 91 92 93 lang: { 94 textSelectAll: function () { return "Select all"; } 95 }, 96 97 98 value:function(value){ 99 return 5; 100 }, 101 102 _init: function() { 103 // Introduce defaults that can be extended either 104 // globally or using an object literal. 105 this.config = $.extend({}, this.defaults, this.options, 106 this.metadata); 107 //alert( JSON.stringify( this.lang.textSearching() ) ) 108 109 //alert( this.config.strokeWidth ) 110 //alert(42) 111 112 //this.isResponsive = false 113 //this.imageLoaded = false 114 this.map = this.$elem 115 116 this.selectedAreas = [] 117 118 var self = this 119 120 //self.mapLoaded = false 121 //self.coordsLoaded = false 122 //self.mapHidden = false 123 124 var mapName = self.$elem.attr('name') 125 self.image = $(document).find("img[usemap='#"+mapName+"']") 126 //self.imageSrc = self.image.attr('src') 127 //alert( self.$elem.attr('name') ) 128 129 var wrapper = $("<div class='wrp'></div>") 130 $("map[name="+mapName+"]").add("img[usemap='#"+mapName+"']").wrapAll(wrapper); 131 //}); 132 this.$elem = this.$elem.closest('div') 133 //this.elem = wrapper[0] 134 //alert( this.image.width() ) 135 136 //if( !self.image.is(':visible') ){ 137 138 //self.image.css('display','block') 139 //self.map.css('display','block') 140 //self.$elem.css('display','block') 141 142 //} 143 144 //alert( self.image.width() ) 145 //alert( self.image.css('width') ) 146 //self.map.on('show',function(){ 147 //alert(1) 148 //}) 149 //var w = this.image.attr('width') 150 //var h = this.image.attr('height') 151 //var wd = this.image.width() 152 //alert(w+" - "+wd) 153 154 self.mapHidden = ( self.mapIsVisible() ) ? false : true 155 156 //alert(self.mapHidden) 157 //if( !self.mapIsVisible() ) 158 // self.mapHidden = true 159 160 //alert( self.$elem.attr('name') ) 161 //$("map[name="+mapName+"],img[usemap='#"+mapName+"']").each(function(){ 162 163 //alert(self.mapIsVisible()) 164 //alert(1) 165 166 167 168 169 self._onImgLoad( self.image, function(img){ 170 171 //alert(img.height) 172 //self. 173 self.image.attr('width', img.width ) 174 self.image.attr('height', img.height ) 175 176 //alert(self.image.attr('width') ) 177 //alert(self.image.attr('height') ) 178 //alert(self.image.css('width') ) 179 //do something 180 //alert('map is not visible') 181 self._loadMap(); 182 183 184 185 //else 186 // 187 188 self._initEvents(); 189 190 191 $(window).resize(function() { 192 //self.resetMap( ); 193 //if(!self.mapLoaded) 194 //self._loadMap(); 195 self._reloadAreas() 196 self.selectAll(this.map); 197 198 //alert(s) 199 });
200 //self.imageLoaded = true 201 202 203 }) 204 205 206 207 return this; 208 209 210 }, 211 212 213 214 /** 215 * Returns a random integer between min (inclusive) and max (inclusive) 216 * Using Math.round() will give you a non-uniform distribution! 217 */ 218 _getRandomInt: function(min, max) { 219 return Math.floor(Math.random() * (max - min + 1)) + min; 220 }, 221 222 mapIsVisible : function() 223 { 224 var self = this 225 //console.log("Entra mapa "); 226 return ( self.map.is(':visible') && self.image.is(':visible') ) 227 //return true 228 229 //return false 230 231 }, 232 233 234 _loadMap : function(){ 235 236 var self = this 237 238 //self.mapLoaded = false 239 240 241 242 243 var i = self._getRandomInt(1,65000) 244 var j = self._getRandomInt(1,100) 245 246 //var j = Math.ceil(Math.random() * 100 + 1); 247 //var $this = $(this); 248 var $this = self.image 249 250 //alert($this.prop('tagName')) 251 252 253 254 //self._loadMap(); 255 //self._responsiveImage( ); 256 257 // redraw canvas of the selected areas 258 259 260 var cla = $this.attr('class') 261 //alert( $(this).attr('class') ) 262 //i = $(this).attr('class') 263 //i=j 264 //alert(cla) 265 266 //$this.attr('class', 'map'+i) 267 268 //$this.attr('usemap', '#map'+i) 269 //this.map.attr('name', 'map'+i) 270 271 //var this_class = $this.attr('class') 272 273 self.$elem.css({'position':'relative'}); 274 //alert(this_class) 275 //self.mlDrawIt(this_class); 276 277 //if (!document.all) { 278 //self.mlDrawCanvas('map'+i); 279 //} 280 281 //var mlSource = $this.attr('src'), 282 //idPrefix = mlSource.substr(mlSource.length - 1), 283 //mlThisID = $this.addClass('image'+j+idPrefix+i), 284 285 //mlMapName = $this.attr('usemap').replace('#',''), 286 //$that = $('map[name="'+mlMapName+'"]'), 287 /* $that = $this.nextAll('map').eq(0), */ 288 //mlThatID = $that.addClass('ml_map'+j+idPrefix+i); 289 290 //self.saveMapData( ); 291 292 //self._responsiveImage( ); 293 294 295 //self.isResponsive = false 296 297 if (typeof(self.image.attr('usemap')) == 'undefined') 298 return; 299 300 //return 301 302 //if( self.mapIsVisible() ) 303 self._redrawCoords() 304 305 306 if(self.config.selectedArea) 307 self._selectAreas( self.config.selectedArea ) 308 309 //console.log('mapa je nacitana') 310 311 312 //self.mapLoaded = true 313 314 315 316 317 318 }, 319 320 321 _redrawCoords : function() 322 { 323 324 var self = this 325 326 //self.coordsLoaded = false 327 328 //if(!self.mapIsVisible) 329 //return 330 331 332 var c = 'coords' 333 var w = self.image.attr('width') 334 var h = self.image.attr('height') 335 var wd = self.image.width() 336 //var hg = this.image.height() 337 //var wPercent = this.image.width()/100 338 //var hPercent = this.image.height()/100 339 340 var proportion = (wd / w) * 100; 341 342 343 344 self.map.find('area').each(function() 345 { 346 var $this = $(this); 347 348 if (!$this.data(c)) 349 $this.data(c, $this.attr(c)); 350 var coords = $this.data(c).split(','), 351 coordsPercent = new Array(coords.length); 352 for (var i = 0; i < coordsPercent.length; ++i) 353 { 354 coordsPercent[i] = ((coords[i])*proportion) / 100 355 356 } 357 358 //Change old coordinates to new 359 $this.attr(c, coordsPercent.toString()); 360 361 }); 362 363 //self.coordsLoaded = true 364 365 }, 366 367 _eventCallback : function(event, e, el){ 368 var self = this 369 370 371 if(self.config[event]) 372 { 373 var id = el.data('id') 374 if(typeof self.config[event] === 'function') 375 self.config[event]( e, el, id, self.selectedAreas ) 376 else 377 console.log( event + ' nie je funkcia111!') 378 379 return true 380 } 381 382 return false 383 384 }, 385 386 _reloadAreasIfHidden : function(){ 387 388 var self = this 389 if(self.mapHidden) 390 { 391 self._reloadAreas() 392 self.mapHidden = false; 393 } 394 395 }, 396 397 398 _reloadAreas : function(){ 399 400 var self = this 401 402 self.$elem.find('canvas').remove(); 403 404 if( !self.mapIsVisible() ) 405 { 406 self.mapHidden = true 407 console.log('mapa nie je vidiet') 408 return 409 } 410 411 412 self._redrawCoords() 413 414 var s = self.$elem.find('area.selected').each(function(k,v){ 415 416 var id = $(this).data('id') 417 var fixed = $(this).hasClass('fixed') 418 419 self._mapover( $(this), true, fixed ) 420 421 }) 422 423 }, 424 425 _initEvents : function(){ 426 427 var self = this 428 429 430 431 self.map.on('mouseover', 'area', function(e){
432 //console.log(14891) 433 //if(!self.coordsLoaded) 434 //if( !self.mapIsVisible() ) 435 436 self._reloadAreasIfHidden() 437 438 self._eventCallback('mouseover', e, $(this)) 439 440 self._mapover( $(this), false, false, true ) 441 //alert(1) 442 443 444 445 }) 446 447 448 449 self.map.on('mouseout', 'area', function(e){ 450 //console.log(tid) 451 452 self._eventCallback('mouseout', e, $(this)) 453 454 self.$elem.find('canvas.temp').fadeOut( self.config.fadeTime ) 455 //alert( $(this).closest('div').find('canvas').length ) 456 //alert(self.$elem.attr('class')) 457 //alert( self.$elem.find('canvas').length ) 458 459 460 461 }) 462 463 self.map.on('click', 'area', function(e){ 464 //console.log(tid) 465 e.preventDefault() 466 467 468 if(!self._eventCallback('click', e, $(this)) && !self.config.selectOnClick) 469 { 470 var href = $(this).attr('href') 471 if(href) 472 location.href = href; 473 } 474 475 else if(self.config.selectOnClick) 476 { 477 var id = parseInt( $(this).data('id') ) 478 479 //var selected = $(this).hasClass('selected') 480 var selected = self._inArray(self.selectedAreas, id) 481 var fixed = $(this).hasClass('fixed') 482 483 //if(!fixed) 484 { 485 if(!selected) 486 { 487 //self.selectedAreas.push(id) 488 self._selectArea(id,fixed,false) 489 490 491 } 492 else 493 { 494 self._deselectArea( id, false ) 495 496 497 } 498 } 499 //else 500 //alert(id) 501 //console.log( self.selectedAreas ) 502 } 503 504 505 506 507 508 //alert(href) 509 return false 510 511 512 //self.$elem.find('canvas.temp').fadeOut( self.config.fadeTime ) 513 }) 514 515 self.map.on('mousedown', 'area', function(e){ 516 self._eventCallback('mousedown', e, $(this)) 517 }) 518 self.map.on('mouseup', 'area', function(e){ 519 self._eventCallback('mouseup', e, $(this)) 520 }) 521 522 self.map.on('dblclick', 'area', function(e){ 523 self._eventCallback('dblclick', e, $(this)) 524 }) 525 526 self.map.on('mousemove', 'area', function(e){ 527 self._eventCallback('mousemove', e, $(this)) 528 }) 529 530 self.map.on('mouseenter', 'area', function(e){ 531 self._eventCallback('mouseenter', e, $(this)) 532 }) 533 self.map.on('mouseleave', 'area', function(e){ 534 self._eventCallback('mouseleave', e, $(this)) 535 }) 536 537 self.map.find('area').hover(function(e){ 538 self._eventCallback('hoverIn', e, $(this)) 539 }, function(e){ 540 self._eventCallback('hoverOut', e, $(this)) 541 }) 542 543 }, 544 545 _removeItem: function (array, item) 546 { 547 for (var i = 0; i < array.length; i++) 548 { 549 if(array[i]===item){ 550 array.splice(i,1); 551 break; 552 } 553 } 554 }, 555 556 _inArray: function (array, item) 557 { 558 for (var i = 0; i < array.length; i++) 559 { 560 if(array[i]===item){ 561 return true; 562 break; 563 } 564 } 565 566 return false; 567 }, 568 569 570 _onImgLoad: function ( image, cb ) 571 { 572 var self = this 573 var img = new Image; 574 //img.src = areaImg; 575 576 img.src = ( image[0].getAttribute ? image[0].getAttribute("src") : false) || image[0].src; 577 578 img.onload = function() { 579 580 cb(img) 581 582 } 583 584 585 //_getOrigImgSize : function( img ){ 586 //var t = new Image(); 587 //t.src = (img.getAttribute ? img.getAttribute("src") : false) || img.src; 588 //return {'w':t.width, 'h':t.height}; 589 //}, 590 591 }, 592 593 _onMapLoaded: function(cb) 594 { 595 var self = this 596 597 598 //if( this.mapLoaded && !this.coordsLoaded && self.mapIsVisible() ) 599 //{ 600 // self._redrawCoords() 601 602 // setTimeout(function(){ 603 // console.log('0000') 604 // self._onMapLoaded( cb ) 605 //},10) 606 //} 607 //else if(this.mapLoaded && this.coordsLoaded) 608 if( self.mapIsVisible() ) 609 { 610 611 self._onImgLoad( self.image, function(img){ 612 613 //if(self.mapHidden) 614 { 615 //self._redrawCoords() 616 //self.mapHidden = false; 617 } 618 619 cb() 620 //self._loadMap(); 621 //self._initEvents(); 622 623 //self.imageLoaded = true 624 }) 625 626 } 627 //else 628 { 629 //console.log('Public function denied - hidden') 630 631 //self._onImgLoad( self.image.attr('src'), function(img){ 632 //if( self.mapIsVisible() ) 633 //self._loadMap(); 634 //}) 635 636 //setTimeout(function(){ 637 //console.log('0000') 638 //self._onMapLoaded( cb ) 639 //},10) 640 } 641 642 643 }, 644 645 646 647 648 _mapover : function( area, selected, fixed, removeTemp ){ 649 650 var self = this 651 652 var area_id = parseInt( area.data('id') ) 653 if( isNaN(area_id) ) 654 { 655 area_id = self._getRandomInt(1,99999) 656 area.data('id', area_id) 657 //alert(id) 658 } 659 660 if(removeTemp) 661 self.$elem.find('canvas.temp').remove() 662 663 //cId = this._getRandomInt(1,60000) 664 665 var $img = self.image, 666 $bg_fill = $img.data('bg_fill'), 667 w = $img.width(), 668 h = $img.height(), 669 shapeSort = area.attr('shape'); 670 var canvas = $('<canvas data-id="'+area_id+'" width="'+w+'" height="'+h+'"></canvas>'); 671 //$img.parent().append(makeCanvas); 672 673 674 675 //alert(size.h ) 676 //canvas.width(w) 677 //canvas.height(h) 678 679 $img.parent().append(canvas); 680 //$('body').prepend(canvas); 681 //$img.parent().append('<canvas>blablabla</canvas>'); 682 //$img.parent().append('<>'); 683 684 if(!selected) 685 canvas.addClass('temp') 686 //$('#can'+cId).addClass('temp') 687 else 688 area.addClass('selected') 689 690 if(fixed) 691 area.addClass('fixed') 692 693 694 //var hmap = $(mlAreaID).closest('.hmap') 695 //this.$elem.find('.tarea'+tarea_id+' .ttitle').addClass('hovered') 696 var bg_fill = self.$elem.find('.fill').css('background-color') 697 var bg_opacity = self.$elem.find('.fill').css('opacity') 698 //console.log( bg_opacity ) 699 //alert(area) 700 //self.$elem.css({'width':'auto','height':'auto',}) 701 702 //var o = self.$elem.offset(); 703 //var x = self.$elem.position(); 704 //alert(o.top) 705 //alert(x.top) 706 //alert("Top: " + x.top + " Left: " + x.left); 707 708 /* 709 *
710 * pointer-events:none makes canvas layer invisible to mouse events in most modern browsers 711 * allowing map area to still be clickable through the canvas layer. 712 * For IE browsers less than 11 the highlighting is disabled in DrawIt function. 713 * 714 */ 715 //canvas.parent().css({'position':'relative'}) 716 canvas.css({ 717 'width': w+'px', 718 'height': h+'px', 719 'display': 'block', 720 'position':'absolute', 721 'top': '0px', 722 'left': '0px', 723 'pointer-events':'none', 724 //'z-index':'9999' 725 }); 726 //var $canvas = document.getElementById('can'+cId), 727 var $canvas = canvas[0], 728 context = $canvas.getContext('2d'); 729 // context.clearRect(0, 0, $canvas.width, $canvas.height); 730 731 //$canvas.width = w; 732 //$canvas.height = h; 733 var cox,coy 734 var coords = area.attr('coords').split(','), 735 cox = []; 736 coy = []; 737 for(var i = 0; i < coords.length; i++) { 738 if(i % 2 == 0) { 739 cox.push(coords[i]); 740 } 741 else { 742 coy.push(coords[i]); 743 } 744 } 745 746 //alert(coords) 747 /* Shape coordinate apportioning */ 748 749 var showCanvas = true 750 var area_img = area.data('img'); 751 752 753 754 755 var mainImgSrc = self.image.attr('src') 756 757 758 //alert(self.image.attr('src')) 759 760 //self.onImgLoad(mainImgSrc, function(im){ 761 762 763 if(area_img && shapeSort == 'poly') 764 { 765 showCanvas = false 766 //area_img = base_url+area_img; 767 768 self._onImgLoad(area_img, function(img){ 769 770 var min_x = Math.min.apply(null, cox); 771 var min_y = Math.min.apply(null, coy); 772 var max_x = Math.max.apply(null, cox); 773 var max_y = Math.max.apply(null, coy); 774 775 var f_w = max_x - min_x 776 var f_h = max_y - min_y 777 //console.log(f_w+" "+f_h) 778 779 context.drawImage(img,min_x,min_y, f_w, f_h); 780 canvas.hide().fadeIn( self.config.fadeTime ) 781 782 }) 783 784 } 785 else 786 { 787 788 context.fillStyle = self.config.fillColor; 789 context.lineWidth = self.config.strokeWidth; 790 context.strokeStyle = self.config.strokeColor; 791 context.globalAlpha = self.config.fillOpacity 792 793 if(shapeSort == 'rect') 794 { 795 context.fillRect(cox[0],coy[0],cox[1]-cox[0],coy[1]-coy[0]); 796 797 if(self.config.strokeWidth > 0) 798 context.strokeRect(cox[0],coy[0],cox[1]-cox[0],coy[1]-coy[0]); 799 } 800 else 801 { 802 context.beginPath(); 803 804 if(shapeSort == 'poly' ) 805 { 806 807 context.moveTo(cox[0],coy[0]); 808 for(var j = 1; j < cox.length; j++) { 809 context.lineTo(cox[j],coy[j]); 810 } 811 context.closePath(); 812 } 813 else if(shapeSort == 'circle') 814 { 815 816 context.arc(cox[0],coy[0],cox[1],0,Math.PI*2,true);
817 //context.fillStyle = 'rgba('+Math.floor((Math.random() * 255) + 1)+','+Math.floor((Math.random() * 255) + 1)+','+Math.floor((Math.random() * 100) + 1)+',0.3)'; 818 } 819 820 if(self.config.fillColor) 821 context.fill(); 822 if(self.config.strokeWidth > 0) 823 context.stroke(); 824 825 } 826 827 828 if(showCanvas) 829 canvas.hide().fadeIn( self.config.fadeTime ) 830 } 831 832 //}) 833 834 835 }, 836 837 _selectArea: function( id, fixed, showCanvas ) 838 { 839 var self = this 840 841 id = parseInt( id ) 842 843 var el = self.$elem.find("area[data-id='"+id+"']") 844 var selected = el.hasClass('selected') 845 var cnv = self.$elem.find('canvas[data-id="'+id+'"]') 846 847 848 //alert(self.mapHidden) 849 if( self.mapIsVisible() ) 850 { 851 self._reloadAreasIfHidden() 852 } 853 else 854 self.mapHidden = true 855 856 //{ 857 //console.log('ID '+id+' nemozem vybrat, mapa nie je viditelna!') 858 //return false; 859 //} 860 861 if(selected) 862 { 863 console.log('ID '+id+' seleccionado!') 864 return false; 865 } 866 867 if(fixed !== true) 868 fixed = false 869 870 if(el.length > 0) 871 { 872 self.$elem.find('canvas[data-id="'+id+'"]:last').removeClass('temp') 873 el.addClass('selected') 874 cnv.removeClass('temp') 875 self.selectedAreas.push(id) 876 if(showCanvas) 877 self._mapover( el, true, fixed ) 878 879 self._eventCallback('select', false, el ) 880 // Si se activa actualizar datos 881 //console.log("Activando"+el.attr("data-titulo")); 882 self._updateCartel(el); 883 } 884 else 885 console.log('El ID '+id+' no existe en el mapa!') 886 }, 887 888 _updateCartel: function(area){ 889 $(this.config.idtitulo).text(area.attr("data-titulo")); 890 $(this.config.iddescripcion).text(area.attr("data-descripcion")); 891 $(this.config.iddominio).html("<a href="+area.attr("href")+">"+area.attr("href")+"</a>"); 892 //alert(area.attr("data-titulo")); 893 //alert(this.config.idtitulo); 894 }, 895 896 _deselectArea: function( id, hideCanvas ) 897 { 898 var self = this 899 900 id = parseInt( id ) 901 902 var el = self.$elem.find("area[data-id='"+id+"']") 903 var cnv = self.$elem.find('canvas[data-id="'+id+'"]') 904 var selected = el.hasClass('selected') 905 var fixed = el.hasClass('fixed') 906 907 if(!selected || fixed) 908 { 909 //console.log('ID '+id+' je uz zrusene!') 910 return false; 911 } 912 913 //if(fixed !== true) 914 //fixed = false 915 916 if(el.length > 0) 917 { 918 cnv.addClass('temp') 919 920 if( cnv.length > 1 || hideCanvas ) 921 { 922 self.$elem.find('canvas[data-id="'+id+'"]:last').fadeOut( self.config.fadeTime ) 923 } 924 el.removeClass('selected') 925 926 self._removeItem( self.selectedAreas, id ) 927 928 self._eventCallback( 'deselect', false, el ) 929 } 930 else 931 console.log('Plocha s ID '+id+' na mape neexistuje!') 932 }, 933 934 935 _selectAreas: function( obj, sec, callback ) 936 { 937 938 var self = this 939 var sec_init = sec 940 var length=obj.length 941 942 function doSetTimeout(i,id,fixed) { 943 setTimeout(function() { 944 self._selectArea(id,fixed,true) 945 self._doCallback(i,length,sec,callback) 946 }, sec_init); 947 sec_init += sec 948 949 } 950 //console.log('l- '+obj.length) 951 for(var i=0; i<length; i++) 952 { 953 var id = parseInt(obj[i].id) 954 var fixed = (obj[i].fixed === true ? true : false ) 955 //var fixed = val.fixed 956 //alert(id) 957 //var isLast = (i == length-1) 958 //alert(id + ' is last') 959 if(sec) 960 { 961 doSetTimeout(i,id,fixed) 962 //setTimeout(function(){ 963 964 965 //console.log('ssssss') 966 //if(isLast) 967 //callback() 968 //}, sec_init) 969 //sec_init += sec 970 } 971 else 972 { 973 self._selectArea(id,fixed,true) 974 self._doCallback(i,length,sec,callback) 975 } 976 } 977 //$.each( obj, function(key, val){ 978 //var id = parseInt(key) 979 //var fixed = val.fixed 980 //alert(val) 981 982 983 //}) 984 }, 985 986 _doCallback: function(i,length,sec,callback) { 987 var self = this 988 if( i === length-1 && typeof callback === 'function') 989 { 990 if(sec>0) 991 setTimeout(function(){ 992 callback( self.map, self.selectedAreas ) 993 }, sec) 994 else 995 callback( self.map, self.selectedAreas ) 996 } 997 }, 998 999 _deselectAreas: function( obj, sec, callback ) 1000 { 1001 var self = this 1002 var sec_init = sec 1003 var length=obj.length 1004 1005 1006 function doSetTimeout(i,id) { 1007 setTimeout(function() { 1008 self._deselectArea( id, true ) 1009 self._doCallback(i,length,sec,callback) 1010 }, sec_init); 1011 sec_init += sec 1012 1013 } 1014 1015 //$.each( obj, function(key, val){ 1016 1017 for(var i=0; i<length; i++) 1018 { 1019 var id = parseInt(obj[i].id) 1020 //var fixed = (obj[i].fixed === true ? true : false ) 1021 1022 //var id = parseInt(key)
1023 //var fixed = val.fixed 1024 1025 if(sec) 1026 { 1027 doSetTimeout(i,id) 1028 1029 //setTimeout(function(){ 1030 //self._selectArea(id,fixed,true) 1031 //self._deselectArea( id, true ) 1032 //}, sec_init) 1033 //sec_init += sec 1034 } 1035 else 1036 { 1037 self._deselectArea( id, true ) 1038 self._doCallback(i,length,sec,callback) 1039 } 1040 1041 1042 } 1043 }, 1044 1045 1046 1047 isSelected: function( id ) 1048 { 1049 var self = this 1050 1051 if ( self._inArray( self.selectedAreas, id) ) 1052 return true 1053 1054 return false 1055 }, 1056 1057 isFixed: function( id ) 1058 { 1059 var self = this 1060 var el = self.$elem.find("area[data-id='"+id+"']") 1061 1062 if ( el.hasClass('fixed') ) 1063 return true 1064 1065 return false 1066 }, 1067 1068 getSelected: function( ) 1069 { 1070 return this.selectedAreas; 1071 }, 1072 1073 getAll: function( ) 1074 { 1075 var self = this 1076 var ids = [] 1077 1078 self.$elem.find('area').each( function(key, val){ 1079 var el = $(this) 1080 var id = parseInt( el.data('id') ) 1081 //var fixed = val.fixed 1082 //alert(val) 1083 ids.push( {'id':id} ) 1084 //ids[id] = {} 1085 //self._selectArea(id,fixed,true) 1086 }) 1087 1088 return ids; 1089 }, 1090 1091 1092 1093 1094 selectOne: function( id, fixed ) 1095 { 1096 var self = this 1097 1098 self._onMapLoaded( function(){ 1099 1100 self._selectArea(id,fixed,true) 1101 }) 1102 1103 1104 }, 1105 1106 1107 selectAll: function( sec, callback ) 1108 { 1109 var self = this 1110 //console.log("Entrando"); 1111 var obj = self.getAll() 1112 //alert(obj) 1113 self.selectMany( obj, sec, callback ) 1114 1115 1116 }, 1117 1118 deselectAll: function( sec, callback ) 1119 { 1120 var self = this 1121 1122 var obj = self.getAll() 1123 //alert(obj) 1124 self.deselect( obj, sec, callback ) 1125 }, 1126 1127 1128 selectMany: function( obj, sec, callback ) 1129 { 1130 var self = this 1131 1132 1133 1134 self._onMapLoaded( function(){ 1135 1136 self._selectAreas(obj, sec, callback) 1137 1138 //callback() 1139 }) 1140 1141 1142 1143 1144 //alert(event) 1145 //alert(id) 1146 }, 1147 1148 deselect: function( obj, sec, callback ) 1149 { 1150 var self = this 1151 self._deselectAreas(obj, sec, callback) 1152 }, 1153 1154 removeFixed: function( obj ) 1155 { 1156 var self = this 1157 //self._deselectAreas(obj, sec, callback) 1158 for(var i=0; i<obj.length; i++) 1159 { 1160 var id = parseInt( obj[i].id ) 1161 var el = self.$elem.find("area[data-id='"+id+"']") 1162 var cnv = self.$elem.find('canvas[data-id="'+id+'"]') 1163 cnv.remove() 1164 el.removeClass('selected').removeClass('fixed') 1165 self._removeItem( self.selectedAreas, id ) 1166 1167 //alert(obj[i].id) 1168 } 1169 1170 }, 1171 1172 1173 changeConfig: function( key, value ) 1174 { 1175 var self = this 1176 self.config[ key ] = value 1177 } 1178 1179 /* 1180 mlDrawCanvas : function(){ 1181 1182 //var mlImageClass = document.getElementsByClassName(imageClass)[0], 1183 var $image = this.image, 1184 //$image = $("."+imageClass), 1185 w = $image.width(), 1186 h = $image.height(); 1187 1188 if($image.siblings('canvas')) { 1189 $image.siblings('canvas').remove(); 1190 } 1191 1192 mlGetMapName = $image.attr('usemap').replace('#',''), 1193 theMap = $('map[name="'+mlGetMapName+'"]').addClass('mlHighlight'), 1194 wrapped = $('<div id="wrap'+mlGetMapName+'image"></div>'); 1195 //wrapped = $('<div class="wrapper"></div>'); 1196 1197 if($image.parent('#wrap'+mlGetMapName+'image').length) { 1198 $image.unwrap(); 1199 } 1200 $image.wrap(wrapped); 1201 1202 1203 var $wrap = $('#wrap'+mlGetMapName+'image'); 1204 1205 var opts = { 1206 'position':'relative', 1207 'margin':'0 auto', 1208 'line-height':'0', 1209 'width':w 1210 } 1211 if($wrap.parent().width() < $image.attr('width')) 1212 opts.width = 'auto' 1213 1214 1215 this.$elem.css(opts); 1216 1217 1218 var index = 0; 1219 //Adds function atts to all areas on image map 1220 theMap.children('area').each(function() { 1221 var $this = $(this); 1222 index++; 1223 $this.attr('id',mlGetMapName+'area'+index); 1224 // World Map add-ons // 1225 $this.attr('target','_blank'); 1226 var atTitle = $this.attr('alt'); 1227 //$this.attr('href') ? $this.attr('href') : $this.attr('href', 'http://en.wikipedia.org/wiki/'+atTitle); 1228 $this.attr('href') ? $this.attr('href') : $this.attr('href', ''); 1229 // End World Map add-ons // 1230 $this.attr('title') ? $this.attr('title') : $this.attr('title',atTitle); 1231 1232 //var cb = 'mapover('+$this.attr('id')+');' 1233 //$this.attr('onmouseover','mapover('+$this.attr('id')+');').attr('onmouseout','mapout('+$this.attr('id')+');');
1234 //$this.attr('onmouseover', cb).attr('onmouseout'); 1235 1236 1237 }); 1238 1239 1240 //var a = theMap.children('area:first') 1241 //var b = theMap.children('area:last') 1242 1243 //b.mouseover(); mouseover 1244 1245 1246 } 1247 */ 1248 1249 } 1250 1251 // You don't need to change something below: 1252 // A really lightweight plugin wrapper around the constructor, 1253 // preventing against multiple instantiations and allowing any 1254 // public function (ie. a function whose name doesn't start 1255 // with an underscore) to be called via the jQuery plugin, 1256 // e.g. $(element).defaultPluginName('functionName', arg1, arg2) 1257 $.fn[pluginName] = function ( options ) { 1258 var args = arguments; 1259 1260 // Is the first parameter an object (options), or was omitted, 1261 // instantiate a new instance of the plugin. 1262 if (options === undefined || typeof options === 'object') { 1263 return this.each(function () { 1264 1265 // Only allow the plugin to be instantiated once, 1266 // so we check that the element has no plugin instantiation yet 1267 if (!$.data(this, 'plugin_' + pluginName)) { 1268 1269 // if it has no instance, create a new one, 1270 // pass options to our plugin constructor, 1271 // and store the plugin instance 1272 // in the elements jQuery data object. 1273 $.data(this, 'plugin_' + pluginName, new mapoidPlugin( this, options )); 1274 } 1275 }); 1276 1277 // If the first parameter is a string and it doesn't start 1278 // with an underscore or "contains" the `init`-function, 1279 // treat this as a call to a public method. 1280 } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') { 1281 1282 // Cache the method call 1283 // to make it possible 1284 // to return a value 1285 var returns; 1286 1287 this.each(function () { 1288 var instance = $.data(this, 'plugin_' + pluginName); 1289 1290 // Tests that there's already a plugin-instance 1291 // and checks that the requested public method exists 1292 if (instance instanceof mapoidPlugin && typeof instance[options] === 'function') { 1293 //alert( options ) 1294 // Call the method of our plugin instance, 1295 // and pass it the supplied arguments. 1296 returns = instance[options].apply( instance, Array.prototype.slice.call( args, 1 ) ); 1297 } 1298 1299 // Allow instances to be destroyed via the 'destroy' method 1300 if (options === 'destroy') { 1301 $.data(this, 'plugin_' + pluginName, null); 1302 } 1303 }); 1304 1305 // If the earlier cached method 1306 // gives a value back return the value, 1307 // otherwise return this to preserve chainability. 1308 return returns !== undefined ? returns : this; 1309 } 1310 }; 1311 1312}(jQuery, window, document));
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.