Commit 1ab4ca37a76d3795fa248be526d430b268655412
1 parent
18a91101
insertNode
Showing
1 changed file
with
16 additions
and
6 deletions
editer.html
... | ... | @@ -70,6 +70,10 @@ |
70 | 70 | <script src="js/javascript/common/jquery.min.js"></script> |
71 | 71 | <script> |
72 | 72 | $(function() { |
73 | + var range; | |
74 | + $('.editer').on('click', function(){ | |
75 | + range = window.getSelection().getRangeAt(0);//找到焦点位置 | |
76 | + }); | |
73 | 77 | $('#upload_btn').on('change', function(target) { |
74 | 78 | target = $(this); |
75 | 79 | var input = target.get(0), |
... | ... | @@ -85,21 +89,21 @@ |
85 | 89 | var selected_file = input.files[0]; |
86 | 90 | |
87 | 91 | if (!selected_file.type.match(imageType)) { |
88 | - $.mobile.loading('hide'); | |
92 | + | |
89 | 93 | alert('文件格式不正确!'); |
90 | 94 | $(input).val(''); |
91 | 95 | return; |
92 | 96 | } |
93 | 97 | |
94 | 98 | if (!suffix.test(selected_file.name)) { |
95 | - $.mobile.loading('hide'); | |
99 | + | |
96 | 100 | alert('文件格式不正确!'); |
97 | 101 | $(input).val(''); |
98 | 102 | return; |
99 | 103 | } |
100 | 104 | |
101 | 105 | if (selected_file.size > 5000 * 1024) { |
102 | - $.mobile.loading('hide'); | |
106 | + | |
103 | 107 | alert('图片体积不能超过5MB!'); |
104 | 108 | $(input).val(''); |
105 | 109 | return; |
... | ... | @@ -110,8 +114,14 @@ |
110 | 114 | var base64 = e.target.result; |
111 | 115 | // _this.compressPic(selected_file ,base64); |
112 | 116 | var img = $('<img />'); |
113 | - img.attr('src', base64); | |
114 | - $('.editer').append(img); | |
117 | + var img = document.createElement('img'); | |
118 | + img.src = base64; | |
119 | + if(range){ | |
120 | + range.insertNode(img);//在焦点插入节点 | |
121 | + }else{ | |
122 | + $('.editer').append($(img)); | |
123 | + } | |
124 | + | |
115 | 125 | } |
116 | 126 | |
117 | 127 | reader.onerror = function(e) { |
... | ... | @@ -123,7 +133,7 @@ |
123 | 133 | // console.log(src); |
124 | 134 | // alert(src); |
125 | 135 | // if (src == null) { |
126 | - // $.mobile.loading('hide'); | |
136 | + // | |
127 | 137 | // Alert.show('您的浏览器暂不支持上传图片,请更换其它浏览器再试!'); |
128 | 138 | // return; |
129 | 139 | // } | ... | ... |