Skip to content

Commit

Permalink
implement wiki input icon
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-kimoto committed May 12, 2017
1 parent 0f2db5f commit 4a2121f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 74 deletions.
55 changes: 55 additions & 0 deletions public/js/icon-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function insertAtCaret(target, str) {
var obj = $(target);
obj.focus();
if(navigator.userAgent.match(/MSIE/)) {
var r = document.selection.createRange();
r.text = str;
r.select();
} else {
var s = obj.val();
var p = obj.get(0).selectionStart;
var np = p + str.length;
obj.val(s.substr(0, p) + str + s.substr(p));
obj.get(0).setSelectionRange(np, np);
}
}

function init_icon_input () {
// Comment icon
$('.icon-add-header-text').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "# ");
});
$('.icon-add-bold-text').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "****");
});
$('.icon-add-italic-text').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "__");
});
$('.icon-insert-quote').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "> ");
});
$('.icon-insert-code').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "``");
});
$('.icon-add-link').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "[](url)");
});
$('.icon-add-bulleted-list').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "- ");
});
$('.icon-add-numbered-list').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "1. ");
});
$('.icon-mension-user').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "@");
});
}
20 changes: 10 additions & 10 deletions templates/include/issue_comment_icon.html.ep
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<div class="issue-add-comment-icon">
<i class="issue-icon-add-header-text icon icon-font" title="Add header text"></i>
<i class="issue-icon-add-bold-text icon icon-bold" title="Add bold text"></i>
<i class="issue-icon-add-italic-text icon icon-italic" title="Add italic text"></i>
<i class="icon-add-header-text icon icon-font" title="Add header text"></i>
<i class="icon-add-bold-text icon icon-bold" title="Add bold text"></i>
<i class="icon-add-italic-text icon icon-italic" title="Add italic text"></i>
<span style="margin-left:10px"></span>
<i class="issue-icon-insert-quote icon icon-comment" title="Insert a quote"></i>
<i class="issue-icon-insert-code icon icon-file" title="Insert a code"></i>
<i class="issue-icon-add-link icon icon-map-marker" title="Add a link"></i>
<i class="icon-insert-quote icon icon-comment" title="Insert a quote"></i>
<i class="icon-insert-code icon icon-file" title="Insert a code"></i>
<i class="icon-add-link icon icon-map-marker" title="Add a link"></i>
<span style="margin-left:10px"></span>
<i class="issue-icon-add-bulleted-list icon icon-list" title="Add a bulleted list"></i>
<i class="issue-icon-add-numbered-list icon icon-th-list" title="Add a numbered list"></i>
<i class="icon-add-bulleted-list icon icon-list" title="Add a bulleted list"></i>
<i class="icon-add-numbered-list icon icon-th-list" title="Add a numbered list"></i>
<span style="margin-left:10px"></span>
<i class="issue-icon-mension-user icon icon-user" title="Directory mension a user"></i>
<i class="icon-mension-user icon icon-user" title="Directory mension a user"></i>
<!--
<i class="issue-icon-reference-issue icon icon-bookmark" title="Reference a issue or pull request"></i>
<i class="icon-reference-issue icon icon-bookmark" title="Reference a issue or pull request"></i>
-->
</div>
54 changes: 0 additions & 54 deletions templates/include/js/issue.html.ep
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
function insertAtCaret(target, str) {
var obj = $(target);
obj.focus();
if(navigator.userAgent.match(/MSIE/)) {
var r = document.selection.createRange();
r.text = str;
r.select();
} else {
var s = obj.val();
var p = obj.get(0).selectionStart;
var np = p + str.length;
obj.val(s.substr(0, p) + str + s.substr(p));
obj.get(0).setSelectionRange(np, np);
}
}

// Click write tab
$('.issue-message-write-tab').on('click', function () {
var form = $(this).closest('form');
Expand Down Expand Up @@ -99,41 +83,3 @@ $('.issue-message-update-btn').on('click', function () {

return false;
});

// Comment icon
$('.issue-icon-add-header-text').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "# ");
});
$('.issue-icon-add-bold-text').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "****");
});
$('.issue-icon-add-italic-text').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "__");
});
$('.issue-icon-insert-quote').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "> ");
});
$('.issue-icon-insert-code').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "``");
});
$('.issue-icon-add-link').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "[](url)");
});
$('.issue-icon-add-bulleted-list').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "- ");
});
$('.issue-icon-add-numbered-list').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "1. ");
});
$('.issue-icon-mension-user').on('click', function () {
var textarea = $(this).closest('form').find('textarea');
insertAtCaret(textarea, "@");
});
5 changes: 5 additions & 0 deletions templates/issue.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,15 @@
layout 'common', title => "Issue - $user_id/$project_id #$issue_number";
%>

%= javascript '/js/icon-input.js';

%= javascript begin
$(document).ready(function() {
%= include '/include/js/issue';

// Initialize icon input
init_icon_input();

// Click labels btn
$('.issue-labels-setting-btn').on('click', function () {
var popup = $('.issue-labels-popup');
Expand Down
26 changes: 16 additions & 10 deletions templates/wiki.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,14 @@
layout 'common', title => "Wiki - $user_id/$project_id";
%>

%= javascript '/js/icon-input.js';

%= javascript begin
$(document).ready(function () {

// Initialize icon input
init_icon_input();

// Repository URL buttons
var http_rep_url = '<%= url_for("$user/$project.wiki.git")->to_abs %>';

Expand Down Expand Up @@ -286,20 +292,20 @@
<div class="wiki-message-write-tab wiki-add-comment-header-tab"><a href="javascript:void(0)">Write</a></div>
<div class="wiki-message-preview-tab wiki-add-comment-header-tab"><a class="disable" href="javascript:void(0)">Preview</a></div>
<div class="wiki-add-comment-icon">
<i class="wiki-icon-add-header-text icon icon-font" title="Add header text"></i>
<i class="wiki-icon-add-bold-text icon icon-bold" title="Add bold text"></i>
<i class="wiki-icon-add-italic-text icon icon-italic" title="Add italic text"></i>
<i class="icon-add-header-text icon icon-font" title="Add header text"></i>
<i class="icon-add-bold-text icon icon-bold" title="Add bold text"></i>
<i class="icon-add-italic-text icon icon-italic" title="Add italic text"></i>
<span style="margin-left:10px"></span>
<i class="wiki-icon-insert-quote icon icon-comment" title="Insert a quote"></i>
<i class="wiki-icon-insert-code icon icon-file" title="Insert a code"></i>
<i class="wiki-icon-add-link icon icon-map-marker" title="Add a link"></i>
<i class="icon-insert-quote icon icon-comment" title="Insert a quote"></i>
<i class="icon-insert-code icon icon-file" title="Insert a code"></i>
<i class="icon-add-link icon icon-map-marker" title="Add a link"></i>
<span style="margin-left:10px"></span>
<i class="wiki-icon-add-bulleted-list icon icon-list" title="Add a bulleted list"></i>
<i class="wiki-icon-add-numbered-list icon icon-th-list" title="Add a numbered list"></i>
<i class="icon-add-bulleted-list icon icon-list" title="Add a bulleted list"></i>
<i class="icon-add-numbered-list icon icon-th-list" title="Add a numbered list"></i>
<span style="margin-left:10px"></span>
<i class="wiki-icon-mension-user icon icon-user" title="Directory mension a user"></i>
<i class="icon-mension-user icon icon-user" title="Directory mension a user"></i>
<!--
<i class="wiki-icon-reference-issue icon icon-bookmark" title="Reference a issue or pull request"></i>
<i class="icon-reference-issue icon icon-bookmark" title="Reference a issue or pull request"></i>
-->
</div>
</div>
Expand Down

0 comments on commit 4a2121f

Please sign in to comment.