Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
137 lines (124 sloc) 4.6 KB
<!doctype html>
<!-- See http://www.wildpad.io/docs/ for detailed embedding docs. -->
<html>
<head>
<meta charset="utf-8" />
<!-- Wilddog -->
<script src="https://cdn.wilddog.com/js/client/current/wilddog.js"></script>
<!-- CodeMirror -->
<script src="https://dl.wdstatic.cn/cloudflare/ajax/libs/codemirror/5.2.0/codemirror.js"></script>
<link rel="stylesheet" href="https://dl.wdstatic.cn/cloudflare/ajax/libs/codemirror/5.2.0/codemirror.css" />
<!-- Wildpad -->
<link rel="stylesheet" href="https://cdn.wilddog.com/app/wildpad/0.1/wildpad.css" />
<script src="https://cdn.wilddog.com/app/wildpad/0.1/wildpad.js"></script>
<style>
html { height: 100%; }
body { margin: 0; height: 100%; position: relative; }
/* Height / width / positioning can be customized for your use case.
For demo purposes, we make wildpad fill the entire browser. */
#wildpad-container {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="wildpad-container"></div>
<script>
function init() {
//// Initialize Wilddog.
var wildpadRef = getExampleRef();
// TODO: Replace above line with:
// var wildpadRef = new Wilddog('<YOUR WILDDOG URL>');
//// Create CodeMirror (with lineWrapping on).
var codeMirror = CodeMirror(document.getElementById('wildpad-container'), { lineWrapping: true });
//// Create Wildpad (with rich text toolbar and shortcuts enabled).
var wildpad = Wildpad.fromCodeMirror(wildpadRef, codeMirror,
{ richTextToolbar: true, richTextShortcuts: true });
//// Initialize contents.
wildpad.on('ready', function() {
if (wildpad.isHistoryEmpty()) {
wildpad.setHtml(
'<span style="font-size: 24px;">Rich-text editing with <span style="color: red">Wildpad!</span></span><br/>\n' +
'<br/>' +
'<div style="font-size: 18px">' +
'Supports:<br/>' +
'<ul>' +
'<li>Different ' +
'<span style="font-family: impact">fonts,</span>' +
'<span style="font-size: 24px;"> sizes, </span>' +
'<span style="color: blue">and colors.</span>' +
'</li>' +
'<li>' +
'<b>Bold, </b>' +
'<i>italic, </i>' +
'<u>and underline.</u>' +
'</li>' +
'<li>Lists' +
'<ol>' +
'<li>One</li>' +
'<li>Two</li>' +
'</ol>' +
'</li>' +
'<li>Undo / redo</li>' +
'<li>Cursor / selection synchronization.</li>' +
'<li><checkbox></checkbox> It supports customized entities.</li>' +
'<li>And it\'s all fully collaborative!</li>' +
'</ul>' +
'</div>');
}
});
// An example of a complex custom entity.
wildpad.registerEntity('checkbox', {
render: function (info, entityHandler) {
var inputElement = document.createElement('input');
inputElement.setAttribute('type', 'checkbox');
if(info.checked) {
inputElement.checked = 'checked';
}
inputElement.addEventListener('click', function () {
entityHandler.replace({checked:this.checked});
});
return inputElement;
}.bind(this),
fromElement: function (element) {
var info = {};
if(element.hasAttribute('checked')) {
info.checked = true;
}
return info;
},
update: function (info, element) {
if (info.checked) {
element.checked = 'checked';
} else {
element.checked = null;
}
},
export: function (info) {
var inputElement = document.createElement('checkbox');
if(info.checked) {
inputElement.setAttribute('checked', true);
}
return inputElement;
}
});
}
// Helper to get hash from end of URL or generate a random one.
function getExampleRef() {
var ref = new Wilddog('https://wildpad.wilddogio.com');
var hash = window.location.hash.replace(/#/g, '');
if (hash) {
ref = ref.child(hash);
} else {
ref = ref.push(); // generate unique location.
window.location = window.location + '#' + ref.key(); // add it as a hash to the URL.
}
if (typeof console !== 'undefined')
console.log('Wilddog data: ', ref.toString());
return ref;
}
init();
</script>
</body>
</html>