Skip to content

Commit

Permalink
Show and hide tags in a single pane.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrempel committed Mar 7, 2011
1 parent 50d32e5 commit 9edf3a4
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 13 deletions.
20 changes: 19 additions & 1 deletion app/views/documents/show.teisource.xslt
Expand Up @@ -8,7 +8,25 @@
version="1.0">

<xsl:output omit-xml-declaration="yes" method="html" encoding="UTF-8" version="1.0" indent="yes" />


<xsl:template match="tei:facsimile">
<div class="tagOpen">
<xsl:text disable-output-escaping="yes">&amp;lt;</xsl:text>
<xsl:value-of select="local-name(.)" />
<xsl:apply-templates select="@*" mode="source" />
<xsl:text disable-output-escaping="yes">&amp;gt;</xsl:text>
<xsl:text disable-output-escaping="yes">
&amp;lt;!-- Omitting the facsimile ... download the
TEI document to see it --&amp;gt;
</xsl:text>
</div>
<div class="tagClose">
<xsl:text disable-output-escaping="yes">&amp;lt;/</xsl:text>
<xsl:value-of select="local-name(.)" />
<xsl:text disable-output-escaping="yes">&amp;gt;</xsl:text>
</div>
</xsl:template>

<!-- By default, we just copy and descend -->
<xsl:template name="copy-and-descend" match="*">
<!-- Construct a div with a class of our tag name -->
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.haml
Expand Up @@ -16,7 +16,7 @@

= javascript_include_tag "/#{isomorphicDir}/skins/EnterpriseBlue/load_skin.js"

- %w{ seadragon-min RailsDataSource FileUploadForm SeaDragon application }.each do |js|
- %w{ seadragon-min CSSRules RailsDataSource FileUploadForm SeaDragon application }.each do |js|
= javascript_include_tag "/javascripts/#{js}"

= stylesheet_link_tag :all
Expand Down
54 changes: 54 additions & 0 deletions public/javascripts/CSSRules.js
@@ -0,0 +1,54 @@
isc.defineClass("CSSRules").addProperties({
legalStyles: ["color", "backgroundColor", "display"],

init : function() {
this.Super("init", arguments);

// cssRules is a cache of the actual rules in the actual stylesheet
this.cssRules = {};

var head = document.documentElement.firstChild;
var title = "Dynamic-Styles";
isc.Element.insertAdjacentHTML(head, "afterBegin", "<style type='text/css' title='" + title + "' />", true);

for (var i = 0; i < document.styleSheets.length; i++) {
if (document.styleSheets[i].title == title) {
this.stylesheet = document.styleSheets[i];
break;
}
}

return this;
},

setRule : function(selector, styles) {
var cssRule = this.cssRules[selector];

if (!cssRule) {
this.stylesheet.insertRule(selector + " {}", 0);
cssRule = this.cssRules[selector] = this.stylesheet.cssRules[0];
}

this.legalStyles.map(function(style) {
if (styles[style]) cssRule.style[style] = styles[style];
});

return selector;
},

getRule: function(selector) {
var result = {};
var rule = this.cssRules[selector];
if (rule) {
this.legalStyles.map(function(style) {
if (rule.style[style]) result[style] = rule.style[style];
});
}
return result;
},

clearRules: function() {

}
});

40 changes: 30 additions & 10 deletions public/javascripts/application.js
Expand Up @@ -108,14 +108,36 @@ isc.defineClass("DocumentContents", isc.VLayout).addProperties({

documentDownloadDefaults: {
_constructor: isc.HTMLPane,
width: "50%",
height: "100%",
autoParent: "lowerPane"
},

showTagsButtonDefaults: {
_constructor: isc.Button,
autoFit: true,
actionType: "checkbox",
title: "Show Tags",
autoParent: "lowerPane",
action : function () {
book5.showTags(this.isSelected());
this.setTitle(this.isSelected() ? "Hide Tags" : "Show Tags");
}
},

lowerPaneDefaults: {
_constructor: isc.HLayout,
width: "100%",
height: 20
},

initWidget : function () {
this.Super("initWidget");
this.addAutoChild("documentFlow");
this.addAutoChild("lowerPane");
this.addAutoChild("documentDownload");
this.addAutoChild("showTagsButton");
this.observe(this.showTagsButton, "action", "observer.markForRedraw()");
},

setDocument : function (doc) {
Expand Down Expand Up @@ -298,12 +320,6 @@ isc.defineClass("AppLayout", isc.HLayout).addProperties({
width: "100%"
},

styledTEIDefaults: {
_constructor: isc.DocumentStyled,
height: "100%",
width: "100%"
},

documentTabsDefaults: {
_constructor: isc.TabSet,
showResizeBar: true,
Expand All @@ -312,9 +328,6 @@ isc.defineClass("AppLayout", isc.HLayout).addProperties({
tabs: [{
title: "TEI",
pane: "autoChild:documentContents"
},{
title: "Text",
pane: "autoChild:styledTEI"
}]
},

Expand All @@ -329,11 +342,18 @@ isc.defineClass("AppLayout", isc.HLayout).addProperties({
this.addAutoChild("documentLayout");
this.addAutoChild("documentTabs");
this.addAutoChild("deepZoom");
this.cssRules = isc.CSSRules.create();
this.showTags(false);
},

showTags : function (show) {
this.cssRules.setRule("div.tagOpen, div.tagClose, div.tagOpenClose", {
display: show ? "inline" : "none"
});
},

setDocument : function (doc) {
this.documentContents.setDocument(doc);
this.styledTEI.setDocument(doc);
this.deepZoom.setDocument(doc);
}
});
Expand Down
2 changes: 1 addition & 1 deletion public/stylesheets/tei-html.css
@@ -1,7 +1,6 @@
/* Modified for HTML divs, with classes representing the TEI tags */

div.tagOpen, div.tagClose, div.tagOpenClose {
display: inline;
color: green;
font-size: 90%;
}
Expand Down Expand Up @@ -796,6 +795,7 @@ div.p {

div.pb {
display: block;
margin-top: 0.25em;
}

div.pb:after {
Expand Down

0 comments on commit 9edf3a4

Please sign in to comment.