Commit dbc541f5 authored by antoor's avatar antoor

Adjust the display UI

调整显示UI
parent fb19312e
/* /*
* Context.js * Context.js
* Copyright Jacob Kelley * Copyright Jacob Kelley
* MIT License * MIT License
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
// 加载CSS // 加载CSS
// $('head').append('<link href="/js/libs/bmenu/bmenu.css" rel="stylesheet">'); // $('head').append('<link href="/js/libs/bmenu/bmenu.css" rel="stylesheet">');
var context = context || (function () { var context = context || (function () {
var options = { var options = {
fadeSpeed: 100, fadeSpeed: 100,
filter: function ($obj) { filter: function ($obj) {
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
}; };
function initialize(opts) { function initialize(opts) {
options = $.extend({}, options, opts); options = $.extend({}, options, opts);
$(document).on('click', 'html', function () { $(document).on('click', 'html', function () {
// $('._dropdown-context').fadeOut(options.fadeSpeed, function(){ // $('._dropdown-context').fadeOut(options.fadeSpeed, function(){
// $('._dropdown-context').css({display:''}).find('.drop-left').removeClass('drop-left'); // $('._dropdown-context').css({display:''}).find('.drop-left').removeClass('drop-left');
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
$sub.addClass('drop-left'); $sub.addClass('drop-left');
} }
}); });
} }
// 更新设置 // 更新设置
...@@ -120,16 +120,16 @@ ...@@ -120,16 +120,16 @@
} }
function addContext(selector, data, event) { function addContext(selector, data, event) {
var d = new Date(), var d = new Date(),
id = selector ? d.getTime() : 'none', id = selector ? d.getTime() : 'none',
$menu = buildMenu(data, id); $menu = buildMenu(data, id);
$('#dropdown-none').remove(); $('#dropdown-none').remove();
$('body').append($menu); $('body').append($menu);
function show(e) { function show(e) {
$('._dropdown-context:not(._dropdown-context-sub)').hide(); $('._dropdown-context:not(._dropdown-context-sub)').hide();
$dd = $('#dropdown-' + id); $dd = $('#dropdown-' + id);
if (typeof options.above == 'boolean' && options.above) { if (typeof options.above == 'boolean' && options.above) {
$dd.addClass('_dropdown-context-up').css({ $dd.addClass('_dropdown-context-up').css({
...@@ -140,8 +140,12 @@ ...@@ -140,8 +140,12 @@
$dd.removeClass('_dropdown-context-up'); $dd.removeClass('_dropdown-context-up');
var autoH = $dd.height() + 12; var autoH = $dd.height() + 12;
if ((e.pageY + autoH) > $('html').height()) { if ((e.pageY + autoH) > $('html').height()) {
// 这里修改一下,防止菜单栏过上导致无法选择
var _top = e.pageY - 20 - autoH;
_top = _top < 0 ? 0 : _top;
$dd.addClass('_dropdown-context-up').css({ $dd.addClass('_dropdown-context-up').css({
top: e.pageY - 20 - autoH, // top: e.pageY - 20 - autoH,
top: _top,
left: e.pageX - 13 left: e.pageX - 13
}).fadeIn(options.fadeSpeed); }).fadeIn(options.fadeSpeed);
} else { } else {
...@@ -162,7 +166,7 @@ ...@@ -162,7 +166,7 @@
show(event); show(event);
} }
} }
function destroyContext(selector) { function destroyContext(selector) {
$(document).off('contextmenu', selector).off('click', '.context-event'); $(document).off('contextmenu', selector).off('click', '.context-event');
} }
...@@ -173,7 +177,7 @@ ...@@ -173,7 +177,7 @@
$('._dropdown-context').css({display:''}).find('.drop-left').removeClass('drop-left'); $('._dropdown-context').css({display:''}).find('.drop-left').removeClass('drop-left');
}); });
} }
return { return {
init: initialize, init: initialize,
settings: updateOptions, settings: updateOptions,
...@@ -193,4 +197,4 @@ ...@@ -193,4 +197,4 @@
ret.destroy = context.destroy; ret.destroy = context.destroy;
// return ret; // return ret;
window.bmenu = ret; window.bmenu = ret;
})(); })();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment