From 2d5cfd6847a8d887e448a0498fcbe0c237b08bb3 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Wed, 8 Jul 2015 09:24:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=8B=E4=BB=B6=E7=BB=91?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/MDEditor.min.js | 29 +++++++++++++---------------- lib/MDEditor.js | 28 ++++++++++++---------------- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/build/MDEditor.min.js b/build/MDEditor.min.js index 5ade662..177aa2a 100644 --- a/build/MDEditor.min.js +++ b/build/MDEditor.min.js @@ -799,12 +799,15 @@ (function(window, undefined) { var _$ = document.querySelectorAll.bind(document); function addEvent(object, event, method) { - if (object.addEventListener) { - object.addEventListener(event, method, false); - } else if (object.attachEvent) { - object.attachEvent("on" + event, function() { - method(window.event); - }); + event = event.split(" "); + for (var i = 0; i < event.length; i++) { + if (object.addEventListener) { + object.addEventListener(event[i], method, false); + } else if (object.attachEvent) { + object.attachEvent("on" + event[i], function() { + method(window.event); + }); + } } } function _applyAttrs(context, attrs) { @@ -913,10 +916,10 @@ css(self.preview, { height: self.textarea.offsetHeight + "px" }); - valueChange = function(obj, event) { - if (obj.scrollHeight < self.opts.maxheight) { + addEvent(self.textarea, "input propertychange", function(event) { + if (this.scrollHeight < self.opts.maxheight) { css(self.textarea, { - height: obj.scrollHeight + "px", + height: this.scrollHeight + "px", overflow: "hidden" }); } else { @@ -928,14 +931,8 @@ css(self.preview, { height: self.textarea.offsetHeight + "px" }); - self.opts.value = obj.value; + self.opts.value = this.value; self.callback(event, self.opts); - }; - addEvent(self.textarea, "input", function(event) { - valueChange(this, event); - }); - addEvent(self.textarea, "propertychange", function(event) { - valueChange(this, event); }); return this; }; diff --git a/lib/MDEditor.js b/lib/MDEditor.js index 9b05468..5f13f38 100644 --- a/lib/MDEditor.js +++ b/lib/MDEditor.js @@ -9,10 +9,13 @@ * @param {[type]} method [执行函数] */ function addEvent(object, event, method) { - if (object.addEventListener){ - object.addEventListener(event, method, false); - }else if(object.attachEvent){ - object.attachEvent('on'+event, function(){ method(window.event); }); + event = event.split(' ') + for(var i = 0;i