// vim: et:ts=4:sw=4:sts=4:ft=js /*@ Ox.IconItem IconItem Object () -> IconItem Object (options) -> IconItem Object (options, self) -> IconItem Object options Options object borderRadius border radius for icon images iconHeight icon height iconWidth icon width imageHeight icon image height imageWidth icon image width id element id info icon info size icon size title title url icon url self shared private variable @*/ Ox.IconItem = function(options, self) { //Ox.print('IconItem', options, self) self = self || {}; var that = Ox.Element({}, self) .defaults({ borderRadius: 0, iconHeight: 128, iconWidth: 128, imageHeight: 128, imageWidth: 128, itemHeight: 192, itemWidth: 128, id: '', info: '', title: '', url: '' }) .options(options || {}); Ox.extend(self, { fontSize: self.options.itemWidth == 64 ? 6 : 9, lineLength: self.options.itemWidth == 64 ? 15 : 23, lines: self.options.itemWidth == 64 ? 4 : 5, url: Ox.UI.PATH + 'png/transparent.png', }); self.title = formatText(self.options.title, self.lines - 1, self.lineLength); self.info = formatText(self.options.info, 5 - self.title.split('
').length, self.lineLength); that.css({ width: self.options.itemWidth + 'px', height: self.options.itemHeight + 'px' }); that.$icon = $('
') .addClass('OxIcon') .css({ top: self.options.iconWidth == 64 ? -64 : -124, width: (self.options.iconWidth + 4) + 'px', height: (self.options.iconHeight + 4) + 'px' }); that.$iconImage = $('') .addClass('OxLoading OxTarget') .attr({ src: self.url }) .css({ width: self.options.imageWidth + 'px', height: self.options.imageHeight + 'px', borderRadius: self.options.borderRadius + 4 + 'px' }) .mousedown(mousedown) .mouseenter(mouseenter) .mouseleave(mouseleave); self.options.url && that.$iconImage.one('load', load); that.$textBox = $('
') .addClass('OxText') .css({ top: self.options.iconHeight - self.options.itemWidth / 2 + 'px', width: self.options.itemWidth + 4 + 'px', height: (self.options.itemWidth == 64 ? 30 : 58) + 'px' }); that.$text = $('
') .addClass('OxTarget') .css({ fontSize: self.fontSize + 'px' }) .html( self.title + '
' + self.info + '' ) .mouseenter(mouseenter) .mouseleave(mouseleave); that.$reflection = $('
') .addClass('OxReflection') .css({ top: self.options.iconHeight + 'px', width: self.options.itemWidth + 4 + 'px', height: self.options.itemHeight - self.options.iconHeight + 'px' }); that.$reflectionImage = $('') .addClass('OxLoading') .attr({ src: self.url }) .css({ width: self.options.imageWidth + 'px', height: self.options.imageHeight + 'px', // firefox is 1px off when centering images with odd width and scaleY(-1) paddingLeft: ($.browser.mozilla && self.options.imageWidth % 2 ? 1 : 0) + 'px', borderRadius: self.options.borderRadius + 'px' }); that.$gradient = $('
') .css({ //top: (-self.options.size / 2) + 'px', width: self.options.itemWidth + 'px', height: self.options.itemWidth / 2 + 'px' }); that.append( that.$reflection.append( that.$reflectionImage ).append( that.$gradient ) ).append( that.$textBox.append( that.$text ) ).append( that.$icon.append( that.$iconImage ) ); function formatText(text, maxLines, maxLength) { var lines = Ox.wordwrap(text, maxLength, '
', true, false).split('
'); return lines.map(function(line, i) { if (i < maxLines - 1) { return line; } else if (i == maxLines - 1) { return lines.length == maxLines ? line : Ox.truncate(lines.map(function(line, i) { return i < maxLines - 1 ? null : line; }).join(' '), maxLength, '...', 'center'); } else { return null; } }).join('
'); } function load() { that.$iconImage.attr({ src: self.options.url }) .one('load', function() { that.$iconImage.removeClass('OxLoading'); that.$reflectionImage .attr({ src: self.options.url }) .removeClass('OxLoading'); }); } function mousedown(e) { // fixme: preventDefault keeps image from being draggable in safari - but also keeps the list from getting focus // e.preventDefault(); } function mouseenter() { that.addClass('OxHover'); } function mouseleave() { that.removeClass('OxHover'); } return that; };