Skip to content

Commit c6fc595

Browse files
robertleeplummerjrrobertleeplummerjr
robertleeplummerjr
authored and
robertleeplummerjr
committed
UI mostly working, not yet saving
1 parent 5ca8a4a commit c6fc595

File tree

5 files changed

+305
-70
lines changed

5 files changed

+305
-70
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
wikiLingo for wordpress
22
=========
3-
Allows wikiLingo to be enabled in posts, comments and pages
3+
Allows wikiLingo to be enabled in posts, comments, and pages
44

55
<a href="http://visop-dev.com/repo/download/wikiLingoWordPressPlugin.zip">Download Pre Alpha</a>
66

@@ -11,6 +11,6 @@ This plug-in allows you to write using wikiLingo.
1111

1212
Installation is standard and straight forward.
1313

14-
1. Upload as a folder, `wp-wikiLingo`, (and all it's contents!) to the `/wp-content/plugins/` directory
14+
1. Upload as a folder, `wikiLingo`, (and all it's contents!) to the `/wp-content/plugins/` directory
1515
1. Activate the plugin through the 'Plugins' menu in WordPress
1616
1. Go to your Settings > Writing page and enable wikiLingo for the appropriate types

_WP_Editors.php

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
//overwrites the internal WordPress Editors
4+
class _WP_Editors
5+
{
6+
public static function editor($content, $editor_id, $settings)
7+
{
8+
9+
echo <<<HTML
10+
<div id="$editor_id-container" class="wp-editor-container">
11+
<div>
12+
<div id="$editor_id-wysiwyg" style="min-height: 300px;" class="poststuff">$content</div>
13+
</div>
14+
<div>
15+
<textarea id="$editor_id"></textarea>
16+
</div>
17+
<input type="button" class="button" value="Toggle Editor" id="$editor_id-button"/>
18+
<script>
19+
jQuery(function() {
20+
var visual = document.getElementById('$editor_id-wysiwyg'),
21+
source = document.getElementById('$editor_id'),
22+
button = document.getElementById('$editor_id-button'),
23+
visualParentStyle = visual.parentNode.style,
24+
sourceParentStyle = source.parentNode.style;
25+
26+
wikiLingoEditor(visual, source);
27+
sourceParentStyle.display = 'none';
28+
29+
button.onclick = function() {
30+
if (sourceParentStyle.display === 'none') {
31+
sourceParentStyle.display = '';
32+
visualParentStyle.display = 'none';
33+
} else {
34+
sourceParentStyle.display = 'none';
35+
visualParentStyle.display = '';
36+
}
37+
};
38+
39+
});
40+
</script>
41+
</div>
42+
HTML;
43+
44+
}
45+
}
46+
47+
global $_updated_user_settings;
48+
$_updated_user_settings['editor_expand'] = 'off';

composer.lock

+23-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wikilingo.editor.js

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
var wikiLingoEditor = (function($) {
2+
"use strict";
3+
4+
var
5+
WLPlugin = function(el) {
6+
if (el.getAttribute('data-draggable') == 'true') {
7+
new WLPluginAssistant(el);
8+
}
9+
},
10+
color = function(element) {
11+
var newColor = prompt('What color?', element.style['color']);
12+
if (newColor) {
13+
element.style['color'] = newColor
14+
}
15+
},
16+
table = function(element) {
17+
18+
};
19+
20+
return function(editable, editableSource) {
21+
22+
23+
//bubble is the contenteditable toolbar, it is very simple and instantiated here
24+
var
25+
//medium makes contenteditable behave
26+
medium = editable.medium = new Medium({
27+
element: editable,
28+
mode: 'rich',
29+
placeholder: 'Content',
30+
autoHR: false,
31+
attributes: {
32+
remove: []
33+
},
34+
tags: {
35+
paragraph: 'p',
36+
outerLevel: null,
37+
innerLevel: null
38+
},
39+
modifiers: [],
40+
beforeInvokeElement: function() {
41+
console.log(this);
42+
},
43+
beforeInsertHtml: function() {
44+
console.log(this);
45+
},
46+
beforeAddTag: function(tag, shouldFocus, isEditable, afterElement) {
47+
var newEl;
48+
switch (tag) {
49+
case 'br':
50+
case 'p':
51+
newEl = document.createElement('br');
52+
newEl.setAttribute('class', 'element');
53+
newEl.setAttribute('data-element', 'true');
54+
newEl.setAttribute('data-type', 'WikiLingo\\\\Expression\\\\Line');
55+
56+
this.insertHtml(newEl);
57+
return true;
58+
}
59+
60+
return newEl;
61+
}
62+
}),
63+
bubble = new WLBubble(window.expressionSyntaxes, editable),
64+
codemirror = CodeMirror.fromTextArea(editableSource, {
65+
mode: 'wikiLingo',
66+
lineNumbers: false,
67+
readOnly: false,
68+
lineWrapping: true,
69+
scroll: false
70+
}),
71+
settingSource = false,
72+
updateSource = function() {
73+
$.ajax({
74+
type: 'POST',
75+
dataType: 'json',
76+
url: 'reflect.php',
77+
data: {w: editable.innerHTML, reflect:'WYSIWYGWikiLingo'},
78+
success: function(result) {
79+
settingSource = true;
80+
codemirror.setValue(result.output);
81+
editableSource.value = result.output;
82+
settingSource = false;
83+
}
84+
});
85+
},
86+
updateWYSIWYG = function() {
87+
$.ajax({
88+
type: 'POST',
89+
dataType: 'json',
90+
url: 'reflect.php',
91+
data: {w: codemirror.getValue(), reflect:'wikiLingoWYSIWYG'},
92+
success: function(result) {
93+
editable.innerHTML = result.output;
94+
window.wLPlugins = result.plugins;
95+
96+
$('body')
97+
.append(result.css)
98+
.append(result.script)
99+
.trigger('resetWLPlugins');
100+
}
101+
});
102+
};
103+
104+
codemirror.on('change', function() {
105+
if (!settingSource) {
106+
updateWYSIWYG();
107+
}
108+
});
109+
110+
$(editable)
111+
.on('mouseup', function(event) {
112+
if (document.activeElement === this) {
113+
bubble.goToSelection();
114+
}
115+
})
116+
.on('focus', function() {
117+
this.before = this.innerHTML;
118+
return this;
119+
})
120+
.on('blur keyup paste input', function() {
121+
var me = $(this);
122+
if (this.before !== this.innerHTML) {
123+
this.before = this.innerHTML;
124+
setTimeout(function() {
125+
me.trigger('change');
126+
}, 10);
127+
}
128+
return this;
129+
})
130+
.on('change', updateSource);
131+
132+
$(editableSource)
133+
.on('change', updateWYSIWYG);
134+
135+
136+
$('body')
137+
.on('resetWLPlugins', function() {
138+
if (window.wLPlugins !== undefined) {
139+
for(var i = 0; i < wLPlugins.length; i++) {
140+
new WLPlugin(document.getElementById(wLPlugins[i]));
141+
}
142+
}
143+
})
144+
.trigger('resetWLPlugins');
145+
146+
147+
bubble.staticToTop();
148+
149+
console.log(window.expressionSyntaxes);
150+
}
151+
})(jQuery);

0 commit comments

Comments
 (0)