This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
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
1 parent
bce9f31
commit 0cfc82a
Showing
3 changed files
with
83 additions
and
75 deletions.
There are no files selected for viewing
85 changes: 42 additions & 43 deletions
85
assets/javascripts/discourse/initializers/checklist.js.es6
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,73 +1,72 @@ | ||
import { withPluginApi } from 'discourse/lib/plugin-api'; | ||
import AjaxLib from 'discourse/lib/ajax'; | ||
import TextLib from 'discourse/lib/text'; | ||
import { withPluginApi } from "discourse/lib/plugin-api"; | ||
import AjaxLib from "discourse/lib/ajax"; | ||
import TextLib from "discourse/lib/text"; | ||
|
||
function initializePlugin(api) | ||
{ | ||
const siteSettings = api.container.lookup('site-settings:main'); | ||
function initializePlugin(api) { | ||
const siteSettings = api.container.lookup("site-settings:main"); | ||
|
||
if (siteSettings.checklist_enabled) | ||
{ | ||
if (siteSettings.checklist_enabled) { | ||
api.decorateCooked(checklistSyntax); | ||
} | ||
} | ||
|
||
export function checklistSyntax($elem, post) | ||
{ | ||
if (!post) { return; } | ||
export function checklistSyntax($elem, post) { | ||
if (!post) { | ||
return; | ||
} | ||
|
||
var boxes = $elem.find(".chcklst-box"), | ||
viewPost = post.getModel(); | ||
|
||
if (!viewPost.can_edit) { return; } | ||
if (!viewPost.can_edit) { | ||
return; | ||
} | ||
|
||
boxes.each(function(idx, val) | ||
{ | ||
$(val).click(function(ev) | ||
{ | ||
boxes.each(function(idx, val) { | ||
$(val).click(function(ev) { | ||
var elem = $(ev.currentTarget), | ||
new_value = elem.hasClass("checked") ? "[ ]": "[\\*]"; | ||
new_value = elem.hasClass("checked") ? "[ ]" : "[\\*]"; | ||
|
||
elem.after('<i class="fa fa-spinner fa-spin fa-fw"></i>'); | ||
elem.hide(); | ||
|
||
var postId = viewPost.id; | ||
AjaxLib.ajax("/posts/" + postId, { type: 'GET', cache: false }).then(function(result) | ||
{ | ||
var nth = -1, // make the first run go to index = 0 | ||
new_raw = result.raw.replace(/\[(\s|\_|\-|\x|\\?\*)?\]/ig, function(match) | ||
{ | ||
nth += 1; | ||
return nth === idx ? new_value : match; | ||
}); | ||
AjaxLib.ajax("/posts/" + postId, { type: "GET", cache: false }).then( | ||
function(result) { | ||
var nth = -1, // make the first run go to index = 0 | ||
new_raw = result.raw.replace(/\[(\s|\_|\-|\x|\\?\*)?\]/gi, function( | ||
match | ||
) { | ||
nth += 1; | ||
return nth === idx ? new_value : match; | ||
}); | ||
|
||
var props = { | ||
raw: new_raw, | ||
edit_reason: I18n.t("checklist.edit_reason"), | ||
}; | ||
var props = { | ||
raw: new_raw, | ||
edit_reason: I18n.t("checklist.edit_reason") | ||
}; | ||
|
||
if (TextLib.cookAsync) { | ||
TextLib.cookAsync(new_raw).then(cooked => { | ||
props.cooked = cooked.string; | ||
if (TextLib.cookAsync) { | ||
TextLib.cookAsync(new_raw).then(cooked => { | ||
props.cooked = cooked.string; | ||
viewPost.save(props); | ||
}); | ||
} else { | ||
props.cooked = TextLib.cook(new_raw).string; | ||
viewPost.save(props); | ||
}); | ||
} else { | ||
props.cooked = TextLib.cook(new_raw).string; | ||
viewPost.save(props); | ||
} | ||
} | ||
|
||
}); | ||
); | ||
}); | ||
}); | ||
|
||
// confirm the feature is enabled by showing the click-ability | ||
boxes.css({"cursor": "pointer"}); | ||
boxes.css({ cursor: "pointer" }); | ||
} | ||
|
||
export default { | ||
name: 'checklist', | ||
initialize: function() | ||
{ | ||
withPluginApi('0.1', api => initializePlugin(api)); | ||
name: "checklist", | ||
initialize: function() { | ||
withPluginApi("0.1", api => initializePlugin(api)); | ||
} | ||
}; |
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
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,3 +1,3 @@ | ||
span.chcklst-stroked { | ||
text-decoration: line-through; | ||
} | ||
} |