Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/delibero.git

Using asynchronous get and callbacks to dynamically load custom JavaScript for integration with WYSIWYG editor.

AuthorDave Jarvis <email>
Date2014-12-05 23:03:15 GMT-0800
Commit8356b90bc1ade9de30036070ae70695712808c69
Parentdff2314
xml/common.xsl
<html>
<head>
- <meta charset="utf-8"/>
+ <meta charset='utf-8'/>
<title>Liberum Consilium: moderated, transparent deliberation</title>
- <link rel="stylesheet" type="text/css" href="css/common.css"/>
- <link rel="stylesheet" type="text/css"
- href="//fonts.googleapis.com/css?family=Open+Sans"/>
- <link rel="stylesheet" type="text/css"
- href="//fonts.googleapis.com/css?family=Montserrat"/>
+ <link rel='stylesheet' type='text/css' href='css/common.css'/>
+ <link rel='stylesheet' type='text/css'
+ href='//fonts.googleapis.com/css?family=Open+Sans'/>
+ <link rel='stylesheet' type='text/css'
+ href='//fonts.googleapis.com/css?family=Montserrat'/>
- <script type="text/javascript">
-function include( file, type ) {
- var src = type + "/" + file.substr( 0, file.lastIndexOf( "." ) ) + "." + type;
- var doc = document.head;
- var element = document.createElement( "link" );
+ <script type='text/javascript'><![CDATA[
+var REQ_OBJECTS = [
+ function () {return new XMLHttpRequest()},
+ function () {return new ActiveXObject('Msxml2.XMLHTTP')},
+ function () {return new ActiveXObject('Msxml3.XMLHTTP')},
+ function () {return new ActiveXObject('Microsoft.XMLHTTP')}
+];
+
+function get_request_object() {
+ for( var i = 0; i < REQ_OBJECTS.length; i++ ) {
+ try {
+ return REQ_OBJECTS[ i ]();
+ }
+ catch( e ) { continue; }
+ }
+}
+
+function inject( path, parent, element, callback ) {
+ var req = get_request_object();
+
+ req.open( 'GET', path, true );
+
+ req.onreadystatechange = function() {
+ if( req.readyState == 4 && req.status == 200 ) {
+ element.appendChild( document.createTextNode( req.responseText ) );
+ parent.appendChild( element );
+
+ if( typeof( callback ) === typeof( Function ) ) {
+ callback();
+ }
+ }
+ }
+
+ req.send( null );
+}
+function include( file, type, callback ) {
+ var src = type + '/' + file.substr( 0, file.lastIndexOf( '.' ) ) + '.' + type;
+ var parent, element;
+
switch( type ) {
- case "css":
- element.href = src;
- element.type = "text/" + type;
- element.rel = "stylesheet";
- element.media = "all";
+ case 'css':
+ parent = document.head || document.getElementsByTagName('head')[0];
+ element = document.createElement( 'style' );
+ element.type = 'text/' + type;
+ element.media = 'all';
break;
- case "js":
- doc = document.body;
- element = document.createElement( "script" );
- element.src = src;
- element.type = "text/javascript";
+ case 'js':
+ parent = document.body || document.getElementsByTagName('body')[0];
+ element = document.createElement( 'script' );
+ element.type = 'text/javascript';
+ break;
}
- doc.appendChild( element );
+ inject( src, parent, element, callback );
}
-function insert( type ) {
- include( location.pathname.split( "/" ).pop(), type );
+function path() {
+ return location.pathname.split( '/' ).pop();
}
-insert( "css" );
- </script>
+include( path(), 'css' );
+ ]]></script>
</head>
<body>
<xsl:apply-templates/>
- <script type="text/javascript">
- insert( "js" );
- </script>
+ <script type='text/javascript'>include( path(), 'js' );</script>
</body>
</html>
xml/css/account.css
-@import url( "related.css" );
-@import url( "xref.css" );
+@import url( "css/related.css" );
+@import url( "css/xref.css" );
.account::before {
xml/css/common.css
-@import url(//reset5.googlecode.com/hg/reset.min.css);
+@import url( //reset5.googlecode.com/hg/reset.min.css );
body {
xml/css/discuss.css
-@import url( "related.css" );
-@import url( "xref.css" );
+@import url( "css/related.css" );
+@import url( "css/xref.css" );
.summary, .policy {
xml/css/hypothesis.css
-@import url( "edit-discuss-flag.css" );
-@import url( "xref.css" );
+@import url( "css/edit-discuss-flag.css" );
+@import url( "css/xref.css" );
.policy {
xml/css/legend.css
+/**
+ * Decorates the tabular data for the pie chart values.
+ */
+table.legend {
+ margin-left: 2em;
+
+ border: 1px solid #eee;
+}
+
+th, td {
+ padding: 4px;
+}
+
+th {
+ padding-bottom: 8px;
+}
+
+td.amount, td.percent {
+ text-align: right;
+}
+
+td.amount {
+ border-right: 1px solid #eee;
+}
+
+tr:nth-child(even) {
+ background-color: #eee;
+}
+
+table.legend > thead > tr > * {
+ color: white;
+ background-color: black;
+}
+
+table.legend > tfoot {
+ border-top: 3px double black;
+}
+
+table.legend > tfoot > tr > td.footer {
+ text-align: right;
+}
+
xml/css/proposal.css
-@import url( "edit-discuss-flag.css" );
-@import url( "xref.css" );
-@import url( "parts.css" );
+@import url( "css/edit-discuss-flag.css" );
+@import url( "css/xref.css" );
+@import url( "css/parts.css" );
.policy, .tags {
xml/css/resources.css
-@import url( "edit-discuss-flag.css" );
-@import url( "xref.css" );
-@import url( "parts.css" );
-@import url( "table.css" );
+@import url( "css/edit-discuss-flag.css" );
+@import url( "css/xref.css" );
+@import url( "css/parts.css" );
+@import url( "css/legend.css" );
.policy {
xml/css/summary.css
-@import url( "related.css" );
-@import url( "xref.css" );
-@import url( "votes.css" );
+@import url( "css/related.css" );
+@import url( "css/xref.css" );
+@import url( "css/votes.css" );
.summary, .paragraph {
xml/css/support.css
-@import url( "edit-discuss-flag.css" );
-@import url( "xref.css" );
-@import url( "votes.css" );
+@import url( "css/edit-discuss-flag.css" );
+@import url( "css/xref.css" );
+@import url( "css/votes.css" );
.policy {
xml/css/table.css
-/**
- * Decorates the tabular data for the pie chart values.
- */
-table.legend {
- margin-left: 2em;
-
- border: 1px solid #eee;
-}
-
-th, td {
- padding: 4px;
-}
-
-th {
- padding-bottom: 8px;
-}
-
-td.amount, td.percent {
- text-align: right;
-}
-
-td.amount {
- border-right: 1px solid #eee;
-}
-
-tr:nth-child(even) {
- background-color: #eee;
-}
-
-table.legend > thead > tr > * {
- color: white;
- background-color: black;
-}
-
-table.legend > tfoot {
- border-top: 3px double black;
-}
-
-table.legend > tfoot > tr > td.footer {
- text-align: right;
-}
-
xml/css/tags.css
-@import url( "support.css" );
-@import url( "xref.css" );
-@import url( "edit-discuss-flag.css" );
+@import url( "css/support.css" );
+@import url( "css/xref.css" );
+@import url( "css/edit-discuss-flag.css" );
/* ***********************************************************************
xml/js/support.js
+include( "editor.min.js", "js", function() {
+ aloha( document.querySelector('.support') );
+});
Delta129 lines added, 94 lines removed, 35-line increase