<commit_before>/**
 * jq.web.carousel - a carousel library for html5 mobile apps
 * @copyright AppMobi 2011 - AppMobi
 * 
 */
(function($) {
    var cache = [];
	var objId=function(obj){
		if(!obj.jqmCarouselId) obj.jqmCarouselId=$.uuid();
		return obj.jqmCarouselId;
	}
    $.fn.carousel = function(opts) {
        var tmp, id;
        for (var i = 0; i < this.length; i++) {
			//cache system
			id = objId(this[i]);
			if(!cache[id]){
				tmp = new carousel(this[i], opts);
				cache[id] = tmp;
			} else {
				tmp = cache[id];
			}
        }
        return this.length == 1 ? tmp : this;
    };
    
    var carousel = (function() {
        if (!window.WebKitCSSMatrix) {
            return;
        }
        var translateOpen = 'm11' in new WebKitCSSMatrix() ? "3d(" : "(";
        var translateClose = 'm11' in new WebKitCSSMatrix() ? ",0)" : ")";
        
        var carousel = function(containerEl, opts) {
            if (typeof containerEl === "string" || containerEl instanceof String) {
                this.container = document.getElementById(containerEl);
            } else {
                this.container = containerEl;
            }
            if (!this.container) {
                alert("Error finding container for carousel " + containerEl);
                return;
            }
            if (this instanceof carousel) {
                for (var j in opts) {
                    if (opts.hasOwnProperty(j)) {
                        this[j] = opts[j];
                    }
                }
            } else {
                
                return new carousel(containerEl, opts);
            }
        
                 
                var that = this;
				jq(this.container).bind('destroy', function(){
					var id = that.container.jqmCarouselId;
					//window event need to be cleaned up manually, remaining binds are automatically killed in the dom cleanup process
	                window.removeEventListener("orientationchange", that.orientationHandler, false);
					if(cache[id]) delete cache[id];
				});
				
                this.pagingDiv = this.pagingDiv ? document.getElementById(this.pagingDiv) : null;


                // initial setup
                this.container.style.overflow = "hidden";
                this.container.style['-webkit-box-orient'] = "vertical";
                this.container.style['display'] = "-webkit-box";
                this.container.style['-webkit-box-orient'] = "vertical";
                if (this.vertical) {
                    this.horizontal = false;
                }
                
                var el = document.createElement("div");
                this.container.appendChild(el);
                var $el=$(el);
                var $container=$(this.container);
                var data = Array.prototype.slice.call(this.container.childNodes);
                while(data.length>0)
                {
                    var myEl=data.splice(0,1);
                    myEl=$container.find(myEl)
                    if(myEl.get()==el)
                       continue;
                    $el.append(myEl.get());
                }
                if (this.horizontal) {
                    el.style.display = "-webkit-box";
                    el.style['-webkit-box-flex'] = 1;
                } 
                else {
                    el.style.display = "block";
                }
                
                this.el = el;
                this.refreshItems();
               
                el.addEventListener('touchmove', function(e) {
                    that.touchMove(e);
                }, false);
                el.addEventListener('touchend', function(e) {
                    that.touchEnd(e);
                }, false);
                el.addEventListener('touchstart', function(e) {
                    that.touchStart(e);
                }, false);
                var that = this;
                window.addEventListener("orientationchange", function() {
                    that.onMoveIndex(that.carouselIndex,0);
                }, false);
           
        };
        
        carousel.prototype = {
            startX: 0,
            startY: 0,
            dx: 0,
            dy: 0,
            myDivWidth: 0,
            myDivHeight: 0,
            cssMoveStart: 0,
            childrenCount: 0,
            carouselIndex: 0,
            vertical: false,
            horizontal: true,
            el: null,
            movingElement: false,
            container: null,
            pagingDiv: null,
            pagingCssName: "carousel_paging",
            pagingCssNameSelected: "carousel_paging_selected",
            pagingFunction: null,
            lockMove:false,
            // handle the moving function
            touchStart: function(e) {
                this.myDivWidth = numOnly(this.container.clientWidth);
                this.myDivHeight = numOnly(this.container.clientHeight);
                this.lockMove=false;
                if (event.touches[0].target && event.touches[0].target.type !== undefined) {
                    var tagname = event.touches[0].target.tagName.toLowerCase();
                    if (tagname === "select" || tagname === "input" || tagname === "button")  // stuff we need to allow
                    {
                        return;
                    }
                }
                if (e.touches.length === 1) {
                    
                    this.movingElement = true;
                    this.startY = e.touches[0].pageY;
                    this.startX = e.touches[0].pageX;
                    if (this.vertical) {
                        try {
                            this.cssMoveStart = numOnly(new WebKitCSSMatrix(window.getComputedStyle(this.el, null).webkitTransform).f);
                        } catch (ex1) {
                            this.cssMoveStart = 0;
                        }
                    } else {
                        try {
                            this.cssMoveStart = numOnly(new WebKitCSSMatrix(window.getComputedStyle(this.el, null).webkitTransform).e);
                        } catch (ex1) {
                            this.cssMoveStart = 0;
                        }
                    }
                }
            },
            touchMove: function(e) {
                if(!this.movingElement)
                   return;
                if (e.touches.length > 1) {
                    return this.touchEnd(e);
                }
                
                var rawDelta = {
                    x: e.touches[0].pageX - this.startX,
                    y: e.touches[0].pageY - this.startY
                };
                
                if (this.vertical) {
                    var movePos = { x: 0, y: 0 };
                    this.dy = e.touches[0].pageY - this.startY;
                    this.dy += this.cssMoveStart;
                    movePos.y = this.dy;
                    e.preventDefault();
                    e.stopPropagation();
                } else {
                    if (!this.lockMove&&isHorizontalSwipe(rawDelta.x, rawDelta.y)) {
                         
                        var movePos = {x: 0,y: 0};
                        this.dx = e.touches[0].pageX - this.startX;
                        this.dx += this.cssMoveStart;
                        e.preventDefault();
                        e.stopPropagation();
                        movePos.x = this.dx;
                    }
                    else
                       return this.lockMove=true;
                }
                
                var totalMoved = this.vertical ? ((this.dy % this.myDivHeight) / this.myDivHeight * 100) * -1 : ((this.dx % this.myDivWidth) / this.myDivWidth * 100) * -1; // get a percentage of movement.
                if(movePos)
                    this.moveCSS3(this.el, movePos);
            },
            touchEnd: function(e) {
                if (!this.movingElement) {
                    return;
                }
                // e.preventDefault();
                // e.stopPropagation();
                var runFinal = false;
                try {
                    var endPos = this.vertical ? numOnly(new WebKitCSSMatrix(window.getComputedStyle(this.el, null).webkitTransform).f) : numOnly(new WebKitCSSMatrix(window.getComputedStyle(this.el, null).webkitTransform).e);
                    if (endPos > 0) {
                        this.moveCSS3(this.el, {
                            x: 0,
                            y: 0
                        }, "300");
                    } else {
                        var totalMoved = this.vertical ? ((this.dy % this.myDivHeight) / this.myDivHeight * 100) * -1 : ((this.dx % this.myDivWidth) / this.myDivWidth * 100) * -1; // get a percentage of movement.
                        // Only need
                        // to drag 3% to trigger an event
                        var currInd = this.carouselIndex;
                        if (endPos < this.cssMoveStart && totalMoved > 3) {
                            currInd++; // move right/down
                        } else if ((endPos > this.cssMoveStart && totalMoved < 97)) {
                            currInd--; // move left/up
                        }
                        if (currInd > (this.childrenCount - 1)) {
                            currInd = this.childrenCount - 1;
                        }
                        if (currInd < 0) {
                            currInd = 0;
                        }
                        var movePos = {
                            x: 0,
                            y: 0
                        };
                        if (this.vertical) {
                            movePos.y = (currInd * this.myDivHeight * -1);
                        } 
                        else {
                            movePos.x = (currInd * this.myDivWidth * -1);
                        }
                        
                        this.moveCSS3(this.el, movePos, "150");
                        
                        if (this.pagingDiv && this.carouselIndex !== currInd) {
                            document.getElementById(this.container.id + "_" + this.carouselIndex).className = this.pagingCssName;
                            document.getElementById(this.container.id + "_" + currInd).className = this.pagingCssNameSelected;
                        }
                        if (this.carouselIndex != currInd)
                            runFinal = true;
                        this.carouselIndex = currInd;
                    }
                } catch (e) {
                    console.log(e);
                }
                this.dx = 0;
                this.movingElement = false;
                this.startX = 0;
                this.dy = 0;
                this.startY = 0;
                if (runFinal && this.pagingFunction && typeof this.pagingFunction == "function")
                    this.pagingFunction(this.carouselIndex);
            },
            onMoveIndex: function(newInd,transitionTime) {
                
                this.myDivWidth = numOnly(this.container.clientWidth);
                this.myDivHeight = numOnly(this.container.clientHeight);
                var runFinal = false;
  
                    if(document.getElementById(this.container.id + "_" + this.carouselIndex))
                        document.getElementById(this.container.id + "_" + this.carouselIndex).className = this.pagingCssName;
                    var newTime = Math.abs(newInd - this.carouselIndex);
                    
                    var ind = newInd;
                    if (ind < 0)
                        ind = 0;
                    if (ind > this.childrenCount - 1) {<commit_msg>changed carousel listeners to $().bind() to avoid memory leaks<commit_after>/**
 * jq.web.carousel - a carousel library for html5 mobile apps
 * @copyright AppMobi 2011 - AppMobi
 * 
 */
(function($) {
    var cache = [];
	var objId=function(obj){
		if(!obj.jqmCarouselId) obj.jqmCarouselId=$.uuid();
		return obj.jqmCarouselId;
	}
    $.fn.carousel = function(opts) {
        var tmp, id;
        for (var i = 0; i < this.length; i++) {
			//cache system
			id = objId(this[i]);
			if(!cache[id]){
				tmp = new carousel(this[i], opts);
				cache[id] = tmp;
			} else {
				tmp = cache[id];
			}
        }
        return this.length == 1 ? tmp : this;
    };
    
    var carousel = (function() {
        if (!window.WebKitCSSMatrix) {
            return;
        }
        var translateOpen = 'm11' in new WebKitCSSMatrix() ? "3d(" : "(";
        var translateClose = 'm11' in new WebKitCSSMatrix() ? ",0)" : ")";
        
        var carousel = function(containerEl, opts) {
            if (typeof containerEl === "string" || containerEl instanceof String) {
                this.container = document.getElementById(containerEl);
            } else {
                this.container = containerEl;
            }
            if (!this.container) {
                alert("Error finding container for carousel " + containerEl);
                return;
            }
            if (this instanceof carousel) {
                for (var j in opts) {
                    if (opts.hasOwnProperty(j)) {
                        this[j] = opts[j];
                    }
                }
            } else {
                
                return new carousel(containerEl, opts);
            }
        
                 
                var that = this;
				jq(this.container).bind('destroy', function(){
					var id = that.container.jqmCarouselId;
					//window event need to be cleaned up manually, remaining binds are automatically killed in the dom cleanup process
	                window.removeEventListener("orientationchange", that.orientationHandler, false);
					if(cache[id]) delete cache[id];
				});
				
                this.pagingDiv = this.pagingDiv ? document.getElementById(this.pagingDiv) : null;


                // initial setup
                this.container.style.overflow = "hidden";
                this.container.style['-webkit-box-orient'] = "vertical";
                this.container.style['display'] = "-webkit-box";
                this.container.style['-webkit-box-orient'] = "vertical";
                if (this.vertical) {
                    this.horizontal = false;
                }
                
                var el = document.createElement("div");
                this.container.appendChild(el);
                var $el=$(el);
                var $container=$(this.container);
                var data = Array.prototype.slice.call(this.container.childNodes);
                while(data.length>0)
                {
                    var myEl=data.splice(0,1);
                    myEl=$container.find(myEl)
                    if(myEl.get()==el)
                       continue;
                    $el.append(myEl.get());
                }
                if (this.horizontal) {
                    el.style.display = "-webkit-box";
                    el.style['-webkit-box-flex'] = 1;
                } 
                else {
                    el.style.display = "block";
                }
                
                this.el = el;
                this.refreshItems();
                var jqEl = jq(el);
                jqEl.bind('touchmove', function(e) {that.touchMove(e);});
                jqEl.bind('touchend', function(e) {that.touchEnd(e);});
                jqEl.bind('touchstart', function(e) {that.touchStart(e);});
				this.orientationHandler = function() {that.onMoveIndex(that.carouselIndex,0);};
                window.addEventListener("orientationchange", this.orientationHandler, false);
           
        };
        
        carousel.prototype = {
            startX: 0,
            startY: 0,
            dx: 0,
            dy: 0,
            myDivWidth: 0,
            myDivHeight: 0,
            cssMoveStart: 0,
            childrenCount: 0,
            carouselIndex: 0,
            vertical: false,
            horizontal: true,
            el: null,
            movingElement: false,
            container: null,
            pagingDiv: null,
            pagingCssName: "carousel_paging",
            pagingCssNameSelected: "carousel_paging_selected",
            pagingFunction: null,
            lockMove:false,
            // handle the moving function
            touchStart: function(e) {
                this.myDivWidth = numOnly(this.container.clientWidth);
                this.myDivHeight = numOnly(this.container.clientHeight);
                this.lockMove=false;
                if (event.touches[0].target && event.touches[0].target.type !== undefined) {
                    var tagname = event.touches[0].target.tagName.toLowerCase();
                    if (tagname === "select" || tagname === "input" || tagname === "button")  // stuff we need to allow
                    {
                        return;
                    }
                }
                if (e.touches.length === 1) {
                    
                    this.movingElement = true;
                    this.startY = e.touches[0].pageY;
                    this.startX = e.touches[0].pageX;
                    if (this.vertical) {
                        try {
                            this.cssMoveStart = numOnly(new WebKitCSSMatrix(window.getComputedStyle(this.el, null).webkitTransform).f);
                        } catch (ex1) {
                            this.cssMoveStart = 0;
                        }
                    } else {
                        try {
                            this.cssMoveStart = numOnly(new WebKitCSSMatrix(window.getComputedStyle(this.el, null).webkitTransform).e);
                        } catch (ex1) {
                            this.cssMoveStart = 0;
                        }
                    }
                }
            },
            touchMove: function(e) {
                if(!this.movingElement)
                   return;
                if (e.touches.length > 1) {
                    return this.touchEnd(e);
                }
                
                var rawDelta = {
                    x: e.touches[0].pageX - this.startX,
                    y: e.touches[0].pageY - this.startY
                };
                
                if (this.vertical) {
                    var movePos = { x: 0, y: 0 };
                    this.dy = e.touches[0].pageY - this.startY;
                    this.dy += this.cssMoveStart;
                    movePos.y = this.dy;
                    e.preventDefault();
                    e.stopPropagation();
                } else {
                    if (!this.lockMove&&isHorizontalSwipe(rawDelta.x, rawDelta.y)) {
                         
                        var movePos = {x: 0,y: 0};
                        this.dx = e.touches[0].pageX - this.startX;
                        this.dx += this.cssMoveStart;
                        e.preventDefault();
                        e.stopPropagation();
                        movePos.x = this.dx;
                    }
                    else
                       return this.lockMove=true;
                }
                
                var totalMoved = this.vertical ? ((this.dy % this.myDivHeight) / this.myDivHeight * 100) * -1 : ((this.dx % this.myDivWidth) / this.myDivWidth * 100) * -1; // get a percentage of movement.
                if(movePos)
                    this.moveCSS3(this.el, movePos);
            },
            touchEnd: function(e) {
                if (!this.movingElement) {
                    return;
                }
                // e.preventDefault();
                // e.stopPropagation();
                var runFinal = false;
                try {
                    var endPos = this.vertical ? numOnly(new WebKitCSSMatrix(window.getComputedStyle(this.el, null).webkitTransform).f) : numOnly(new WebKitCSSMatrix(window.getComputedStyle(this.el, null).webkitTransform).e);
                    if (endPos > 0) {
                        this.moveCSS3(this.el, {
                            x: 0,
                            y: 0
                        }, "300");
                    } else {
                        var totalMoved = this.vertical ? ((this.dy % this.myDivHeight) / this.myDivHeight * 100) * -1 : ((this.dx % this.myDivWidth) / this.myDivWidth * 100) * -1; // get a percentage of movement.
                        // Only need
                        // to drag 3% to trigger an event
                        var currInd = this.carouselIndex;
                        if (endPos < this.cssMoveStart && totalMoved > 3) {
                            currInd++; // move right/down
                        } else if ((endPos > this.cssMoveStart && totalMoved < 97)) {
                            currInd--; // move left/up
                        }
                        if (currInd > (this.childrenCount - 1)) {
                            currInd = this.childrenCount - 1;
                        }
                        if (currInd < 0) {
                            currInd = 0;
                        }
                        var movePos = {
                            x: 0,
                            y: 0
                        };
                        if (this.vertical) {
                            movePos.y = (currInd * this.myDivHeight * -1);
                        } 
                        else {
                            movePos.x = (currInd * this.myDivWidth * -1);
                        }
                        
                        this.moveCSS3(this.el, movePos, "150");
                        
                        if (this.pagingDiv && this.carouselIndex !== currInd) {
                            document.getElementById(this.container.id + "_" + this.carouselIndex).className = this.pagingCssName;
                            document.getElementById(this.container.id + "_" + currInd).className = this.pagingCssNameSelected;
                        }
                        if (this.carouselIndex != currInd)
                            runFinal = true;
                        this.carouselIndex = currInd;
                    }
                } catch (e) {
                    console.log(e);
                }
                this.dx = 0;
                this.movingElement = false;
                this.startX = 0;
                this.dy = 0;
                this.startY = 0;
                if (runFinal && this.pagingFunction && typeof this.pagingFunction == "function")
                    this.pagingFunction(this.carouselIndex);
            },
            onMoveIndex: function(newInd,transitionTime) {
                
                this.myDivWidth = numOnly(this.container.clientWidth);
                this.myDivHeight = numOnly(this.container.clientHeight);
                var runFinal = false;

                    if(document.getElementById(this.container.id + "_" + this.carouselIndex))
                        document.getElementById(this.container.id + "_" + this.carouselIndex).className = this.pagingCssName;

                    var newTime = Math.abs(newInd - this.carouselIndex);
                    
                    var ind = newInd;
                    if (ind < 0)
                        ind = 0;
                    if (ind > this.childrenCount - 1) {
{'fraction_non_alphanumeric': 0.10549516391337842, 'fraction_numerical': 0.007960284173585552, 'mean_word_length': 1.061127282349828, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7354238', 'n_tokens_mistral': 6309, 'n_tokens_neox': 5730, 'n_words': 1139}