kaerus-component-slideshow 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 9623d33cdb055350d09cc5d1717b2a78be468bbb
         | 
| 4 | 
            +
              data.tar.gz: 08229965f72b944821118c69ef85423c36585ab9
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 538fe6b9b7d4a90cd4f9434a3c82c7a651104bafa9735782a2f7bca212396a4f18e818dd5954e7703a70de245c0740fd356df7ef24dd448f1629b3188074de72
         | 
| 7 | 
            +
              data.tar.gz: 4ec530f96a540bfe2563e2908392f491f4bf44a2873d6cd3b5e2f9a12e3bdc82f44505084ecd45a107675ee73cdcc6b09cb2d7603edc6ec3e98896cf6f1408ea
         | 
| @@ -422,11 +422,6 @@ require.register("slideshow/index.js", function(exports, require, module){ | |
| 422 422 | 
             
            var Carousel = require('carousel'),
         | 
| 423 423 | 
             
                template = require('./template');
         | 
| 424 424 |  | 
| 425 | 
            -
            var transitionProp = ['webkitTransition','mozTransition','msTransition','oTransition'],
         | 
| 426 | 
            -
                transitionEndEvents = ['transitionend', 'webkitTransitionEnd', 'otransitionend'],
         | 
| 427 | 
            -
                transformProp = ['webkitTransform','mozTransform','msTransform','oTransform'];
         | 
| 428 | 
            -
             | 
| 429 | 
            -
             | 
| 430 425 | 
             
            function Slideshow(container,options){
         | 
| 431 426 | 
             
            	if(!(this instanceof Slideshow))
         | 
| 432 427 | 
             
            		return new Slideshow(container,options);
         | 
| @@ -436,7 +431,7 @@ function Slideshow(container,options){ | |
| 436 431 |  | 
| 437 432 | 
             
                if(!container) throw new Error("invalid slideshow container");
         | 
| 438 433 |  | 
| 439 | 
            -
                 | 
| 434 | 
            +
                this.settings = {
         | 
| 440 435 | 
             
                    id: container.id || 'slideshow',
         | 
| 441 436 | 
             
                    template: template,
         | 
| 442 437 | 
             
                    next:'⟩',
         | 
| @@ -447,60 +442,98 @@ function Slideshow(container,options){ | |
| 447 442 | 
             
                    afterTransit: undefined
         | 
| 448 443 | 
             
                };
         | 
| 449 444 |  | 
| 450 | 
            -
                mergeOptions(settings,options);
         | 
| 451 | 
            -
             | 
| 445 | 
            +
                mergeOptions(this.settings,options);
         | 
| 446 | 
            +
             | 
| 447 | 
            +
                Object.defineProperty(this,'paused',{
         | 
| 448 | 
            +
                    get: function() {
         | 
| 449 | 
            +
                        return this.carousel.paused;
         | 
| 450 | 
            +
                    }
         | 
| 451 | 
            +
                });
         | 
| 452 452 |  | 
| 453 453 | 
             
            	this.init(container);
         | 
| 454 454 | 
             
            }
         | 
| 455 455 |  | 
| 456 | 
            -
            Slideshow.prototype =  | 
| 457 | 
            -
             | 
| 456 | 
            +
            Slideshow.prototype = {
         | 
| 457 | 
            +
                    init: function(container,options){
         | 
| 458 | 
            +
                        var settings = this.settings,
         | 
| 459 | 
            +
                            id = settings.id,
         | 
| 460 | 
            +
                            slides = '\n', 
         | 
| 461 | 
            +
                            dots = '\n', 
         | 
| 462 | 
            +
                            navId = id + '-nav',
         | 
| 463 | 
            +
                            childs = container.childNodes;
         | 
| 464 | 
            +
             | 
| 465 | 
            +
                        /* get slides from parent container */
         | 
| 466 | 
            +
                        for(var i = 0, n = 0, l = childs.length; i < l; i++){
         | 
| 467 | 
            +
                            if(childs[i].nodeType === 1){ 
         | 
| 468 | 
            +
                                slides+= '<div id="'+ id + '-s' + n + '">' + childs[i].outerHTML + '</div>\n';
         | 
| 469 | 
            +
                                dots+='<li class="dot" id="' + navId + n + '"></li>\n';
         | 
| 470 | 
            +
                                n++;
         | 
| 471 | 
            +
                            }    
         | 
| 472 | 
            +
                        }
         | 
| 473 | 
            +
             | 
| 474 | 
            +
                        /* create dom structure from template */
         | 
| 475 | 
            +
                        var template = settings.template.replace(/{\w+}/mg,function(m){
         | 
| 476 | 
            +
                            switch(m){
         | 
| 477 | 
            +
                                case "{id}": return id;
         | 
| 478 | 
            +
                                case "{slides}": return slides;
         | 
| 479 | 
            +
                                case "{next}": return settings.next;
         | 
| 480 | 
            +
                                case "{prev}": return settings.prev; 
         | 
| 481 | 
            +
                                case "{nav}": return dots;
         | 
| 482 | 
            +
                            }
         | 
| 483 | 
            +
                        });
         | 
| 484 | 
            +
             | 
| 485 | 
            +
                        /* apply slider template */
         | 
| 486 | 
            +
                        container.innerHTML = template;
         | 
| 487 | 
            +
                        /* add slideshow class to target container */
         | 
| 488 | 
            +
                        if(!container.className) container.className = 'slideshow';
         | 
| 489 | 
            +
                        else container.className+= ' slideshow';
         | 
| 458 490 |  | 
| 459 | 
            -
             | 
| 460 | 
            -
             | 
| 461 | 
            -
                        slideshow = this;
         | 
| 491 | 
            +
                        /* create newcarousel instance */
         | 
| 492 | 
            +
                        this.carousel = new Carousel(id+'-slides');
         | 
| 462 493 |  | 
| 463 | 
            -
                         | 
| 494 | 
            +
                        this.slides = this.carousel.slides;
         | 
| 464 495 |  | 
| 465 | 
            -
                         | 
| 496 | 
            +
                        attachHandlers(this);        
         | 
| 497 | 
            +
             | 
| 498 | 
            +
                        return this;        
         | 
| 466 499 | 
             
                    },
         | 
| 467 500 | 
             
                    start: function(){
         | 
| 468 | 
            -
                        carousel.start(0, | 
| 501 | 
            +
                        this.carousel.start(0,this.settings.time);
         | 
| 469 502 |  | 
| 470 503 | 
             
                        return this;
         | 
| 471 504 | 
             
                    },
         | 
| 472 505 | 
             
                    stop: function(){
         | 
| 473 | 
            -
                        carousel.stop();
         | 
| 506 | 
            +
                        this.carousel.stop();
         | 
| 474 507 |  | 
| 475 508 | 
             
                        return this;
         | 
| 476 509 | 
             
                    },
         | 
| 477 510 | 
             
                    pause: function(){
         | 
| 478 | 
            -
                        carousel.pause();
         | 
| 511 | 
            +
                        this.carousel.pause();
         | 
| 479 512 |  | 
| 480 513 | 
             
                        return this;
         | 
| 481 514 | 
             
                    },
         | 
| 482 515 | 
             
                    next: function(){
         | 
| 483 | 
            -
                        carousel.next();
         | 
| 516 | 
            +
                        this.carousel.next();
         | 
| 484 517 |  | 
| 485 518 | 
             
                        return this;
         | 
| 486 519 | 
             
                    },
         | 
| 487 | 
            -
                     | 
| 488 | 
            -
                        carousel.prev();
         | 
| 520 | 
            +
                    prev: function(){
         | 
| 521 | 
            +
                        this.carousel.prev();
         | 
| 489 522 |  | 
| 490 523 | 
             
                        return this;
         | 
| 491 524 | 
             
                    },
         | 
| 492 525 | 
             
                    resume: function(){
         | 
| 493 | 
            -
                        carousel.resume;
         | 
| 526 | 
            +
                        this.carousel.resume();
         | 
| 494 527 |  | 
| 495 528 | 
             
                        return this;
         | 
| 496 529 | 
             
                    },
         | 
| 497 530 | 
             
                    show: function(x){
         | 
| 498 | 
            -
                        carousel.show(x);
         | 
| 531 | 
            +
                        this.carousel.show(x);
         | 
| 499 532 |  | 
| 500 533 | 
             
                        return this;
         | 
| 501 534 | 
             
                    },
         | 
| 502 535 | 
             
                    display: function(value){
         | 
| 503 | 
            -
                        var slides = document.getElementById( | 
| 536 | 
            +
                        var slides = document.getElementById(this.settings.id);
         | 
| 504 537 |  | 
| 505 538 | 
             
                        if(typeof value === 'string') slides.style.display = value;
         | 
| 506 539 | 
             
                        else if(!!value) slides.style.display = 'block';
         | 
| @@ -508,58 +541,35 @@ Slideshow.prototype = (function(){ | |
| 508 541 |  | 
| 509 542 | 
             
                        return this;
         | 
| 510 543 | 
             
                    }
         | 
| 511 | 
            -
             | 
| 512 | 
            -
             | 
| 513 | 
            -
                function setup(container){
         | 
| 514 | 
            -
                    var slides = '\n', 
         | 
| 515 | 
            -
                        dots = '\n', 
         | 
| 516 | 
            -
                        navId = slideshow.id + '-nav',
         | 
| 517 | 
            -
                        childs = container.childNodes;
         | 
| 518 | 
            -
             | 
| 519 | 
            -
                    /* get slides from parent container */
         | 
| 520 | 
            -
                    for(var i = 0, n = 0, l = childs.length; i < l; i++){
         | 
| 521 | 
            -
                        if(childs[i].nodeType === 1){ 
         | 
| 522 | 
            -
                            slides+= '<div id="'+ slideshow.id + '-s' + n + '">' + childs[i].outerHTML + '</div>\n';
         | 
| 523 | 
            -
                            dots+='<li class="dot" id="' + navId + n + '"></li>\n';
         | 
| 524 | 
            -
                            n++;
         | 
| 525 | 
            -
                        }    
         | 
| 526 | 
            -
                    }
         | 
| 527 | 
            -
             | 
| 528 | 
            -
                    /* create dom structure from template */
         | 
| 529 | 
            -
                    var template = slideshow.template.replace(/{\w+}/mg,function(m){
         | 
| 530 | 
            -
                        switch(m){
         | 
| 531 | 
            -
                            case "{id}": return slideshow.id;
         | 
| 532 | 
            -
                            case "{slides}": return slides;
         | 
| 533 | 
            -
                            case "{next}": return slideshow.next;
         | 
| 534 | 
            -
                            case "{prev}": return slideshow.prev; 
         | 
| 535 | 
            -
                            case "{nav}": return dots;
         | 
| 536 | 
            -
                        }
         | 
| 537 | 
            -
                    });
         | 
| 544 | 
            +
            }
         | 
| 538 545 |  | 
| 539 | 
            -
                    /* apply slider template */
         | 
| 540 | 
            -
                    container.innerHTML = template;
         | 
| 541 | 
            -
                    /* add slideshow class to target container */
         | 
| 542 | 
            -
                    if(!container.className) container.className = 'slideshow';
         | 
| 543 | 
            -
                    else container.className+= ' slideshow';
         | 
| 544 546 |  | 
| 545 | 
            -
             | 
| 546 | 
            -
             | 
| 547 | 
            +
                var transitionProp = ['webkitTransition','mozTransition','msTransition','oTransition'],
         | 
| 548 | 
            +
                transitionEndEvents = ['transitionend', 'webkitTransitionEnd', 'otransitionend'],
         | 
| 549 | 
            +
                transformProp = ['webkitTransform','mozTransform','msTransform','oTransform'];
         | 
| 547 550 |  | 
| 548 | 
            -
                    attachHandlers();        
         | 
| 549 | 
            -
                }
         | 
| 550 551 |  | 
| 551 | 
            -
                function attachHandlers(){
         | 
| 552 | 
            -
                    var  | 
| 553 | 
            -
                         | 
| 554 | 
            -
                         | 
| 555 | 
            -
                         | 
| 552 | 
            +
                function attachHandlers(slideshow){
         | 
| 553 | 
            +
                    var id = slideshow.settings.id,
         | 
| 554 | 
            +
                        slides = document.getElementById(id+'-slides'),
         | 
| 555 | 
            +
                        nav = document.getElementById(id+'-nav'),
         | 
| 556 | 
            +
                        next = document.getElementById(id+'-next'),
         | 
| 557 | 
            +
                        prev = document.getElementById(id+'-prev');
         | 
| 556 558 |  | 
| 557 559 | 
             
                    /* add slidshow UI handlers */
         | 
| 558 | 
            -
                    addNavHandler(nav);
         | 
| 560 | 
            +
                    addNavHandler(nav,slideshow);
         | 
| 559 561 | 
             
                    addPauseHandler(slides);
         | 
| 560 | 
            -
                    addTransitionHandler(nav, slides);
         | 
| 561 | 
            -
             | 
| 562 | 
            -
                     | 
| 562 | 
            +
                    addTransitionHandler(nav, slides, slideshow);
         | 
| 563 | 
            +
             | 
| 564 | 
            +
                    addEvent(next,'click',function(event){
         | 
| 565 | 
            +
                        slideshow.next();
         | 
| 566 | 
            +
                        event.stopPropagation();
         | 
| 567 | 
            +
                    }); 
         | 
| 568 | 
            +
                    
         | 
| 569 | 
            +
                    addEvent(prev,'click',function(event){
         | 
| 570 | 
            +
                        slideshow.prev();
         | 
| 571 | 
            +
                        event.stopPropagation();
         | 
| 572 | 
            +
                    }); 
         | 
| 563 573 | 
             
                }
         | 
| 564 574 |  | 
| 565 575 | 
             
                function applyStyle(elem,prop,attr){
         | 
| @@ -592,15 +602,8 @@ Slideshow.prototype = (function(){ | |
| 592 602 | 
             
                    elem.style[prop] = style; 
         | 
| 593 603 | 
             
                }
         | 
| 594 604 |  | 
| 595 | 
            -
                function  | 
| 596 | 
            -
                     | 
| 597 | 
            -
                        carousel[button]();
         | 
| 598 | 
            -
                        event.stopPropagation();
         | 
| 599 | 
            -
                    });	
         | 
| 600 | 
            -
                }
         | 
| 601 | 
            -
             | 
| 602 | 
            -
                function addNavHandler(elem){
         | 
| 603 | 
            -
                    var nav = document.getElementById(slideshow.id+'-nav'),
         | 
| 605 | 
            +
                function addNavHandler(elem,slideshow){
         | 
| 606 | 
            +
                    var nav = document.getElementById(slideshow.settings.id+'-nav'),
         | 
| 604 607 | 
             
                        matchNav = new RegExp(elem.id + '(\\d+)');
         | 
| 605 608 |  | 
| 606 609 | 
             
                    addEvent(elem,'click', function(event){
         | 
| @@ -609,62 +612,67 @@ Slideshow.prototype = (function(){ | |
| 609 612 | 
             
                            ix = matchNav.exec(target.id);
         | 
| 610 613 |  | 
| 611 614 | 
             
                        if(ix) {
         | 
| 612 | 
            -
                             | 
| 615 | 
            +
                            slideshow.show(ix[1]);
         | 
| 613 616 | 
             
                            event.stopPropagation();
         | 
| 614 617 | 
             
                        }	
         | 
| 615 618 | 
             
                    });
         | 
| 616 619 | 
             
                }
         | 
| 617 620 |  | 
| 618 621 | 
             
                /* adds click handler on slide to toggle pause */
         | 
| 619 | 
            -
                function addPauseHandler(elem){
         | 
| 622 | 
            +
                function addPauseHandler(elem,slideshow){
         | 
| 620 623 | 
             
                    elem.addEventListener('click',function(event){
         | 
| 621 | 
            -
                        if( | 
| 622 | 
            -
                             | 
| 624 | 
            +
                        if(slideshow.paused) {
         | 
| 625 | 
            +
                            slideshow.resume();
         | 
| 623 626 | 
             
                        } else {
         | 
| 624 | 
            -
                             | 
| 627 | 
            +
                            slideshow.pause();
         | 
| 625 628 | 
             
                        }
         | 
| 626 629 | 
             
                    });
         | 
| 627 630 | 
             
                }
         | 
| 628 631 |  | 
| 629 | 
            -
                function addTransitionHandler(nav,slides){
         | 
| 630 | 
            -
                    var  | 
| 632 | 
            +
                function addTransitionHandler(nav,slides,slideshow){
         | 
| 633 | 
            +
                    var settings = slideshow.settings,
         | 
| 634 | 
            +
                        transition = settings.transition,
         | 
| 635 | 
            +
                        beforeTransit = settings.beforeTransit,
         | 
| 636 | 
            +
                        afterTransit = settings.afterTransit,
         | 
| 637 | 
            +
                        dots = nav.getElementsByTagName('li'), 
         | 
| 631 638 | 
             
                        ix, fx, lx = dots.length;
         | 
| 632 639 |  | 
| 633 | 
            -
                    carousel.onChange = function(index,from){
         | 
| 640 | 
            +
                    slideshow.carousel.onChange = function(index,from){
         | 
| 634 641 | 
             
                        ix = index % lx;
         | 
| 635 642 | 
             
                        fx = from % lx;
         | 
| 636 643 |  | 
| 637 | 
            -
                        if(typeof  | 
| 644 | 
            +
                        if(typeof beforeTransit === 'function') 
         | 
| 645 | 
            +
                            beforeTransit(ix, slideshow);
         | 
| 638 646 |  | 
| 639 647 | 
             
                        if(from !== undefined){
         | 
| 640 648 | 
             
                            dots[fx].className = "dot";
         | 
| 641 649 | 
             
                            /* apply transitions after first slide */
         | 
| 642 650 | 
             
                            /* to avoid animations on startup */
         | 
| 643 651 | 
             
                            if(!slideshow.hasTransitions){
         | 
| 644 | 
            -
                                for(var i = 0, l =  | 
| 645 | 
            -
                                    applyStyle( | 
| 652 | 
            +
                                for(var i = 0, l = slideshow.slides.length; i < l; i++)
         | 
| 653 | 
            +
                                    applyStyle(settings.id + '-s' + i,transitionProp,transition);
         | 
| 646 654 | 
             
                                slideshow.hasTransitions = true;
         | 
| 647 655 | 
             
                            }
         | 
| 648 656 | 
             
                        }
         | 
| 649 657 |  | 
| 650 658 | 
             
                        dots[ix].className = "active dot";
         | 
| 651 659 |  | 
| 652 | 
            -
                        carousel.transit(index,from);
         | 
| 660 | 
            +
                        slideshow.carousel.transit(index,from);
         | 
| 653 661 | 
             
                    }
         | 
| 654 662 |  | 
| 655 663 | 
             
                    addTransitionEndHandler(slides);
         | 
| 656 664 |  | 
| 657 665 | 
             
                    function addTransitionEndHandler(elem){
         | 
| 658 | 
            -
                        var te,  | 
| 666 | 
            +
                        var te, index = slideshow.carousel.index, x = index % lx;
         | 
| 659 667 |  | 
| 660 668 | 
             
                        if((te = hasTransitionEndEvent())){
         | 
| 661 669 | 
             
                            addEvent(elem,te,function(event){
         | 
| 662 670 | 
             
                                event = event ? event : window.event;
         | 
| 663 671 | 
             
                                var target = event.target || event.srcElement,
         | 
| 664 | 
            -
                                    target_id = slideshow.id + '-s' +  | 
| 672 | 
            +
                                    target_id = slideshow.id + '-s' + index;
         | 
| 665 673 | 
             
                                // fixme: fires twice
         | 
| 666 | 
            -
                                if(target.id === target_id && typeof  | 
| 667 | 
            -
                                     | 
| 674 | 
            +
                                if(target.id === target_id && typeof afterTransit ==='function'){ 
         | 
| 675 | 
            +
                                    afterTransit(x, slideshow);
         | 
| 668 676 | 
             
                                }   
         | 
| 669 677 | 
             
                            });
         | 
| 670 678 | 
             
                            slideshow.hasTransitionEndEvent = true;
         | 
| @@ -675,50 +683,47 @@ Slideshow.prototype = (function(){ | |
| 675 683 |  | 
| 676 684 | 
             
                }
         | 
| 677 685 |  | 
| 678 | 
            -
                 | 
| 679 | 
            -
             | 
| 680 | 
            -
             | 
| 681 | 
            -
            transitionProp = getStyleProperty(transitionProp);
         | 
| 682 | 
            -
            transformProp = getStyleProperty(transformProp);
         | 
| 686 | 
            +
                transitionProp = getStyleProperty(transitionProp);
         | 
| 687 | 
            +
                transformProp = getStyleProperty(transformProp);
         | 
| 683 688 |  | 
| 684 | 
            -
            function getStyleProperty(props){
         | 
| 685 | 
            -
             | 
| 686 | 
            -
             | 
| 689 | 
            +
                function getStyleProperty(props){
         | 
| 690 | 
            +
                    var root = document.documentElement, 
         | 
| 691 | 
            +
                        prop;
         | 
| 687 692 |  | 
| 688 | 
            -
             | 
| 689 | 
            -
             | 
| 690 | 
            -
             | 
| 693 | 
            +
                    prop = props.filter(function(p){
         | 
| 694 | 
            +
                        return p in root.style
         | 
| 695 | 
            +
                    });
         | 
| 691 696 |  | 
| 692 | 
            -
             | 
| 693 | 
            -
            }
         | 
| 697 | 
            +
                    return prop[0]
         | 
| 698 | 
            +
                }
         | 
| 694 699 |  | 
| 695 | 
            -
            function hasTransitionEndEvent(){
         | 
| 696 | 
            -
             | 
| 700 | 
            +
                function hasTransitionEndEvent(){
         | 
| 701 | 
            +
                    var hasTev;
         | 
| 697 702 |  | 
| 698 | 
            -
             | 
| 699 | 
            -
             | 
| 700 | 
            -
             | 
| 703 | 
            +
                    hasTev = transitionEndEvents.filter(function(m){
         | 
| 704 | 
            +
                        return ('on'+m.toLowerCase()) in window
         | 
| 705 | 
            +
                    });
         | 
| 701 706 |  | 
| 702 | 
            -
             | 
| 703 | 
            -
            }
         | 
| 707 | 
            +
                    return hasTev[0];
         | 
| 708 | 
            +
                }
         | 
| 704 709 |  | 
| 705 | 
            -
            function mergeOptions(target,source){
         | 
| 706 | 
            -
             | 
| 707 | 
            -
             | 
| 710 | 
            +
                function mergeOptions(target,source){
         | 
| 711 | 
            +
                    for(var key in source) {
         | 
| 712 | 
            +
                        target[key] = source[key];
         | 
| 713 | 
            +
                    }
         | 
| 714 | 
            +
                    
         | 
| 715 | 
            +
                    return target;
         | 
| 708 716 | 
             
                }
         | 
| 709 | 
            -
                
         | 
| 710 | 
            -
                return target;
         | 
| 711 | 
            -
            }
         | 
| 712 717 |  | 
| 713 | 
            -
            function addEvent(el,ev,fn,cap){
         | 
| 714 | 
            -
             | 
| 715 | 
            -
             | 
| 716 | 
            -
             | 
| 717 | 
            -
             | 
| 718 | 
            -
             | 
| 718 | 
            +
                function addEvent(el,ev,fn,cap){
         | 
| 719 | 
            +
                    if(el.addEventListener){
         | 
| 720 | 
            +
                        el.addEventListener(ev, fn, !!cap);
         | 
| 721 | 
            +
                    } else if (el.attachEvent){
         | 
| 722 | 
            +
                        el.attachEvent('on' + ev, fn);
         | 
| 723 | 
            +
                    }  else el['on' + ev] = fn;
         | 
| 719 724 |  | 
| 720 | 
            -
             | 
| 721 | 
            -
            }
         | 
| 725 | 
            +
                    return el;
         | 
| 726 | 
            +
                }
         | 
| 722 727 |  | 
| 723 728 |  | 
| 724 729 | 
             
            module.exports = Slideshow;
         |