is utils improvement

This commit is contained in:
fuxiaohei 2014-09-25 21:52:58 +08:00
parent 089d934547
commit 7c30ae7002
6 changed files with 79 additions and 16 deletions

View file

@ -1,6 +1,7 @@
// @codekit-prepend "lib/jquery-1.11.1.min.js"
// @codekit-prepend "lib/lib.js"
// @codekit-prepend "lib/tabs.js"
// @codekit-prepend "utils/tabs.js"
// @codekit-prepend "utils/preview.js"
// @codekit-prepend "lib/jquery.tipsy.js"
var Gogs = {};
@ -290,6 +291,7 @@ function initCore() {
$(this).addClass('js-tab-nav-show');
$($(this).data('tab-target')).show();
}
e.preventDefault();
});
}
@ -643,7 +645,8 @@ $(document).ready(function () {
initInstall();
}
Tabs('#dashboard-sidebar-menu');
$('#dashboard-sidebar-menu').tabs();
$('#pull-issue-preview').markdown_preview(".issue-add-comment");
homepage();

File diff suppressed because one or more lines are too long

View file

@ -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);
}
});

View file

@ -1,7 +1,6 @@
/**
* Created by fuxiaohei on 14-6-26.
/*
js tabs and tabbed content plugin
*/
function Tabs(selector) {
function hide($nav) {
@ -24,7 +23,8 @@ function Tabs(selector) {
$($current.data("tab-target")).addClass("js-tab-show");
}
// bind nav click
$e.on("click", ".js-tab-nav", function () {
$e.on("click", ".js-tab-nav", function (e) {
e.preventDefault();
var $this = $(this);
// is showing, not change.
if ($this.hasClass("js-tab-nav-show")) {
@ -36,4 +36,10 @@ function Tabs(selector) {
});
console.log("init tabs @", selector)
}
}
}
$.fn.extend({
tabs: function () {
Tabs(this);
}
});