Skip to content

Commit

Permalink
[POLISH] Added example spans on featuretypes demo page and codemirror…
Browse files Browse the repository at this point in the history
….js for beautification.
  • Loading branch information
Ralf Dauenhauer committed Dec 10, 2013
1 parent 7188821 commit f52b989
Show file tree
Hide file tree
Showing 9 changed files with 893 additions and 6 deletions.
22 changes: 16 additions & 6 deletions www/assessment/questions/featuretypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<h4>Example</h4>
<span class="learnosity-feature" data-type="audioplayer" data-src="http://assets.learnosity.com/demos/docs/audiofeaturedemo.mp3" data-waveform="http://assets.learnosity.com/demos/docs/waveform.png"></span>
<br />
<pre class="feature htmlexample">&lt;span class="learnosity-feature" data-type="audioplayer" data-src="audio-source.mp3" data-waveform="http://assets.learnosity.com/demos/docs/waveform.png"&gt;&lt;/span&gt;</pre>
<hr />
</section>

Expand All @@ -40,27 +41,36 @@
<h4>Example (with embedded youtube video)</h4>
<span class="learnosity-feature" data-type="videoplayer" data-src="http://www.youtube.com/watch?feature=player_detailpage&v=flL7M36QszA"></span>
<br />
<pre class="feature htmlexample">&lt;span class="learnosity-feature" data-type="videoplayer" data-src="http://www.youtube.com/watch?feature=player_detailpage&v=flL7M36QszA"&gt;&lt;/span&gt;</pre>
<hr />
</section>

<section>
<h3 id="calculator">Calculator</h3>
<h4>Example (Basic)</h4>
<span class="learnosity-feature" data-type="calculator"></span></br></br>
<span class="learnosity-feature" data-type="calculator"></span>
<br /><br />
<pre class="feature htmlexample">&lt;span class="learnosity-feature" data-type="calculator"&gt;&lt;/span&gt;</pre><br />
<h4>Example (Scientific)</h4>
<span class="learnosity-feature" data-type="calculator" data-mode="scientific"></span></br></br>
<span class="learnosity-feature" data-type="calculator" data-mode="scientific"></span>
<br /><br />
<pre class="feature htmlexample">&lt;span class="learnosity-feature" data-type="calculator" data-mode="scientific"&gt;&lt;/span&gt;</pre>
<hr />
</section>

<section>
<h3 id="imagetool">Image Tool</h3>
<h4 style="margin-bottom:35px">Example (Protractor)</h4>
<h4>Example (Protractor)</h4>
<span class="learnosity-feature" data-type="imagetool" data-image="protractor"></span>
</br>
<h4 style="margin-top: 200px">Example (Ruler 6 inches)</h4>
<pre style="margin-top:185px" class="feature htmlexample">&lt;span class="learnosity-feature" data-type="imagetool" data-image="protractor"&gt;&lt;/span&gt;</pre>
<br/><h4>Example (Ruler 6 inches)</h4>
<span class="learnosity-feature" data-type="imagetool" data-image="ruler-6-inches"></span>
<p style="margin-bottom:80px"></p>
<pre style="margin-top: 70px" class="feature htmlexample">&lt;span class="learnosity-feature" data-type="imagetool" data-image="ruler-6-inches"&gt;&lt;/span&gt;</pre>
</section>

<script src="/static/js/codemirror.min.js"></script>
<script src="/static/js/underscore.min.js"></script>
<script src="/static/js/initCodeMirror.js"></script>

<?php
include_once '../../../src/includes/footer.php';
26 changes: 26 additions & 0 deletions www/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,29 @@ td {
#securityForm pre {
word-wrap: break-word;
}

/********************************************************************
*
* Codemirror styles
*
********************************************************************/
.cm-s-default {border: 1px solid #CCC;}
.cm-s-default span.cm-keyword {color: #708;}
.cm-s-default span.cm-atom {color: #219;}
.cm-s-default span.cm-number {color: #164;}
.cm-s-default span.cm-def {color: #00f;}
.cm-s-default span.cm-variable {color: black;}
.cm-s-default span.cm-variable-2 {color: #05a;}
.cm-s-default span.cm-variable-3 {color: #0a5;}
.cm-s-default span.cm-property {color: black;}
.cm-s-default span.cm-operator {color: black;}
.cm-s-default span.cm-comment {color: #a50;}
.cm-s-default span.cm-string {color: #a11;}
.cm-s-default span.cm-string-2 {color: #f50;}
.cm-s-default span.cm-meta {color: #555;}
.cm-s-default span.cm-error {color: #f00;}
.cm-s-default span.cm-qualifier {color: #555;}
.cm-s-default span.cm-builtin {color: #30a;}
.cm-s-default span.cm-bracket {color: #cc7;}
.cm-s-default span.cm-tag {color: #170;}
.cm-s-default span.cm-attribute {color: #00c;}
1 change: 1 addition & 0 deletions www/static/js/codemirror.min.js

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions www/static/js/codemirror/mode/htmlembedded/htmlembedded.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {

//config settings
var scriptStartRegex = parserConfig.scriptStartRegex || /^<%/i,
scriptEndRegex = parserConfig.scriptEndRegex || /^%>/i;

//inner modes
var scriptingMode, htmlMixedMode;

//tokenizer when in html mode
function htmlDispatch(stream, state) {
if (stream.match(scriptStartRegex, false)) {
state.token=scriptingDispatch;
return scriptingMode.token(stream, state.scriptState);
}
else
return htmlMixedMode.token(stream, state.htmlState);
}

//tokenizer when in scripting mode
function scriptingDispatch(stream, state) {
if (stream.match(scriptEndRegex, false)) {
state.token=htmlDispatch;
return htmlMixedMode.token(stream, state.htmlState);
}
else
return scriptingMode.token(stream, state.scriptState);
}


return {
startState: function() {
scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.scriptingModeSpec);
htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed");
return {
token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch,
htmlState : CodeMirror.startState(htmlMixedMode),
scriptState : CodeMirror.startState(scriptingMode)
};
},

token: function(stream, state) {
return state.token(stream, state);
},

indent: function(state, textAfter) {
if (state.token == htmlDispatch)
return htmlMixedMode.indent(state.htmlState, textAfter);
else if (scriptingMode.indent)
return scriptingMode.indent(state.scriptState, textAfter);
},

copyState: function(state) {
return {
token : state.token,
htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState),
scriptState : CodeMirror.copyState(scriptingMode, state.scriptState)
};
},

electricChars: "/{}:",

innerMode: function(state) {
if (state.token == scriptingDispatch) return {state: state.scriptState, mode: scriptingMode};
else return {state: state.htmlState, mode: htmlMixedMode};
}
};
}, "htmlmixed");

CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"});
CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"});
CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingModeSpec:"text/x-java"});
CodeMirror.defineMIME("application/x-erb", { name: "htmlembedded", scriptingModeSpec:"ruby"});
104 changes: 104 additions & 0 deletions www/static/js/codemirror/mode/htmlmixed/htmlmixed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
var cssMode = CodeMirror.getMode(config, "css");

var scriptTypes = [], scriptTypesConf = parserConfig && parserConfig.scriptTypes;
scriptTypes.push({matches: /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^$/i,
mode: CodeMirror.getMode(config, "javascript")});
if (scriptTypesConf) for (var i = 0; i < scriptTypesConf.length; ++i) {
var conf = scriptTypesConf[i];
scriptTypes.push({matches: conf.matches, mode: conf.mode && CodeMirror.getMode(config, conf.mode)});
}
scriptTypes.push({matches: /./,
mode: CodeMirror.getMode(config, "text/plain")});

function html(stream, state) {
var tagName = state.htmlState.tagName;
var style = htmlMode.token(stream, state.htmlState);
if (tagName == "script" && /\btag\b/.test(style) && stream.current() == ">") {
// Script block: mode to change to depends on type attribute
var scriptType = stream.string.slice(Math.max(0, stream.pos - 100), stream.pos).match(/\btype\s*=\s*("[^"]+"|'[^']+'|\S+)[^<]*$/i);
scriptType = scriptType ? scriptType[1] : "";
if (scriptType && /[\"\']/.test(scriptType.charAt(0))) scriptType = scriptType.slice(1, scriptType.length - 1);
for (var i = 0; i < scriptTypes.length; ++i) {
var tp = scriptTypes[i];
if (typeof tp.matches == "string" ? scriptType == tp.matches : tp.matches.test(scriptType)) {
if (tp.mode) {
state.token = script;
state.localMode = tp.mode;
state.localState = tp.mode.startState && tp.mode.startState(htmlMode.indent(state.htmlState, ""));
}
break;
}
}
} else if (tagName == "style" && /\btag\b/.test(style) && stream.current() == ">") {
state.token = css;
state.localMode = cssMode;
state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
}
return style;
}
function maybeBackup(stream, pat, style) {
var cur = stream.current();
var close = cur.search(pat), m;
if (close > -1) stream.backUp(cur.length - close);
else if (m = cur.match(/<\/?$/)) {
stream.backUp(cur.length);
if (!stream.match(pat, false)) stream.match(cur[0]);
}
return style;
}
function script(stream, state) {
if (stream.match(/^<\/\s*script\s*>/i, false)) {
state.token = html;
state.localState = state.localMode = null;
return html(stream, state);
}
return maybeBackup(stream, /<\/\s*script\s*>/,
state.localMode.token(stream, state.localState));
}
function css(stream, state) {
if (stream.match(/^<\/\s*style\s*>/i, false)) {
state.token = html;
state.localState = state.localMode = null;
return html(stream, state);
}
return maybeBackup(stream, /<\/\s*style\s*>/,
cssMode.token(stream, state.localState));
}

return {
startState: function() {
var state = htmlMode.startState();
return {token: html, localMode: null, localState: null, htmlState: state};
},

copyState: function(state) {
if (state.localState)
var local = CodeMirror.copyState(state.localMode, state.localState);
return {token: state.token, localMode: state.localMode, localState: local,
htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
},

token: function(stream, state) {
return state.token(stream, state);
},

indent: function(state, textAfter) {
if (!state.localMode || /^\s*<\//.test(textAfter))
return htmlMode.indent(state.htmlState, textAfter);
else if (state.localMode.indent)
return state.localMode.indent(state.localState, textAfter);
else
return CodeMirror.Pass;
},

electricChars: "/{}:",

innerMode: function(state) {
return {state: state.localState || state.htmlState, mode: state.localMode || htmlMode};
}
};
}, "xml", "javascript", "css");

CodeMirror.defineMIME("text/html", "htmlmixed");
Loading

0 comments on commit f52b989

Please sign in to comment.