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