提交 722d72b0 编写于 作者: Z ztree

使用 scrollIntoViewIfNeeded 替代 scrollIntoView,兼容各种浏览器

上级 912d1b61
jQuery Tree Plugin ---- zTree
============
last verson : 3.5.25
last verson : 3.5.26
**Donate to zTree** : http://www.ztree.me/v3/donate.php
......
......@@ -35,7 +35,7 @@
<div class="ieSuggest">浏览本网站建议您使用 Chrome、FireFox、Opera、IE9 等浏览器(只要不是 IE6 7 8 就行), 速度会更快,画面会更炫!</div>
<div class="google_plus"><g:plusone></g:plusone></div>
<div class="header-text">
<h1><em>zTree v3.5.25 API 文档</em></h1><p></p>
<h1><em>zTree v3.5.26 API 文档</em></h1><p></p>
<p>all.js = core + excheck + exedit ( 不包括 exhide ); 发现错误请及时通知,谢谢。</p>
</div>
<ul class="shortcuts language" style="top:0;">
......
......@@ -34,7 +34,7 @@
<div class="ieSuggest">If you use the Chrome / FireFox / Opera / IE9 browser will be even more dazzling effect!</div>
<div class="google_plus"><g:plusone></g:plusone></div>
<div class="header-text">
<h1><em>zTree v3.5.25 API Document</em></h1><p></p>
<h1><em>zTree v3.5.26 API Document</em></h1><p></p>
<p>all.js = core + excheck + exedit ( without exhide ); if you found some mistakes please contact me.</p>
</div>
<ul class="shortcuts language" style="top:0;">
......
此差异已折叠。
/*
* JQuery zTree core v3.5.25
* JQuery zTree core v3.5.26
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -9,7 +9,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2016-09-27
* Date: 2016-11-03
*/
(function($){
var settings = {}, roots = {}, caches = {},
......@@ -1353,13 +1353,75 @@
if (!dom) {
return;
}
if (dom.scrollIntoViewIfNeeded) {
dom.scrollIntoViewIfNeeded();
} else if (dom.scrollIntoView) {
dom.scrollIntoView(false);
} else {
try{dom.focus().blur();}catch(e){}
// code src: http://jsfiddle.net/08u6cxwj/
if (!Element.prototype.scrollIntoViewIfNeeded) {
Element.prototype.scrollIntoViewIfNeeded = function (centerIfNeeded) {
function withinBounds(value, min, max, extent) {
if (false === centerIfNeeded || max <= value + extent && value <= min + extent) {
return Math.min(max, Math.max(min, value));
} else {
return (min + max) / 2;
}
}
function makeArea(left, top, width, height) {
return { "left": left, "top": top, "width": width, "height": height
, "right": left + width, "bottom": top + height
, "translate":
function (x, y) {
return makeArea(x + left, y + top, width, height);
}
, "relativeFromTo":
function (lhs, rhs) {
var newLeft = left, newTop = top;
lhs = lhs.offsetParent;
rhs = rhs.offsetParent;
if (lhs === rhs) {
return area;
}
for (; lhs; lhs = lhs.offsetParent) {
newLeft += lhs.offsetLeft + lhs.clientLeft;
newTop += lhs.offsetTop + lhs.clientTop;
}
for (; rhs; rhs = rhs.offsetParent) {
newLeft -= rhs.offsetLeft + rhs.clientLeft;
newTop -= rhs.offsetTop + rhs.clientTop;
}
return makeArea(newLeft, newTop, width, height);
}
};
}
var parent, elem = this, area = makeArea(
this.offsetLeft, this.offsetTop,
this.offsetWidth, this.offsetHeight);
while ((parent = elem.parentNode) instanceof HTMLElement) {
var clientLeft = parent.offsetLeft + parent.clientLeft;
var clientTop = parent.offsetTop + parent.clientTop;
// Make area relative to parent's client area.
area = area.
relativeFromTo(elem, parent).
translate(-clientLeft, -clientTop);
parent.scrollLeft = withinBounds(
parent.scrollLeft,
area.right - parent.clientWidth, area.left,
parent.clientWidth);
parent.scrollTop = withinBounds(
parent.scrollTop,
area.bottom - parent.clientHeight, area.top,
parent.clientHeight);
// Determine actual scroll amount by reading back scroll properties.
area = area.translate(clientLeft - parent.scrollLeft,
clientTop - parent.scrollTop);
elem = parent;
}
};
}
dom.scrollIntoViewIfNeeded();
},
setFirstNode: function(setting, parentNode) {
var childKey = setting.data.key.children, childLength = parentNode[childKey].length;
......@@ -1821,7 +1883,7 @@
consts = zt.consts;
})(jQuery);
/*
* JQuery zTree excheck v3.5.25
* JQuery zTree excheck v3.5.26
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -1830,7 +1892,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2016-09-27
* Date: 2016-11-03
*/
(function($){
//default consts of excheck
......@@ -2449,7 +2511,7 @@
}
})(jQuery);
/*
* JQuery zTree exedit v3.5.25
* JQuery zTree exedit v3.5.26
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -2458,7 +2520,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2016-09-27
* Date: 2016-11-03
*/
(function($){
//default consts of exedit
......
此差异已折叠。
/*
* JQuery zTree core v3.5.25
* JQuery zTree core v3.5.26
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2016-09-27
* Date: 2016-11-03
*/
(function($){
var settings = {}, roots = {}, caches = {},
......@@ -1352,13 +1352,75 @@
if (!dom) {
return;
}
if (dom.scrollIntoViewIfNeeded) {
dom.scrollIntoViewIfNeeded();
} else if (dom.scrollIntoView) {
dom.scrollIntoView(false);
} else {
try{dom.focus().blur();}catch(e){}
// code src: http://jsfiddle.net/08u6cxwj/
if (!Element.prototype.scrollIntoViewIfNeeded) {
Element.prototype.scrollIntoViewIfNeeded = function (centerIfNeeded) {
function withinBounds(value, min, max, extent) {
if (false === centerIfNeeded || max <= value + extent && value <= min + extent) {
return Math.min(max, Math.max(min, value));
} else {
return (min + max) / 2;
}
}
function makeArea(left, top, width, height) {
return { "left": left, "top": top, "width": width, "height": height
, "right": left + width, "bottom": top + height
, "translate":
function (x, y) {
return makeArea(x + left, y + top, width, height);
}
, "relativeFromTo":
function (lhs, rhs) {
var newLeft = left, newTop = top;
lhs = lhs.offsetParent;
rhs = rhs.offsetParent;
if (lhs === rhs) {
return area;
}
for (; lhs; lhs = lhs.offsetParent) {
newLeft += lhs.offsetLeft + lhs.clientLeft;
newTop += lhs.offsetTop + lhs.clientTop;
}
for (; rhs; rhs = rhs.offsetParent) {
newLeft -= rhs.offsetLeft + rhs.clientLeft;
newTop -= rhs.offsetTop + rhs.clientTop;
}
return makeArea(newLeft, newTop, width, height);
}
};
}
var parent, elem = this, area = makeArea(
this.offsetLeft, this.offsetTop,
this.offsetWidth, this.offsetHeight);
while ((parent = elem.parentNode) instanceof HTMLElement) {
var clientLeft = parent.offsetLeft + parent.clientLeft;
var clientTop = parent.offsetTop + parent.clientTop;
// Make area relative to parent's client area.
area = area.
relativeFromTo(elem, parent).
translate(-clientLeft, -clientTop);
parent.scrollLeft = withinBounds(
parent.scrollLeft,
area.right - parent.clientWidth, area.left,
parent.clientWidth);
parent.scrollTop = withinBounds(
parent.scrollTop,
area.bottom - parent.clientHeight, area.top,
parent.clientHeight);
// Determine actual scroll amount by reading back scroll properties.
area = area.translate(clientLeft - parent.scrollLeft,
clientTop - parent.scrollTop);
elem = parent;
}
};
}
dom.scrollIntoViewIfNeeded();
},
setFirstNode: function(setting, parentNode) {
var childKey = setting.data.key.children, childLength = parentNode[childKey].length;
......
此差异已折叠。
/*
* JQuery zTree excheck v3.5.25
* JQuery zTree excheck v3.5.26
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2016-09-27
* Date: 2016-11-03
*/
(function($){
//default consts of excheck
......
/*
* JQuery zTree excheck v3.5.25
* JQuery zTree excheck v3.5.26
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2016-09-27
* Date: 2016-11-03
*/
(function(m){var p,q,r,o={event:{CHECK:"ztree_check"},id:{CHECK:"_check"},checkbox:{STYLE:"checkbox",DEFAULT:"chk",DISABLED:"disable",FALSE:"false",TRUE:"true",FULL:"full",PART:"part",FOCUS:"focus"},radio:{STYLE:"radio",TYPE_ALL:"all",TYPE_LEVEL:"level"}},v={check:{enable:!1,autoCheckTrigger:!1,chkStyle:o.checkbox.STYLE,nocheckInherit:!1,chkDisabledInherit:!1,radioType:o.radio.TYPE_LEVEL,chkboxType:{Y:"ps",N:"ps"}},data:{key:{checked:"checked"}},callback:{beforeCheck:null,onCheck:null}};p=function(c,
a){if(a.chkDisabled===!0)return!1;var b=g.getSetting(c.data.treeId),d=b.data.key.checked;if(k.apply(b.callback.beforeCheck,[b.treeId,a],!0)==!1)return!0;a[d]=!a[d];e.checkNodeRelation(b,a);d=n(a,j.id.CHECK,b);e.setChkClass(b,d,a);e.repairParentChkClassWithSelf(b,a);b.treeObj.trigger(j.event.CHECK,[c,b.treeId,a]);return!0};q=function(c,a){if(a.chkDisabled===!0)return!1;var b=g.getSetting(c.data.treeId),d=n(a,j.id.CHECK,b);a.check_Focus=!0;e.setChkClass(b,d,a);return!0};r=function(c,a){if(a.chkDisabled===
......
/*
* JQuery zTree exedit v3.5.25
* JQuery zTree exedit v3.5.26
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2016-09-27
* Date: 2016-11-03
*/
(function($){
//default consts of exedit
......
/*
* JQuery zTree exedit v3.5.25
* JQuery zTree exedit v3.5.26
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2016-09-27
* Date: 2016-11-03
*/
(function(v){var J={event:{DRAG:"ztree_drag",DROP:"ztree_drop",RENAME:"ztree_rename",DRAGMOVE:"ztree_dragmove"},id:{EDIT:"_edit",INPUT:"_input",REMOVE:"_remove"},move:{TYPE_INNER:"inner",TYPE_PREV:"prev",TYPE_NEXT:"next"},node:{CURSELECTED_EDIT:"curSelectedNode_Edit",TMPTARGET_TREE:"tmpTargetzTree",TMPTARGET_NODE:"tmpTargetNode"}},x={onHoverOverNode:function(b,a){var c=m.getSetting(b.data.treeId),d=m.getRoot(c);if(d.curHoverNode!=a)x.onHoverOutNode(b);d.curHoverNode=a;f.addHoverDom(c,a)},onHoverOutNode:function(b){var b=
m.getSetting(b.data.treeId),a=m.getRoot(b);if(a.curHoverNode&&!m.isSelectedNode(b,a.curHoverNode))f.removeTreeDom(b,a.curHoverNode),a.curHoverNode=null},onMousedownNode:function(b,a){function c(b){if(B.dragFlag==0&&Math.abs(O-b.clientX)<e.edit.drag.minMoveSize&&Math.abs(P-b.clientY)<e.edit.drag.minMoveSize)return!0;var a,c,n,k,i;i=e.data.key.children;M.css("cursor","pointer");if(B.dragFlag==0){if(g.apply(e.callback.beforeDrag,[e.treeId,l],!0)==!1)return r(b),!0;for(a=0,c=l.length;a<c;a++){if(a==0)B.dragNodeShowBefore=
......
/*
* JQuery zTree exHideNodes v3.5.25
* JQuery zTree exHideNodes v3.5.26
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2016-09-27
* Date: 2016-11-03
*/
(function($){
//default init node of exLib
......
/*
* JQuery zTree exHideNodes v3.5.25
* JQuery zTree exHideNodes v3.5.26
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
......@@ -8,7 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: hunter.z@263.net
* Date: 2016-09-27
* Date: 2016-11-03
*/
(function(i){i.extend(!0,i.fn.zTree._z,{view:{clearOldFirstNode:function(c,a){for(var b=a.getNextNode();b;){if(b.isFirstNode){b.isFirstNode=!1;d.setNodeLineIcos(c,b);break}if(b.isLastNode)break;b=b.getNextNode()}},clearOldLastNode:function(c,a,b){for(a=a.getPreNode();a;){if(a.isLastNode){a.isLastNode=!1;b&&d.setNodeLineIcos(c,a);break}if(a.isFirstNode)break;a=a.getPreNode()}},makeDOMNodeMainBefore:function(c,a,b){c.push("<li ",b.isHidden?"style='display:none;' ":"","id='",b.tId,"' class='",l.className.LEVEL,
b.level,"' tabindex='0' hidefocus='true' treenode>")},showNode:function(c,a){a.isHidden=!1;f.initShowForExCheck(c,a);j(a,c).show()},showNodes:function(c,a,b){if(a&&a.length!=0){var e={},g,k;for(g=0,k=a.length;g<k;g++){var h=a[g];if(!e[h.parentTId]){var i=h.getParentNode();e[h.parentTId]=i===null?f.getRoot(c):h.getParentNode()}d.showNode(c,h,b)}for(var j in e)a=e[j][c.data.key.children],d.setFirstNodeForShow(c,a),d.setLastNodeForShow(c,a)}},hideNode:function(c,a){a.isHidden=!0;a.isFirstNode=!1;a.isLastNode=
......
......@@ -13,6 +13,9 @@
</font>
*2016.11.03* v3.5.26
* [修改] 使用 scrollIntoViewIfNeeded 替代 scrollIntoView,兼容各种浏览器
*2016.09.27* v3.5.25
* [修改] ajax 异步加载支持 contentType = 'application/json'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册