// // SiteStripSegment.js // Home2011 // // Created by Bret Victor on 3/25/11. // (c) 2011 Bret Victor. MIT open-source license. // Classes: // SiteStripSegment // SiteStripSegmentButtonSet // SiteStripSegmentButton (function(){ //==================================================================================== // // SiteStripSegment // var SiteStripSegment = this.SiteStripSegment = new Class({ Extends: BVLayer, initialize: function (superlayer, segmentElement) { this.parent(superlayer); this.strip = this.getAncestorWithClass(SiteStrip); this.section = this.getAncestorWithClass(SiteSection); this.site = this.getAncestorWithClass(Site); this.setHoverable(true); this.setTouchable(true); this.element.setStyle("cursor", "pointer"); this.properties = this.site.mergePropertiesFromElement(this.strip.properties, segmentElement); this.parseSegmentElement(segmentElement); var scale = this.strip.stripScale; var widthScale = this.properties.widthScale || 1; this.setSize(this.strip.segmentSize.width * widthScale, this.strip.segmentSize.height); var windowOffsetY = this.properties.filmEdges ? -29 : -14; var windowPosition = { x: Math.round(5 * scale), y:Math.round(windowOffsetY * scale) }; var windowSize = { width: Math.round((218 * widthScale - 10) * scale), height: Math.round(170 * scale) }; this.film = new BVLayer(this); var filmURL = "Images/FilmMiddle" + (this.properties.filmEdges ? "" : "Solid") + ".png"; this.film.setContentsURLAndSize(filmURL, this.getSize()); this.contentClip = new BVLayer(this); this.contentClip.setPosition(windowPosition); this.contentClip.setSize(windowSize.width, windowSize.height - 1); // this.contentClip.setMasksToBounds(true); // todo this.window = new BVLayer(this); this.window.setContentsURLAndSize("Images/Window.png", windowSize); this.window.setPosition(windowPosition); this.window.setHidden(false); this.windowOverlay = new BVLayer(this.window); this.windowOverlay.setSize(this.window.getSize()); this.windowOverlay.setHidden(true); this.addContent(); }, parseSegmentElement: function (segmentElement) { var linkElement = segmentElement.getElement("a"); this.name = linkElement.get("id"); this.url = ContentContainer.getBrowserSpecificURL(linkElement.get("href")); var displayLinkElement = segmentElement.getElement(".display") || linkElement; this.displayURL = ContentContainer.getBrowserSpecificURL(displayLinkElement.get("href")); var contentClickElement = segmentElement.getElement(".click"); if (contentClickElement) { this.contentClickURL = ContentContainer.getBrowserSpecificURL(contentClickElement.get("href")); } else { this.contentClickURL = (this.displayURL == this.url) ? null : this.url; } var previewLinkElement = segmentElement.getElement(".preview") || displayLinkElement; this.previewURL = ContentContainer.getPreviewURL(previewLinkElement.get("href")); var matches = this.url.match(/^\/(.+)/); this.localURL = (matches && matches[1]) ? matches[1] : this.url; this.localURL = this.localURL.replace(/\/$/, ""); this.urlIndex = (this.properties.urlIndex || 0) * 1; var titleElement = segmentElement.getElement(".title"); this.titleString = titleElement ? titleElement.get("html") : ""; var subtitleElement = segmentElement.getElement(".subtitle"); this.subtitleString = subtitleElement ? subtitleElement.get("html") : ""; var captionElement = segmentElement.getElement(".caption"); this.captionString = captionElement ? captionElement.get("html") : ""; }, addContent: function () { this.content = new BVLayer(this.contentClip); if (gSiteShowThumbnailImages) { this.content.setContentsURLAndSize("ThumbnailImages/" + this.name + ".jpg", this.contentClip.getSize()); } if (!this.properties.hideTitle) { this.title = new BVText(this.contentClip); this.title.setPosition(0, -this.contentClip.height); var styles = { position: "absolute", bottom: "0px", left: "0px", width: this.contentClip.width + "px", backgroundImage: "url(Images/WindowCaption.png)", backgroundRepeat: "repeat-x" }; this.title.setTextStyles(styles); var titleClass = this.properties.titleClass ? (" " + this.properties.titleClass) : ""; var titleHTML = this.properties.subtitleOnly ? ("