-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
12,357 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,39 @@ | ||
# zk-codemirror | ||
Integration Codemirror library in ZK 7 framework | ||
Integration of Codemirror library in ZK 7 framework | ||
|
||
##Usage | ||
|
||
```xml | ||
<?page title="ZK Code mirror example"?> | ||
<window title="ZK Code mirror example" border="normal" mode="overlapped" sizable="true"> | ||
<hlayout vflex="1"> | ||
<codemirror id="s" hflex="1" vflex="1" mode="javascript" | ||
value="function abc() {}"></codemirror> | ||
</hlayout> | ||
<hlayout> | ||
<div hflex="1"></div> | ||
<button label="ok" onClick="alert(s.getText())" /> | ||
<button label="mode" onClick='s.setMode("text/x-java");'/> | ||
</hlayout> | ||
</window> | ||
``` | ||
|
||
## Supported modes | ||
|
||
* HTML mode = "text/html"; | ||
* JAVA mode = "x-java"; | ||
* JAVASCRIPT mode = "text/javascript"; | ||
* C mode = "text/x-csrc"; | ||
* CPP mode = "text/x-c++src"; | ||
* OBJECTIVE_C mode = "text/x-objectivec"; | ||
* SCALA mode = "text/x-scala"; | ||
* KOTLIN mode = "text/x-kotlin"; | ||
* CEYLON mode = "text/x-ceylon"; | ||
* CSHARP mode = "text/x-csharp"; | ||
* JSON mode = "application/json"; | ||
* LD_JSON mode = "application/ld+json"; | ||
* TYPESCRIPT mode = "text/typescript"; | ||
* CSS mode = "text/css"; | ||
* SCSS mode = "text/x-scss"; | ||
* LESS mode = "text/x-less"; | ||
* XML mode = "application/xml"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Class-Path: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- ZK will load this file | ||
(classpath/metainfo/zk/lang-addon.xml) automatically --> | ||
|
||
<language-addon> | ||
<!-- addon name, | ||
required, it's better to be unique --> | ||
<addon-name>codemirror</addon-name> | ||
<!-- specifies the name of a language definition | ||
should be unique in a language definition, | ||
xul/html is predefinied language in ZK | ||
so can be used in lang-addon directly --> | ||
<language-name>xul/html</language-name> | ||
|
||
<!-- version | ||
optional, | ||
if the version specified in version-class is not | ||
the same as version-uid, or the real ZK version is smaller | ||
then zk-version, the addon will be ignored --> | ||
<version> | ||
<version-class>org.sinnlabs.zk.codemirror.Version</version-class> | ||
<version-uid>0.0.1</version-uid> | ||
<zk-version>7.0.0</zk-version><!-- or later --> | ||
</version> | ||
|
||
<!-- define a component --> | ||
<component> | ||
<!-- the tag name of this component | ||
required, | ||
must be unique --> | ||
<component-name>codemirror</component-name> | ||
<!-- fully-qualified java class name at server side | ||
required for a new component that not extends another component --> | ||
<component-class>org.sinnlabs.zk.ui.CodeMirror</component-class> | ||
<!-- widget class, 'org.sinnlabs.zk.ui.CodeMirror' also specify the | ||
package of widget class 'org.sinnlabs.zk.ui' | ||
required for a new component that not extends another component --> | ||
|
||
<widget-class>org.sinnlabs.zk.ui.CodeMirrorWidget</widget-class> | ||
<!-- mold | ||
required for a new component that not extends another component | ||
or has self widget-class | ||
a mold denotes the files that to render and style this comopnent --> | ||
<mold> | ||
<!-- default mold is required --> | ||
<mold-name>default</mold-name> | ||
<!-- relative path based on widget-class' path | ||
(web/js/org/sinnlabs/zk/ui/) | ||
where codemirrorwidget.js (required) contains a function that | ||
will render the html of the comopnent. --> | ||
<mold-uri>mold/codemirrorwidget.js</mold-uri> | ||
<css-uri>css/codemirror.css</css-uri> | ||
</mold> | ||
</component> | ||
</language-addon> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* CodeMirror.java | ||
* | ||
* Copyright (C) 2015 Sinnlabs LTD. All Rights Reserved. | ||
* | ||
* {{IS_RIGHT | ||
* This program is distributed under LGPL Version 2.1 in the hope that | ||
* it will be useful, but WITHOUT ANY WARRANTY. | ||
* }}IS_RIGHT | ||
*/ | ||
package org.sinnlabs.zk.codemirror; | ||
|
||
/** | ||
* Language addon version | ||
* @author peter.liverovsky | ||
* | ||
*/ | ||
public class Version { | ||
public static final String UID = "0.0.1"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* CodeMirror.java | ||
* | ||
* Copyright (C) 2015 Sinnlabs LTD. All Rights Reserved. | ||
* | ||
* {{IS_RIGHT | ||
* This program is distributed under LGPL Version 2.1 in the hope that | ||
* it will be useful, but WITHOUT ANY WARRANTY. | ||
* }}IS_RIGHT | ||
*/ | ||
package org.sinnlabs.zk.ui; | ||
|
||
import java.io.IOException; | ||
|
||
import org.zkoss.zk.ui.sys.ContentRenderer; | ||
import org.zkoss.zul.Textbox; | ||
|
||
/** | ||
* Class represents source editor component for ZK framework | ||
* @author peter.liverovsky | ||
* | ||
*/ | ||
public class CodeMirror extends Textbox { | ||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = -6278831344472300331L; | ||
|
||
public static final String TEXT_HTML = "text/html"; | ||
|
||
public static final String JAVA = "x-java"; | ||
|
||
public static final String JAVASCRIPT = "text/javascript"; | ||
|
||
public static final String C = "text/x-csrc"; | ||
|
||
public static final String CPP = "text/x-c++src"; | ||
|
||
public static final String OBJECTIVE_C = "text/x-objectivec"; | ||
|
||
public static final String SCALA = "text/x-scala"; | ||
|
||
public static final String KOTLIN = "text/x-kotlin"; | ||
|
||
public static final String CEYLON = "text/x-ceylon"; | ||
|
||
public static final String CSHARP = "text/x-csharp"; | ||
|
||
public static final String JSON = "application/json"; | ||
|
||
public static final String LD_JSON = "application/ld+json"; | ||
|
||
public static final String TYPESCRIPT = "text/typescript"; | ||
|
||
public static final String CSS = "text/css"; | ||
|
||
public static final String SCSS = "text/x-scss"; | ||
|
||
public static final String LESS = "text/x-less"; | ||
|
||
public static final String XML = "application/xml"; | ||
|
||
private String _mode = TEXT_HTML; | ||
|
||
public CodeMirror() { | ||
super(); | ||
this.setZclass("z-div"); | ||
} | ||
|
||
public CodeMirror(String value) { | ||
super(value); | ||
setZclass("z-div"); | ||
} | ||
|
||
/** | ||
* Returns syntax mode | ||
* @return | ||
*/ | ||
public String getMode() { | ||
return _mode; | ||
} | ||
|
||
/** | ||
* Sets the syntax mode name | ||
* @param name - Mode name | ||
*/ | ||
public void setMode(String name) { | ||
_mode = name; | ||
smartUpdate("mode", _mode); | ||
} | ||
|
||
@Override | ||
protected void renderProperties(ContentRenderer renderer) throws IOException { | ||
super.renderProperties(renderer); | ||
render(renderer, "mode", _mode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* CodeMirrorWidget.js | ||
* Purpose: | ||
* | ||
* Description: | ||
* | ||
* History: | ||
Tue Nov 15 14:47:28 2015, Created by peter.liverovsky | ||
* Copyright (C) 2015 Sinnlabs LTD. All Rights Reserved. | ||
* This program is distributed under LGPL Version 2.1 in the hope that | ||
* it will be useful, but WITHOUT ANY WARRANTY. | ||
*/ | ||
|
||
zk.$package('org.sinnlabs.zk.ui'); | ||
|
||
(function () { | ||
|
||
function stopOnChanging_(wgt) { | ||
if (wgt._tChg) { | ||
clearTimeout(wgt._tChg); | ||
wgt._tChg = null; | ||
} | ||
} | ||
|
||
function startOnChanging_(wgt) { | ||
stopOnChanging_(wgt); | ||
wgt._tChg = setTimeout(wgt.proxy(onChanging_), zul.inp.InputWidget.onChangingDelay); | ||
} | ||
|
||
function onChanging_() { | ||
this.fireOnChange(); | ||
} | ||
|
||
var SourceWidget = | ||
/** | ||
* <p>The delay to send the onChanging event is controlled by | ||
* {@link #onChangingDelay}, which is default to 350. | ||
* To change it, you can specify the following in a ZUL file. | ||
* <pre><code> | ||
<?script content="zk.afterLoad('zul.inp',function(){zul.inp.InputWidget.onChangingDelay=1000;})"?> | ||
</code></pre> | ||
*/ | ||
org.sinnlabs.zk.ui.CodeMirrorWidget = zk.$extends(zul.inp.Textbox, { | ||
|
||
_codemirror: null, | ||
|
||
_mode: "text/html", | ||
|
||
$init: function () { | ||
this.$supers('$init', arguments); | ||
zWatch.listen({onSize: [this, this.onSize_]}); | ||
}, | ||
|
||
bind_: function (dt, skipper, after) { | ||
this.$supers('bind_', arguments); | ||
var wgt = this; | ||
_codemirror = CodeMirror.fromTextArea(this.$n('codemirror'), { | ||
lineNumbers: true, | ||
mode: wgt._mode, | ||
matchBrackets: true | ||
}); | ||
_codemirror.on('blur', function () { | ||
var val = _codemirror.getValue(); | ||
wgt.setValue(val); | ||
if (wgt._tChg) { | ||
clearTimeout(wgt._tChg); | ||
wgt._tChg = null; | ||
} | ||
wgt.fireOnChange(); | ||
}); | ||
_codemirror.on('keydown', function (evnt) { | ||
stopOnChanging_(wgt); //wait for key up | ||
}); | ||
_codemirror.on('keyup', function (evnt) { | ||
startOnChanging_(wgt); | ||
}); | ||
this._multiline = true; | ||
}, | ||
|
||
fireOnChange: function () { | ||
var val = _codemirror.getValue(); | ||
this.setValue(val); | ||
this.fire('onChange', {value: val}, {toServer: true}); | ||
}, | ||
|
||
onSize_: function (e) { | ||
_codemirror.refresh(); | ||
}, | ||
|
||
setMode: function (val) { | ||
if (this._mode != val) { | ||
this._mode = val; | ||
if (this._codemirror) { | ||
_codemirror.setOption("mode", _mode); | ||
} | ||
} | ||
}, | ||
|
||
getMode: function() { | ||
return _mode; | ||
} | ||
}); | ||
})(); |
Oops, something went wrong.