forked from wikiLingo/wikiLingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.php
184 lines (149 loc) · 5.44 KB
/
editor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
//setup auto load
require_once("vendor/autoload.php");
//create scripts collector utility
$scripts = (new WikiLingo\Utilities\Scripts())
//add some css
->addCssLocation("~jquery/jquery-ui/themes/base/jquery.ui.all.css")
->addCssLocation("~mediumjs/mediumjs/medium.css")
->addCssLocation("~/editor/bubble.css")
->addCssLocation("~/editor/IcoMoon/sprites/sprites.css")
->addCssLocation("~/editor/pastLink.css")
//add some javascript
->addScriptLocation("~jquery/jquery/jquery-1.10.2.js")
->addScriptLocation("~jquery/jquery-ui/ui/jquery-ui.js")
->addScriptLocation("~undojs/undojs/undo.js")
->addScriptLocation("~rangy/rangy/uncompressed/rangy-core.js")
->addScriptLocation("~rangy/rangy/uncompressed/rangy-cssclassapplier.js")
->addScriptLocation("~mediumjs/mediumjs/medium.js")
//this doesn't work now with composer
->addCssLocation("~codemirror/codemirror/lib/codemirror.css")
->addScriptLocation("~codemirror/codemirror/lib/codemirror.js")
->addCssLocation("~wikilingo/codemirror/wikiLingo.css")
->addScriptLocation("~wikilingo/codemirror/wikiLingo.js")
->addScriptLocation("~/editor/WLExpressionUI.js")
->addScriptLocation("~/editor/WLPluginEditor.js")
->addScriptLocation("~/editor/WLPluginAssistant.js")
->addScriptLocation("~/editor/bubble.js")
->addScriptLocation("~/editor/editor.js")
->addScriptLocation("~/WikiLingo/Definition.js")
->addScriptLocation("~/WikiLingo/Parsed.js")
->addScriptLocation("~/WikiLingo/Parser.js")
/*->addScript(<<<JS
var parser = new WikiLingo.Parser();
console.log(parser.parse(document.getElementById('editableSource').value));
CodeMirror.StringStream.prototype.eatM = CodeMirror.StringStream.prototype.eat;
CodeMirror.StringStream.prototype.eat = function(match) {
console.log(this);
return this.eatM(match);
};
JS
)*/
->addCss(<<<CSS
@font-face {
font-family: "dayRoman";
src: url(editor/font/dayRoman.woff);
}
body {
background-image: url(editor/img/canvas.jpg);
font-family: "dayRoman";
color: white;
}
.canvas {
background-color: rgba(255,255,255, 1);
-moz-box-shadow: 0px 0px 3px 4px rgba(0, 0, 0, 0.5);
-webkit-box-shadow: 0px 0px 3px 4px rgba(0, 0, 0, 0.5);
box-shadow: 0px 0px 3px 4px rgba(0, 0, 0, 0.5);
border-radius: 10px;
padding: 10px;
}
div.CodeMirror {
height: inherit;
}
.canvas-header {
text-align: center;
}
.canvas-header {
text-shadow: 2px 2px #000000;
}
.canvas > div {
color: rgba(0, 0, 0, 0.75);
background-color: transparent;
}
.canvas a {
text-decoration: none;
color: rgba(0, 0, 0, 1);
}
CSS
);
//create a wikiLingo to WYSIWYG parser, and send scripts collector to it
$parser = new WikiLingoWYSIWYG\Parser($scripts);
//open a file and parse it
$source = file_get_contents('editor/page.wl');
$page = $parser->parse($source);
//create a new group of possible syntaxes possible in the WikiLingo to WYSIWYG parser
$expressionSyntaxes = new WikiLingoWYSIWYG\ExpressionSyntaxes($scripts);
//bind to event "WikiLingoWYSIWYG\Event\ExpressionSyntax\Registered",giving certain syntax extra attributes
$expressionSyntaxes->parser->events->bind(new WikiLingoWYSIWYG\Event\ExpressionSyntax\Registered(function(\WikiLingoWYSIWYG\ExpressionType $expressionType) {
switch ($expressionType->name) {
case 'Plugin':
$expressionType->extraAttributes['onmouseover'] = '';
break;
case 'Table':
$expressionType->extraAttributes['data-bubble-event'] = 'table';
break;
case 'Color':
$expressionType->extraAttributes['ondblclick'] = 'color(this);return false;';
break;
}
}));
//register expression types so that they can be turned into json and sent to browser
$expressionSyntaxes->registerExpressionTypes();
//json encode the parsed expression syntaxes
$expressionSyntaxesJson = json_encode($expressionSyntaxes->parsedExpressionSyntaxes);
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>wikiLingo editor (contenteditable only and a tiny bit of js and css)</title>
<?php
//render css from scripts collector and bring it to the page
echo $scripts->renderCss();
?>
</head>
<body>
<div id="header" style="text-align: center;">
<h1><img src="editor/img/wLogo.png" style="width: 40px;"/> wikiLingo</h1>
</div><?php //create an editable area and echo page to it ?>
<table style="width: 75%; margin-left: auto; margin-right: auto;">
<tr>
<td style="width: 60%; vertical-align: top;">
<h2 class="canvas-header">edit visually</h2>
<div class="canvas">
<div id="editable" contenteditable="true" style="border: none;"><?php echo $page;?></div>
</div>
</td>
<td style="width: 3%; vertical-align: top; text-align: center;">
<h2 class="canvas-header">
or
</h2>
<span style="font-size: 30px; position:relative; top: 250px;">=</span>
</td>
<td style="width: 37%; vertical-align: top;">
<h2 class="canvas-header">edit wiki markup</h2>
<div class="canvas">
<textarea id="editableSource" style="width: 100%; height: 400px;"><?php echo $source; ?></textarea>
</div>
</td>
</tr>
</table>
</body>
<script>
window.expressionSyntaxes = <?php echo $expressionSyntaxesJson; ?>;
window.wLPlugins = <?php echo json_encode($parser->plugins); ?>;
</script>
<?php
//echo script from the scripts collector to page
echo $scripts->renderScript();
?>
</html>