changeset 34:2d195bee1efa tip

CKeditor wrapper
author Adam Chlipala <adam@chlipala.net>
date Thu, 21 Nov 2013 18:19:02 -0500
parents 2e7f8f7d71d4
children
files ckeditor.js ckeditor.ur ckeditor.urp ckeditor.urs ckeditorFfi.urs examples/ckedit.ur examples/ckedit.urp examples/ckedit.urs
diffstat 8 files changed, 355 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ckeditor.js	Thu Nov 21 18:19:02 2013 -0500
@@ -0,0 +1,68 @@
+function toolbar_set(toolbars) {
+    var toolbarsOut = [];
+
+    for (; toolbars != null; toolbars = toolbars._2) {
+        var toolbar = toolbars._1;
+
+        if (toolbar == null)
+            toolbarsOut.push('/');
+        else if (toolbar.n == "Bar") {
+            var buttonsOut = [], r = toolbar.v;
+            var name = r._Nam;
+
+            for (var buttons = r._Buttons; buttons != null; buttons = buttons._2) {
+                var button = buttons._1;
+                buttonsOut.push(button == "Separator" ? "-" : button);
+            }
+
+            if (name == null)
+                toolbarsOut.push(buttonsOut);
+            else
+                toolbarsOut.push({name: name, items: buttonsOut});
+        } else
+            throw ("Invalid Ckeditor toolbar " + toolbar);
+    }
+
+    return toolbarsOut;
+}
+
+function sizeOut(v) {
+    if (v == "DefaultSize")
+        return null;
+    else if (v.n == "Pixels")
+        return (ts(v.v));
+    else if (v.n == "Percent")
+        return (ts(v.v) + "%");
+    else
+        throw ("Invalid Ckeditor.size " + v);
+}
+
+function uw_ckeditor_editor(r) {
+    var config = {};
+
+    var width = sizeOut(r._Width);
+    if (width != null)
+        config.width = width;
+
+    var height = sizeOut(r._Height);
+    if (height != null)
+        config.height = height;
+
+    var toolbarSet = r._ToolbarSet;
+
+    if (toolbarSet != null)
+        config.toolbar = toolbar_set(toolbarSet.v);
+    
+    return {config: config, name: fresh()}
+}
+
+function uw_ckeditor_replace(t, id) {
+    t.editor = CKEDITOR.replace(id, t.config);
+}
+
+function uw_ckeditor_content(t) {
+    if (t.editor == undefined)
+        return "";
+    else
+        return t.editor.getData();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ckeditor.ur	Thu Nov 21 18:19:02 2013 -0500
@@ -0,0 +1,9 @@
+open CkeditorFfi
+
+fun show ed = <xml>
+  <active code={id <- fresh;
+                return <xml>
+                  <span id={id}/>
+                  <active code={CkeditorFfi.replace ed id; return <xml/>}/>
+                </xml>}/>
+</xml>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ckeditor.urp	Thu Nov 21 18:19:02 2013 -0500
@@ -0,0 +1,12 @@
+ffi ckeditorFfi
+jsFunc CkeditorFfi.editor=uw_ckeditor_editor
+jsFunc CkeditorFfi.replace=uw_ckeditor_replace
+jsFunc CkeditorFfi.content=uw_ckeditor_content
+clientOnly CkeditorFfi.editor
+clientOnly CkeditorFfi.replace
+clientOnly CkeditorFfi.content
+benignEffectful CkeditorFfi.editor
+benignEffectful CkeditorFfi.replace
+benignEffectful CkeditorFfi.content
+
+ckeditor
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ckeditor.urs	Thu Nov 21 18:19:02 2013 -0500
@@ -0,0 +1,112 @@
+datatype size =
+         DefaultSize
+       | Pixels of int
+       | Percent of int
+
+datatype button =
+         Separator
+
+       | Source
+       | Save
+       | NewPage
+       | DocProps
+       | Preview
+       | Print
+       | Templates
+       | Document
+
+       | Cut
+       | Copy
+       | Paste
+       | PasteText
+       | PasteFromWord
+       | Undo
+       | Redo
+
+       | Find
+       | Replace
+       | SelectAll
+       | Scayt
+
+       | Form
+       | Checkbox
+       | Radio
+       | TextField
+       | Textarea
+       | Select
+       | Button
+       | ImageButton
+       | HiddenField
+
+       | Bold
+       | Italic
+       | Underline
+       | Strike
+       | Subscript
+       | Superscript
+       | RemoveFormat
+
+       | NumberedList
+       | BulletedList
+       | Outdent
+       | Indent
+       | Blockquote
+       | CreateDiv
+       | JustifyLeft
+       | JustifyCenter
+       | JustifyRight
+       | JustifyBlock
+       | BidiLtr
+       | BidiRtl
+
+       | Link
+       | Unlink
+       | Anchor
+
+       | CreatePlaceholder
+       | Image
+       | Flash
+       | Table
+       | HorizontalRule
+       | Smiley
+       | SpecialChar
+       | PageBreak
+       | Iframe
+       | InsertPre
+
+       | Styles
+       | Format
+       | Font
+       | FontSize
+
+       | TextColor
+       | BGColor
+
+       | UIColor
+       | Maximize
+       | ShowBlocks
+  	
+       | Button1
+       | Button2
+       | Button3
+       | Oembed
+       | MediaEmbed
+
+       | About
+
+datatype toolbar =
+         Newline
+       | Bar of { Nam : option string, Buttons : list button }
+
+datatype toolbar_set =
+         DefaultToolbarSet
+       | Custom of list toolbar
+
+type editor
+
+val editor : {Width : size,
+              Height : size,
+              ToolbarSet : toolbar_set}
+             -> transaction editor
+val show : editor -> xbody
+val content : editor -> transaction string
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ckeditorFfi.urs	Thu Nov 21 18:19:02 2013 -0500
@@ -0,0 +1,112 @@
+datatype size =
+         DefaultSize
+       | Pixels of int
+       | Percent of int
+
+datatype button =
+         Separator
+
+       | Source
+       | Save
+       | NewPage
+       | DocProps
+       | Preview
+       | Print
+       | Templates
+       | Document
+
+       | Cut
+       | Copy
+       | Paste
+       | PasteText
+       | PasteFromWord
+       | Undo
+       | Redo
+
+       | Find
+       | Replace
+       | SelectAll
+       | Scayt
+
+       | Form
+       | Checkbox
+       | Radio
+       | TextField
+       | Textarea
+       | Select
+       | Button
+       | ImageButton
+       | HiddenField
+
+       | Bold
+       | Italic
+       | Underline
+       | Strike
+       | Subscript
+       | Superscript
+       | RemoveFormat
+
+       | NumberedList
+       | BulletedList
+       | Outdent
+       | Indent
+       | Blockquote
+       | CreateDiv
+       | JustifyLeft
+       | JustifyCenter
+       | JustifyRight
+       | JustifyBlock
+       | BidiLtr
+       | BidiRtl
+
+       | Link
+       | Unlink
+       | Anchor
+
+       | CreatePlaceholder
+       | Image
+       | Flash
+       | Table
+       | HorizontalRule
+       | Smiley
+       | SpecialChar
+       | PageBreak
+       | Iframe
+       | InsertPre
+
+       | Styles
+       | Format
+       | Font
+       | FontSize
+
+       | TextColor
+       | BGColor
+
+       | UIColor
+       | Maximize
+       | ShowBlocks
+  	
+       | Button1
+       | Button2
+       | Button3
+       | Oembed
+       | MediaEmbed
+
+       | About
+
+datatype toolbar =
+         Newline
+       | Bar of { Nam : option string, Buttons : list button }
+
+datatype toolbar_set =
+         DefaultToolbarSet
+       | Custom of list toolbar
+
+type editor
+
+val editor : {Width : size,
+              Height : size,
+              ToolbarSet : toolbar_set}
+             -> transaction editor
+val replace : editor -> id -> transaction unit
+val content : editor -> transaction string
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/ckedit.ur	Thu Nov 21 18:19:02 2013 -0500
@@ -0,0 +1,35 @@
+open Ckeditor
+
+fun make1 () =
+    editor <- editor {Width = DefaultSize,
+                      Height = DefaultSize,
+                      ToolbarSet = DefaultToolbarSet};
+    return <xml>
+      {show editor}
+      <hr/>
+      <button onclick={fn _ => s <- content editor; alert s}/>
+    </xml>
+
+fun make2 () =
+    editor <- editor {Width = Percent 50,
+                      Height = Pixels 500,
+                      ToolbarSet = Custom (
+                      Bar {Nam = Some "bloop", Buttons = Cut :: Separator :: Paste :: []}
+                          :: Newline
+                          :: Bar {Nam = None, Buttons = Bold :: []}
+                          :: [])};
+    return <xml>
+      {show editor}
+      <hr/>
+      <button onclick={fn _ => s <- content editor; alert s}/>
+    </xml>
+
+fun main () =
+    spot1 <- source <xml/>;
+    spot2 <- source <xml/>;
+    return <xml><body onload={x1 <- make1 (); set spot1 x1;
+                              x2 <- make2 (); set spot2 x2}>
+      <dyn signal={signal spot1}/>
+      <hr/>
+      <dyn signal={signal spot2}/>
+    </body></xml>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/ckedit.urp	Thu Nov 21 18:19:02 2013 -0500
@@ -0,0 +1,6 @@
+library ../ckeditor
+rewrite all Ckedit/*
+script http://ckeditor.com/apps/ckeditor/4.3/ckeditor.js
+script http://localhost/ckeditor/ckeditor.js
+
+ckedit
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/ckedit.urs	Thu Nov 21 18:19:02 2013 -0500
@@ -0,0 +1,1 @@
+val main : unit -> transaction page