FloatHelper
function FloatHelper() {
}
FloatHelper.prototype.showFloater = function (Target, Title, Action, ActionCallback, Callback, IsNeedTemplete) {
this.hideFloater();
var FloaterID = "Float_" + Title;
var Floater = $("#" + FloaterID);
if (Floater.length == 0) {
var newFloater = $("<div>");
newFloater.addClass("Absolute FloatDiv");
newFloater.attr("id", FloaterID);
Floater = newFloater;
if (IsNeedTemplete == undefined || IsNeedTemplete == null || IsNeedTemplete) {
var newDiv = $("<div>");
newDiv.addClass("Template_HoverHead");
var newSpan = $("<span>");
newSpan.addClass("title");
newSpan.html(Title);
newDiv.append(newSpan);
var newActionDiv = $("<div>");
newActionDiv.addClass("HoverHead_Buttons Right");
var newInput = $("<input>");
newInput.attr({
"type": "button",
"value": Action
});
if (ActionCallback != undefined && ActionCallback != null) {
newActionDiv.on("click", ActionCallback);
newFloater.css("cursor", "pointer").click(ActionCallback);
$("[data-name=" + Title + "]").css("cursor", "pointer").click(function (event) {
event.preventDefault ? event.preventDefault() : event.returnvalue = false;
ActionCallback();
});
}
newInput.addClass("Action");
newActionDiv.append(newInput);
newDiv.append(newActionDiv);
newFloater.append(newDiv);
}
$(doc.body).append(newFloater);
} else {
Floater.show();
}
var top, left, TargetTop, width;
if (Target != null) {
width = Target.width();
TargetTop = Target.offset().top;
top = Math.ceil(TargetTop - Floater.height());
left = Target.offset().left;
Floater.css({
"top": top + "px",
"left": left + "px",
"width": width + "px"
});
this.showOutLine(Title);
if (Callback != undefined && Callback != null) {
Callback();
}
}
};
FloatHelper.prototype.hideFloater = function (Callback) {
var FloatDiv = $(".FloatDiv");
if (FloatDiv.is(":visible")) {
FloatDiv.remove();
this.hideOutline();
if (Callback != undefined && Callback != null) {
Callback();
}
}
};
FloatHelper.prototype.resize = function (Callback) {
var FloatDiv = $(".FloatDiv:visible");
if (FloatDiv.length > 0) {
var name = FloatDiv.attr("id").replace("Float_", "");
var Target = $("[data-name = " + name + "]");
var width, top, left;
if (FloatDiv.is(":visible")) {
top = Target.offset().top;
left = Target.offset().left;
width = Target.width();
if (width < 180) {
width = 180;
}
FloatDiv.css({
"width": width,
"top": top,
"left": left
});
if (Callback != undefined && Callback != null) {
Callback();
}
}
}
};
FloatHelper.prototype.showOutLine = function (name) {
var target = $(".FloatDiv:visible");
var Floater;
if (target.length > 0) {
name = name || target.attr("id").replace("Float_", "");
var editableDiv = $("[data-name =" + name + " ]");
try {
this.hideOutline();
} catch (e) {
}
editableDiv.css("outline", "solid 6px #fdc666");
Floater = $("#Float_" + name);
var w = editableDiv.width() + 12 + Math.round(editableDiv.css("padding-left").match(/^[0-9]*/g)[0]) + Math.round(editableDiv.css("padding-right").match(/^[0-9]*/g)[0]);
if (w <= 180) {
w = 180;
editableDiv.css("width", w - 12);
editableDiv.find("ul").addClass("Right Less180");
} else {
editableDiv.find("ul.Right.Less180").removeClass("Right");
}
Floater.css({
"width": w,
"left": editableDiv.offset().left - 6,
"top": Math.ceil(editableDiv.offset().top - Floater.height())
});
if (name == "Background") {
Floater.css("top", editableDiv.offset().top);
}
}
};
FloatHelper.prototype.hideOutline = function () {
_.each($("[data-editable = True]"), function (item) {
if (item) {
$(item).css("outline", "none");
}
});
};
可视化建站这个项目中的Js,除了DialogHelper,其他的都是自己完成的,感觉自己真厉害啊,虽然写的不是那么完善,可能还会有各种bug,但是很高兴,自己终于完成了,赞自己一次。
下班回家喽!
FloatHelper的更多相关文章
随机推荐
- poj2279排队——杨氏矩阵与钩子公式(DP爆内存)
题目:http://poj.org/problem?id=2279 书上的DP做法会爆内存,尝试写了一个,过了样例. 转载: 代码如下: #include<iostream> #inclu ...
- 怎么在docker容器的mysql的编码格式变为utf8
第一个方法: 1. 编辑MySql的配置文件 MySql的配置文件Windows下一般在系统目录下或者在MySql的安装目录下名字叫my.ini,可以搜索,Linux下一般是/etc/my.cnf ...
- java 获取 HttpServletRequest 值 demo
private void getHttpServletRequestInfo(HttpServletRequest request){ try { StringBuilder stringBuilde ...
- jQuery contextMenu使用
地址:jQuery contextMenu 需要以下文件: jquery.contextMenu.css jquery.min.css jquery.contextMenu.js jquery.ui. ...
- LaTeX 语法
MathJax是什么? MathJax是一个开源JavaScript库.它支持LaTeX.MathML.AsciiMath符号,可以运行于所有流行浏览器上. LaTeX是什么? LaTeX(LATEX ...
- Listbox 实现Item双击事件
void listBox1_MouseDoubleClick(object sender, MouseEventArgs e) { int index = this.listBox1.IndexFro ...
- 洛谷P3434 [POI2006]KRA-The Disks
P3434 [POI2006]KRA-The Disks 题目描述 For his birthday present little Johnny has received from his paren ...
- 2014-10-28 NOIP模拟赛
Porble 1时间与空间之旅(tstrip.*) 题目描述 公元22××年,宇宙中最普遍的交通工具是spaceship.spaceship的出现使得星系之间的联系变得更为紧密,所以spaceship ...
- ZOJ3469 Food Delivery
Food Delivery ZOJ - 3469 题意:外卖送饭给N个顾客,要求他们不满度和最小,没人不满度=等待时间*耐心值 #include<cstring> #include< ...
- [Xcode 实际操作]六、媒体与动画-(16)实现音乐的背景播放
目录:[Swift]Xcode实际操作 本文将演示音乐的背景播放功能 打开项目信息配置文件[info.plist]. 需要在配置文件中进行一些操作,使程序支持音乐的背景播放. 点击鼠标右键,弹出右键菜 ...