aboutsummaryrefslogtreecommitdiff
path: root/public/ng/js/utils/preview.js
diff options
context:
space:
mode:
authorMichael Boke <michael@mbict.nl>2014-10-03 22:51:07 +0200
committerMichael Boke <michael@mbict.nl>2014-10-03 22:51:07 +0200
commitba1270df2d3d835b397317f133963e7b517242f1 (patch)
tree1265a142a1fd9951d30ae11648e7fbfb5806e594 /public/ng/js/utils/preview.js
parentba0feadc34400cb91ff23f66096884d862651cdd (diff)
parent405ee14711ab946bd709ec28a526890c40cbc03b (diff)
Merge remote-tracking branch 'upstream/master'
Conflicts: conf/app.ini
Diffstat (limited to 'public/ng/js/utils/preview.js')
-rw-r--r--public/ng/js/utils/preview.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/public/ng/js/utils/preview.js b/public/ng/js/utils/preview.js
new file mode 100644
index 00000000..87ab39e5
--- /dev/null
+++ b/public/ng/js/utils/preview.js
@@ -0,0 +1,53 @@
+/**
+ * preview plugin
+ * @param selector
+ * @param target_selector
+ */
+function Preview(selector, target_selector) {
+
+ // get input element
+ function get_input($e) {
+ return $e.find(".js-preview-input").eq(0);
+ }
+
+ // get result html container element
+ function get_container($t) {
+ if ($t.hasClass("js-preview-container")) {
+ return $t
+ }
+ return $t.find(".js-preview-container").eq(0);
+ }
+
+ var $e = $(selector);
+ var $t = $(target_selector);
+
+ var $ipt = get_input($t);
+ if (!$ipt.length) {
+ console.log("[preview]: no preview input");
+ return
+ }
+ var $cnt = get_container($t);
+ if (!$cnt.length) {
+ console.log("[preview]: no preview container");
+ return
+ }
+
+
+ // call api via ajax
+ $e.on("click", function () {
+ $.post("/api/v1/markdown", {
+ text: $ipt.val()
+ }, function (html) {
+ $cnt.html(html);
+ })
+ });
+
+ console.log("[preview]: init preview @", selector, "&", target_selector);
+}
+
+
+$.fn.extend({
+ markdown_preview: function (target) {
+ Preview(this, target);
+ }
+});