# HG changeset patch # User Adam Chlipala # Date 1385075942 18000 # Node ID 2d195bee1efa4f7f93257fd986385c475d3d3e34 # Parent 2e7f8f7d71d456705ce0a19cb7400bc01d0c4fec CKeditor wrapper diff -r 2e7f8f7d71d4 -r 2d195bee1efa ckeditor.js --- /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(); +} diff -r 2e7f8f7d71d4 -r 2d195bee1efa ckeditor.ur --- /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 = + + + }/> + }/> + diff -r 2e7f8f7d71d4 -r 2d195bee1efa ckeditor.urp --- /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 diff -r 2e7f8f7d71d4 -r 2d195bee1efa ckeditor.urs --- /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 diff -r 2e7f8f7d71d4 -r 2d195bee1efa ckeditorFfi.urs --- /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 diff -r 2e7f8f7d71d4 -r 2d195bee1efa examples/ckedit.ur --- /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 + {show editor} +
+