(function($){ $.fn.uiImageSelector = function(Current,List) { return this.each(function() { // Initial HTML $(this).append('
'); $(this).find('a[href=""]').click(function(event){ event.preventDefault(); }); var uiImageSelector = $(this); // Current Image var ImageCurrent = new Image(); ImageCurrent.onload = function(){ $(uiImageSelector).find('.current').html(''); } ImageCurrent.onerror = function(){ $(uiImageSelector).find('.current').html(''); } ImageCurrent.src = Current.Source; // Column and Row Settings Column = new Object(); Row = new Object({ Top : { Index : Array(), Source : Array(), Name : Array() }, Bottom : { Index : Array(), Source : Array(), Name : Array() } }); Column.Total = Math.ceil((List.Index.length - 8) / 2); if(Column.Total < 0) { Column.Total = 0; } Column.Current = 0; for(i in List.Index) { if(List.Index[i] == Current.Index) { Column.Current = Math.ceil(i / 2) - 1; if(Column.Current > Column.Total) { Column.Current = Column.Total; } } if(i % 2 == 0) { Row.Top.Index.push(List.Index[i]); Row.Top.Source.push(List.Source[i]); Row.Top.Name.push(List.Name[i]); } else { Row.Bottom.Index.push(List.Index[i]); Row.Bottom.Source.push(List.Source[i]); Row.Bottom.Name.push(List.Name[i]); } } $('.uiImageSelector input').data({ Column : Column, Row : Row }); // Browser Images for(i=Column.Current;i<=Column.Current+3;i++) { if(Row.Top.Index[i] != '') { $('
') .data({ Index : Row.Top.Index[i], Source : Row.Top.Source[i], Name : Row.Top.Name[i] }) .appendTo($(uiImageSelector).find('.browser.toprow')) .click(BrowserImage); if(Row.Top.Index[i] == Current.Index) { $(uiImageSelector).find('.browser.toprow div:last').addClass('selected'); } } if(Row.Bottom.Index[i] != '') { $('
') .data({ Index : Row.Bottom.Index[i], Source : Row.Bottom.Source[i], Name : Row.Bottom.Name[i] }) .appendTo($(uiImageSelector).find('.browser.bottomrow')) .click(BrowserImage); if(Row.Bottom.Index[i] == Current.Index) { $(uiImageSelector).find('.browser.bottomrow div:last').addClass('selected'); } } } // Events $(document).click(function(){ $(uiImageSelector).find('.browser.padding').addClass('hide'); }); $(uiImageSelector).find('.browser.padding').click(function(event){ event.stopPropagation(); }); $(uiImageSelector).find('.icon').click(function(event){ event.stopPropagation(); $(uiImageSelector).find('.browser.padding').removeClass('hide'); }); if(Column.Current == 0) { $(uiImageSelector).find('.page.first,.page.previous').addClass('disabled'); } if(Column.Current == Column.Total) { $(uiImageSelector).find('.page.last,.page.next').addClass('disabled'); } }); function BrowserImage(){ var uiImageSelector = $(this).parents('.uiImageSelector'); $(uiImageSelector).find('.image').removeClass('selected'); $(this).addClass('selected'); $(uiImageSelector).find('input').val($(this).data().Index); $(uiImageSelector).find('.current').html(''); $(uiImageSelector).find('.browser.padding').addClass('hide'); } } })(jQuery);