JavaScript 的 getSelection (获得页面的选中文字)
来源:互联网 发布:新sat 知乎 编辑:程序博客网 时间:2024/04/27 16:10
来自新浪前端的一段代码,研究了一些,写的有水平。读起来有点费劲,代码已经被压缩处理过了。
但是核心的部分还在,写的非常的好。
(function() { function B() { f.addEntry({ summary: "" }); m = f.entries.length - 1; for (var a = 0, c = "", b = '<div class="bslist">', d = 0; d < r.length; d++) { var e = r[d]; e == v ? (c += "#" + i + " .bslist .icon-" + e + '{background: url("' + w + 'more.gif") center center no-repeat;}', b += '<div class="listitem"><span onclick="javascript:bShare.more(event, ' + m + ');return false;" title="' + n.morePlatsShort + '" class="bsicon icon-' + e + '"></span>', b += "</div>", a++) : g.isUndefined(f.pnMap[e]) || (c += "#" + i + " .bslist .icon-" + e + '{background: url("' + w + e + '.gif") center center no-repeat;}', b += '<div class="listitem"><span onclick="javascript:document.getElementById(\'' + i + "').style.display='none';bShare.share(event,'" + e + "'," + m + ');return false;" title="' + n.shareText + " " + f.pnMap[e][0] + '" class="bsicon icon-' + e + '"></span>', b += "</div>", a++) } d = a * 36 + (g.isIe6 ? 2 : 0); e = 15 * (o.length + 1) + 16; a = "#" + i + " {position:absolute;background-color:#fff;*display:inline;zoom:1;display:inline-block;}"; a += ".b-drag {padding:2px 10px;border:1px solid #ff5c00;border-radius:8px;overflow:hidden;width:" + (d > e ? d: e) + "px;}"; a += ".b-drag-arrow {position:absolute;margin:-4px 40px;width:10px;height:5px;background:url(" + C + "arrow-orange-hollow.gif) no-repeat;}"; a += ".b-drag .bstitle {display:block;height:15px;*height:18px;font-size:12px;padding:2px;color:#333;background:#fff;border-bottom:1px solid #e9e9e9;overflow:hidden;}"; a += ".b-drag .bstitle span {float:left;}"; a += ".b-drag .bstitle .bsclose {cursor:pointer;float:right;font-family:Arial,\u5b8b\u4f53,sans-serif;font-weight:bold;width:15px;height:15px;text-align:center;}"; a += ".b-drag .bslist {height:40px;margin-top:5px;}"; a += ".b-drag .bslist .listitem {float:left;height:30px;width:34px;margin:0 1px;padding:5px 0 0;cursor:pointer;text-align:center;list-style:none;zoom:1;vertical-align:top;}"; a += ".b-drag .bslist .listitem:hover {border-radius:3px;background-color:#e9e9e9;}"; a += ".b-drag .bslist .bsicon {width:24px;height:24px;margin:0 auto;display:block;}"; a += c; c = '<span class="b-drag-arrow BSHARE_IMAGE_NO"></span><div class="b-drag"><div class="bstitle"><span>' + o + '...</span><a class="bsclose" title="' + n.closeHint + "\" onclick=\"var date = new Date(); date.setTime(date.getTime() + 1800000); document.cookie='bshare_off=true; expires='+date.toGMTString()+'; path=/'; document.getElementById('" + i + "').style.display='none'; return false;\">X</a></div>"; c += b; c += "</div></div>"; g.loadStyle(a); s && g.loadScript(s); var j = h.getElementById(i); j || (j = g.createElement("div", i, "", "display:none;", c), x.appendChild(j)); var l = function(a) { a.onmousedown = function(a) { p = t(a || k.event) }; a.onmouseup = function(a) { if (!D()) { a = a || k.event; q = t(a); if (!p || !q || p.left != q.left || p.top != q.top) u = !0; var b; if (k.getSelection) b = k.getSelection().toString(); else if (h.getSelection) b = h.getSelection(); else if (h.selection) try { b = h.selection.createRange().text } catch(c) {} if (b.length != 0 && u) { var y = t(a); setTimeout(function() { f.entries[m].summary = b; f.curb = m; j.style.top = y.top + 15 + "px"; j.style.left = y.left - 40 + "px"; j.style.display = "inline-block" }, 200); u = !1; g.stopProp(a) } } } }; g.getElem(h, "div", z, function(a) { l(a) }); g.getElem(h, "p", z, function(a) { l(a) }); x.onmouseup = function(a) { a = a || k.event; for (a = a.srcElement || a.target; a;) { if (a.id == i || a.id == E) return; a = a.parentNode } j.style.display = "none"; f.entries[m].summary = "" } } function D() { try { var a = h.cookie.split(";"), c, b, d = "false"; for (c = 0; c < a.length; c++) { for (b = a[c]; b.charAt(0) == " ";) b = b.slice(1, b.length); b.indexOf("bshare_off=") == 0 && (d = b.slice(11, b.length)) } if (d == "true") return ! 0 } catch(e) { return ! 0 } return ! 1 } function t(a) { return { left: a.pageX || a.clientX + l.scrollLeft - l.clientLeft, top: a.pageY || a.clientY + l.scrollTop - l.clientTop } } var A = !1, k = window, h = document, l = h.documentElement, x = h.body, g = k.bShareUtil, f = k.bShare, n = f.iL8n || {}, v = "more", C = f.shost + "/images/", w = f.imageBasePath + "logos/m2/", z = "BSHARE_POP", i = "b-drag-div", E = "bsMorePanelHolder", r = ["sinaminiblog", "qqmb", "neteasemb", "sohuminiblog", "renren", "kaixin001", v], s = null, u = !1, q, p, m, o; g.ready(function() { var a = function() { if (f.completed) { n = f.iL8n; o = n.shareText; var c = g.getScript(/((bshare|static).*bshareDrag?(Org)?\.js)/)[0], b = {}; if (!g.isUndefined(window.bShareOpt)) b = window.bShareOpt; if (c) { var c = g.parseOptions(c.src), d; for (d in c) b[d] = c[d] } if (b.text) o = b.text; b.bp && (r = b.bp.split(",")); if (b.popjs) s = b.popjs; B() } else setTimeout(a, 50) }; A || (A = !0, a()) })})();
0 0
- JavaScript 的 getSelection (获得页面的选中文字)
- getSelection 选中文字分享效果
- JavaScript获取页面上被选中的文字
- JavaScript获取页面上被选中文字的技巧
- JavaScript获得选中文本内容的方法
- 用JavaScript获取页面上被选中的文字的技巧
- 用JavaScript获取页面上被选中的文字的技巧
- 用JavaScript获取页面上被选中的文字的技巧
- 用JavaScript获取选中的文字
- getSelection和range的笔记
- JS获取页面里鼠标选中的文字
- 如何获取页面上鼠标选中的文字
- 在页面上屏蔽文字图片的选中功能
- js 取消页面可以选中文字的功能
- JavaScript 设置和获得Radio的选中值【转】
- JavaScript 获得页面区域大小的代码
- javascript获得页面各个部分的焦点
- JavaScript 获得页面区域大小的代码
- java 内部类
- 每日算法之十三:Longest Common Prefix
- openfire mongo ofuser表 批量插入删除脚本
- 有关UIView、subview的几个基础知识点-IOS开发 (实例)
- 微信公众平台关于fakeid和openid的解析
- JavaScript 的 getSelection (获得页面的选中文字)
- 创建sd卡目录和列出sd卡目录
- XIB同Class的关联
- android签名步骤
- Mac配置Python开发环境(Eclipse +Pydev+Python)
- php-fpm进程数优化方法
- ubuntu 14.04 在连接无线的情况下,进行宽带连接
- WEB安全色
- IOS-获取Model(设备型号)、Version(设备版本号)、app(程序版本号)等