if (!LF.TilePanel) { /* var tile = new LF.TilePanel({ Selector: ".TileList .Tile" }); LF.Delegate.Add(tile.OnMovedTileEvent, tileMoved); LF.Delegate.Add(tile.OnRequiredTileEvent, showEverything); //fix footer function tileMoved(params) { $("#footer").css("margin-top", params.Height + 10); } function showEverything() { if (pageIndex > $($(".TileList .Tile")[1]).attr("pageCount")) { tile.Stop(); return; } if (pageUrlFormat) { if ($CL.Portal.Config.IsLogin) { var url = pageUrlFormat.replace("{PageIndex}", pageIndex).replace("{CustomerID}", $CL.SiteLogin.UserInfo().UserID); } else { var url = pageUrlFormat.replace("{PageIndex}", pageIndex).replace("{CustomerID}", 0); } $.ajax( { type: "GET", url: url, dataType: "text", success: function (data) { pageIndex++; if (!data.IsEmpty()) { $(".TileList").append(data); tile.MoveTile(); bindTileMouseOverEvent(); bindAddCommentsEvent(); } }, error: $CL.Config.CommonErrorMessage }); } } */ LF.TilePanel = function (options) { ///a object of tile, must JqueryObject, i.e ".TileList .Tile" ///default is 230 ///default is 10 ///default is 15 ///default is 980 if (options.Selector == null) { throw new Error("must provide tile list"); } if (options.TileWidth == null) { options.TileWidth = 230; } if (options.TileWidthGap == null) { options.TileWidthGap = 10; } if (options.TileHeightGap == null) { options.TileHeightGap = 15; } if (options.MinWidth == null) { options.MinWidth = 980; } var onMovedTileEvent = "onMovedTileEvent_" + window.Uuid(); var onRequiredTileEvent = "onRequiredTileEvent_" + window.Uuid(); var moveTileQueue = 0; var prop = { Height: 0, Width: 0, HeightList: null }; var attachedScroll = false; var noMoreTile = false; function moveTile() { if (moveTileQueue > 1) { return; // only one moveTile in queue allowed } moveTileQueue++; start(); } function start() { var dWidth = Math.max($(window).width() - 10, options.MinWidth); var maxColumn = Math.floor((dWidth + options.TileWidthGap) / (options.TileWidth + options.TileWidthGap)); var tileList = $(options.Selector); maxColumn = Math.min(tileList.length, maxColumn); var startLeft = (dWidth - (maxColumn * options.TileWidth + (maxColumn - 1) * options.TileWidthGap)) / 2; var lowerHeight = new Array(); for (var i = 0; i < maxColumn; i++) { lowerHeight.push(0); } function findLowest(list) { if (!list) { return { Top: 0, Column: 0 }; } var lower = list[0]; var column = 0; for (var i = 0; i < list.length; i++) { if (lower > list[i]) { column = i; lower = list[i]; } } return { Top: lower, Column: column }; } function findHighest() { var lower = lowerHeight[0]; var column = 0; for (var i = 0; i < lowerHeight.length; i++) { if (lower < lowerHeight[i]) { column = i; lower = lowerHeight[i]; } } return { Top: lower, Column: column }; } //first move, need set default position var startPosition = findLowest(prop.HeightList); tileList.each( function () { var item = $(this); if (!item.attr("moved")) { item.attr("moved", 1); //item.hide(); item.css("left", startLeft + startPosition.Column * options.TileWidth + startPosition.Column * options.TileWidthGap); item.css("top", startPosition.Top); } }); var animateComplete = 0; tileList.each( function () { var item = $(this); var lowest = findLowest(lowerHeight); var newTop = lowest.Top + options.TileHeightGap; var newLeft = startLeft + lowest.Column * options.TileWidth + lowest.Column * options.TileWidthGap; lowerHeight[lowest.Column] = newTop + item.height(); item.css("left", newLeft); item.css("top", newTop); item.css("visibility", "visible"); item.animate({ top: newTop, left: newLeft }, 1000, function () { item.show("slow"); animateComplete++; if (animateComplete == tileList.length) { if (moveTileQueue > 0) { moveTileQueue--; } if (moveTileQueue == 0) { var columns = totalColumn(); prop = { Height: findHighest().Top, Width: columns * options.TileWidth + (columns - 1) * options.TileWidthGap, HeightList: lowerHeight }; Web.Debug.Log("TilePanel:onMovedTileEvent - Height:" + prop.Height + " Width:" + prop.Width); LF.Delegate.Call(onMovedTileEvent, prop); if (!attachedScroll && !noMoreTile) { $(window).scroll(scrollEvent); attachedScroll = true; } scrollEvent(); } else { //still have one tile in queue, move it again before call onMovedTileEvent; start(); } } }); } ); function totalColumn() { // get total totalColumn; var total = 0; for (var i = 0; i < lowerHeight.length; i++) { if (lowerHeight[i] != 0) { total++; } } return total; } } function isFull(heightList) { if (heightList) { for (var i = 0; i < heightList.length; i++) { var lowerHeight = heightList[i]; if ((($(window).height() + $(window).scrollTop()) - lowerHeight) > 100) { return false; } } } return true; } var timeOutInt; function adjustTile() { clearTimeout(timeOutInt); setTimeout(moveTile, 100); } function init() { $(window).resize(adjustTile); moveTile(); } function scrollEvent() { //var reachBottom = ($(document).height() - ($(window).height() + $(window).scrollTop())) < 100; var full = isFull(prop.HeightList); if (!full) { Web.Debug.Log("TilePanel:I am reach bottom"); $(window).unbind("scroll", scrollEvent); attachedScroll = false; LF.Delegate.Call(onRequiredTileEvent, prop); } } function stop() { Web.Debug.Log("Stop scroll event,since no more tile coming"); $(window).unbind("scroll", scrollEvent); noMoreTile = true; } init(); return { OnMovedTileEvent: onMovedTileEvent, OnRequiredTileEvent: onRequiredTileEvent, MoveTile: moveTile, Stop: stop }; } }