var projectListTimeout = null var ProjectList = View.extend({ el: ".projectList", events: { "click .viewMore": 'viewMore', "mouseenter .room": 'enter', "mouseleave .room": 'leave', }, initialize: function(){ this.$viewMore = this.$(".viewMore") this.$(".images").each(function(){ $divs = $(this).children("div") $divs.hide() $divs.first().show() $(this).data("index", 0) }) }, timeout: null, enter: function(e){ clearTimeout(projectListTimeout) this.advance(e.currentTarget) }, leave: function(e){ clearTimeout(projectListTimeout) var $divs = $(e.currentTarget).find(".images div") $divs.hide() $divs.eq(0).show() }, advance: function(el){ projectListTimeout = setTimeout(function(){ this.advance(el) }.bind(this), 500) var $images = $(el).find(".images") var $divs = $images.children("div") var index = $images.data("index") var nextIndex = (index + 1) % $divs.length $divs.eq(index).hide() $divs.eq(nextIndex).show() $images.data("index", nextIndex) }, viewMore: function(e){ e.preventDefault() var criteria = {} criteria.offset = this.$(".projectItem").length if (window.location.pathname == "/" || window.location.pathname.match("/home")) { criteria.home = 1 } else { criteria.user_id = this.$(".projectItem").first().data("userid") } $.get("/api/project/paginate", criteria, function(data){ var offset = this.$viewMore.offset() var $data = $(data) var $els = $data.find(".projectItem") $els.insertBefore( this.$viewMore ) if (! $data.find(".viewMore").length) { this.$viewMore.hide() } $("body,html").animate({ scrollTop: offset.top - 80 }, 300) }.bind(this)) }, /* spinOn: function(e){ var iframe = $(e.currentTarget).find("iframe").get('0') if (! iframe) return iframe.contentWindow.postMessage("spin-on", window.location.origin) }, spinOff: function(e){ var iframe = $(e.currentTarget).find("iframe").get('0') if (! iframe) return iframe.contentWindow.postMessage("spin-off", window.location.origin) } */ })