手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >简略的前端架构心得&&基于editor为例子的编码小技巧
简略的前端架构心得&&基于editor为例子的编码小技巧
摘要:比较粗糙简略。感兴趣的同学可以看看。稍微贴下主要内容吧:这是第一份ppt主要的内容。具体东西我就不多贴了,对这几个方面感兴趣的同学可以下载来...

比较粗糙简略。感兴趣的同学可以看看。稍微贴下主要内容吧:

简略的前端架构心得&&基于editor为例子的编码小技巧1

这是第一份ppt主要的内容。具体东西我就不多贴了,对这几个方面感兴趣的同学可以下载来看看,既然是基于editor为例子的ppt,这里我也附上一个简单的利用execCommand命令做的简易的demo,editor的原理在demo里都能看出来。这里附上代码:

<!doctype html>

复制代码 代码如下:

<html>

<head>

<style type="text/css">

.wp {

width: 500px;

}

.bar {

margin-bottom: 8px;

}

.con {

border: 2px solid #ccc;

}

.block {

overflow: hidden;

height: 1%;

}

.controler {

float: left;

margin-right: 6px;

border: 1px solid #999;

height: 20px;

width: 20px;

text-align: center;

font-size: 14px;

font-weight: bold;

}

</style>

</head>

<body>

<script type="text/javascript">

var Class = {

create : function () {

return function () {

this.init.apply(this, arguments);

}

}

},

H$ = function(i) {return document.getElementById(i)},

$CE = function() {

var div = document.createElement('div');

return function(html) {

div.innerHTML = html;

var el = div.childNodes[0];

div.removeChild(el);

return el;

}

} ();

var Editor = Class.create();

Editor.prototype = {

init : function(id) {

var c = [];

c[0] = ['bold', 'B'];

c[1] = ['italic', 'I'];

this.t = H$(id);

this.t.style['display'] = 'none';

this.i = $CE('<iframe frameBorder="0" width="500" height="200"></iframe>');

var wp = $CE('<div></div>'),

bar = $CE('<div></div>'),

con = $CE('<div></div>'),

self = this;

for (var i=0; i<c.length; i++) {

var btn = $CE('<a>'+c[i][1]+'</a>');

bar.appendChild(btn);

btn.onclick = (function(i){

return function () {

self.action(c[i][0]);

}

})(i);

if (!+"v1") {btn.unselectable = 'on'} // IE下一定要设置unselectable = 'on'

}

this.t.parentNode.insertBefore(wp, this.t);

con.appendChild(this.t);

con.appendChild(this.i);

wp.appendChild(bar);

wp.appendChild(con);

this.e = this.i.contentWindow.document || this.i.contentDocument;

this.e.designMode = 'on';

this.e.open();

this.e.close();

},

action : function (cmd, val) {

this.e.execCommand(cmd, 0, val || null);

}

}

</script>

<textarea id="test"></textarea>

<script type="text/javascript">

new Editor('test');

</script>

</body>

</html>

大家可以自行考到本地去演示,很简单的一个例子,提供一个思路而已。

下面提供第一个ppt的下载: 【点击这里下载《关于js的一些小技巧》】

【阿里中国站前端架构史--略谈】

以下为ppt部分内容:

简略的前端架构心得&&基于editor为例子的编码小技巧2

简略的前端架构心得&&基于editor为例子的编码小技巧3

感兴趣的同学可以看看。

文件打包下载地址

【简略的前端架构心得&&基于editor为例子的编码小技巧】相关文章:

下拉菜单的简易制作

理解javascript定时器中的setTimeout与setInterval

js实现简单锁屏功能实例

JavaScript中Number.MIN_VALUE属性的使用示例

浅谈angularJS 作用域

详解AngularJS中的表格使用

游戏人文件夹程序 ver 3.0

原生js实现的贪吃蛇网页版游戏完整实例

onmousewheel event 缩放图片效果

超强图片数量上传无限制

精品推荐
分类导航