{"id":337,"date":"2014-12-19T00:43:59","date_gmt":"2014-12-18T16:43:59","guid":{"rendered":"http:\/\/www.hightopo.com\/blog\/?p=337"},"modified":"2014-12-19T00:54:27","modified_gmt":"2014-12-18T16:54:27","slug":"%e5%9f%ba%e4%ba%8ehtml5%e7%9a%84drag-and-drop%e7%94%9f%e6%88%90%e5%9b%be%e7%89%87base64%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/www.hightopo.com\/blog\/337.html","title":{"rendered":"\u57fa\u4e8eHTML5\u7684Drag and Drop\u751f\u6210\u56fe\u7247Base64\u4fe1\u606f"},"content":{"rendered":"<p>HTML5\u7684Drag and Drop\u662f\u5f88\u4e0d\u9519\u7684\u529f\u80fd\uff0c\u7f51\u4e0a\u4f7f\u7528\u4f8b\u5b50\u8f83\u591a\u5982\u00a0<a href=\"http:\/\/html5demos.com\/drag\">http:\/\/html5demos.com\/drag<\/a>\u00a0\uff0c\u4f46\u8fd9\u4e9b\u4f8b\u5b50\u5927\u90e8\u5206\u6ca1\u5b9e\u9645\u7528\u9014\uff0c\u672c\u6587\u5c06\u641e\u4e2a\u6709\u70b9\u4f7f\u7528\u4ef7\u503c\u7684\u4f8b\u5b50\uff0c\u901a\u8fc7Drag and Drop\u751f\u6210\u56fe\u7247\u7684<a href=\"http:\/\/en.wikipedia.org\/wiki\/Base64\">Base64<\/a>\u7684\u5b57\u7b26\u4e32\u4fe1\u606f\u3002<\/p>\n<p>\u4f7f\u7528<a href=\"http:\/\/en.wikipedia.org\/wiki\/Base64\">Base64<\/a>\u65b9\u5f0f\u7684\u56fe\u7247\u6709\u8bf8\u591a\u597d\u5904\uff0c\u53ef\u5c06\u591a\u4e2a\u56fe\u7247\u4fe1\u606f\u6574\u5408\u5230\u5355\u4e2ajs\u6587\u4ef6\u907f\u514d\u591a\u6b21http\u8bf7\u6c42\uff0c\u53ef\u4ee5\u907f\u514dWebGL\u4f8b\u5b50\u8de8\u57df\u8bbf\u95ee\u7684\u5b89\u5168\u9650\u5236\u65e0\u6cd5\u672c\u5730\u6587\u4ef6\u8fd0\u884c\u7b49\u597d\u5904\uff0c\u5f53\u7136\u5f0a\u7aef\u4e5f\u4e0d\u5c11\u4f8b\u5982\u4e0d\u80fd\u6709\u6548\u5229\u7528\u6d4f\u89c8\u5668\u56fe\u7247\u7f13\u5b58\u673a\u5236\u7b49\u3002\u4f7f<a href=\"http:\/\/www.hightopo.com\/\">\u7528HT for Web<\/a>\u7684\u670b\u53cb\u4f1a\u53d1\u73b0<a href=\"http:\/\/www.hightopo.com\/\">HT<\/a>\u7684\u4f8b\u5b50\u5f88\u591a\u6ce8\u518c\u56fe\u7247\u90fd\u91c7\u7528Base64\u7684\u65b9\u5f0f\uff0c\u8fd9\u4e3b\u8981\u662f\u4e3a\u4e86\u65b9\u4fbf\u7528\u6237\u76f4\u63a5\u672c\u5730\u6587\u4ef6\u6253\u5f00<a href=\"http:\/\/www.hightopo.com\/\">HT<\/a>\u7684\u624b\u518c\u5373\u53ef\u64cd\u4f5c\u6d4f\u89c8\uff0c\u65e0\u9700\u6784\u5efaweb\u670d\u52a1\u5668\u53d1\u5e03\u8fdb\u884c\u8bbf\u95ee\uff0c\u7528\u6237\u5e38\u95ee\u7136\u540e\u5c06\u56fe\u7247\u8f6c\u51faBase64\u4fe1\u606f\uff0c\u6211\u4eec\u4f7f\u7528\u7684\u5c31\u662f\u672c\u6587\u4ecb\u7ecd\u7684\u5c0f\u5de5\u5177\u3002<\/p>\n<p><a href=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.49.18-PM.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-338\" alt=\"Screen Shot 2014-12-18 at 11.49.18 PM\" src=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.49.18-PM.png\" width=\"1010\" height=\"811\" srcset=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.49.18-PM.png 1010w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.49.18-PM-300x240.png 300w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.49.18-PM-200x160.png 200w\" sizes=\"(max-width: 1010px) 100vw, 1010px\" \/><\/a><\/p>\n<p>\u8be5\u5de5\u5177\u7531\u4e00\u4e2a\u5217\u8868\u3001\u4e00\u4e2a\u62d3\u6251\u56fe\u548c\u4e00\u4e2a\u6587\u672c\u6846\u4e09\u90e8\u5206\u7ec4\u6210\uff0c\u7528\u6237\u4efb\u610f\u62d6\u62fd\u672c\u5730\u591a\u56fe\u7247\u6587\u4ef6\u5230\u4efb\u610f\u9875\u9762\u90e8\u5206\uff0cHT\u81ea\u52a8\u5c06\u56fe\u7247\u4fe1\u606f\u751f\u6210\u5bf9\u5e94\u7684DataModel\u6570\u636e\u6a21\u578b\uff0c\u5217\u8868\u663e\u793a\u56fe\u7247\u6548\u679c\u3001\u540d\u79f0\u548c\u5bbd\u9ad8\u4fe1\u606f\uff0c\u62d3\u6251\u663e\u793a\u56fe\u7247\u3001\u4fee\u6539\u65f6\u95f4\u548c\u6587\u4ef6\u5927\u5c0f\u7b49\u4fe1\u606f\uff0c\u6587\u672c\u6846\u751f\u6210\u5bf9\u5e94\u6ce8\u518c\u5230htDefault.setImage\u51fd\u6570\u7684\u4ee3\u7801\u7247\u6bb5\uff0c\u7528\u6237\u76f4\u63a5\u53ef\u4ee5\u5c06\u6587\u672c\u6846\u5185\u7684\u4ee3\u7801\u62f7\u8d1d\u5230\u81ea\u5df1\u7684\u5de5\u7a0b\u7684js\u6587\u4ef6\u8fdb\u884c\u4f7f\u7528\u3002<\/p>\n<pre class=\"&quot;brush:javascript\u201d\">function init(){                                                                 \r\n\tdataModel = new ht.DataModel();                                                                             \r\n\tlistView = new ht.widget.ListView(dataModel); \r\n\tgraphView = new ht.graph.GraphView(dataModel);\r\n\tsplitView = new ht.widget.SplitView(listView, graphView);\r\n\ttextArea = new ht.widget.TextArea(); \r\n\ttextArea.getElement().style.wordWrap = 'normal';\r\n\ttextArea.getElement().style.color = '#777';\r\n\ttextArea.setEditable(false);\r\n\tnew ht.widget.SplitView(splitView, textArea, 'v').addToDOM();    \r\n\tnew ht.layout.ForceLayout(graphView).start();                            \r\n\tlistView.setRowHeight(50);   \r\n\tlistView.drawRowBackground = function(g, data, selected, x, y, width, height){\r\n\t\tif(this.isSelected(data)){\r\n\t\t\tg.fillStyle = '#87A6CB';\r\n\t\t}\r\n\t\telse if(this.getRowIndex(data) % 2 === 0){\r\n\t\t\tg.fillStyle = '#F1F4F7';\r\n\t\t}\r\n\t\telse{\r\n\t\t\tg.fillStyle = '#FAFAFA';\r\n\t\t}\r\n\t\tg.beginPath();\r\n\t\tg.rect(x, y, width, height);\r\n\t\tg.fill();\r\n\t};\r\n\r\n\tht.Default.setImage('icon', {\r\n\t\twidth: 50,\r\n\t\theight: 50,\r\n\t\tclip: function(g, width, height) {   \r\n\t\t\tg.beginPath();\r\n\t\t\tg.arc(width\/2, height\/2, Math.min(width, height)\/2-3, 0, Math.PI * 2, true);\r\n\t\t\tg.clip();                        \r\n\t\t},\r\n\t\tcomps: [\r\n\t\t\t{\r\n\t\t\t\ttype: 'image',\r\n\t\t\t\tstretch: 'uniform',\r\n\t\t\t\trect: [0, 0, 50, 50],\r\n\t\t\t\tname: {func: 'getImage'}\r\n\t\t\t}\r\n\t\t]\r\n\t});\r\n\tlistView.setIndent(60);  \r\n\tlistView.setVisibleFunc(function(data){\r\n\t\treturn data instanceof ht.Node;\r\n\t});\r\n\tlistView.getIcon = function(data){\r\n\t\treturn 'icon';\r\n\t};                                  \r\n\tlistView.getLabel = function(data){\r\n\t\tvar name = data.getName(name);\r\n\t\tvar image = ht.Default.getImage(name);\r\n\t\tif(image){\r\n\t\t\tname += ' ( ' + image.width + ' X ' + image.height + ' )';\r\n\t\t}\r\n\t\treturn name;\r\n\t};\r\n\twindow.addEventListener(\"dragenter\", dragEnter, false);\r\n\twindow.addEventListener(\"dragexit\", dragExit, false);\r\n\twindow.addEventListener(\"dragover\", dragOver, false);\r\n\twindow.addEventListener(\"drop\", drop, false);                                             \r\n}\r\n\r\nfunction dragEnter(evt) {\r\n\tevt.stopPropagation();\r\n\tevt.preventDefault();\r\n}\r\n\r\nfunction dragExit(evt) {\r\n\tevt.stopPropagation();\r\n\tevt.preventDefault();\r\n}\r\n\r\nfunction dragOver(evt) {\r\n\tevt.stopPropagation();\r\n\tevt.preventDefault();\r\n}\r\n\r\nfunction drop(evt) {\r\n\tevt.stopPropagation();\r\n\tevt.preventDefault();\r\n\r\n\tdataModel.clear();\r\n\ttextArea.setText(\"\");\r\n\tlastNode = null;                \r\n\r\n\tvar files = evt.dataTransfer.files;\r\n\tvar count = files.length;                \r\n\tfor (var i = 0; i &lt; count; i++) {\r\n\t\tvar file = files[i];\r\n\t\tvar reader = new FileReader();\r\n\t\treader.onloadend = handleReaderLoadEnd;\r\n\t\treader.file = file;\r\n\t\treader.readAsDataURL(file);\r\n\t}\r\n}\r\n\r\nfunction handleReaderLoadEnd(evt) {\r\n\tvar reader = evt.target;  \r\n\tvar file = reader.file;\r\n\tvar name = file.name;\r\n\tname = name.substr(0, name.length - 4);\r\n\tvar text = \"ht.Default.setImage('\" + name + \"', '\" + reader.result + \"');\\n\";\r\n\ttextArea.setText(textArea.getText() + text);                 \r\n\tht.Default.setImage(name, reader.result); \r\n\r\n\tvar note = 'Date: ' + file.lastModifiedDate.toLocaleString() + '\\n'\r\n\t\t\t+ 'Name: ' + file.name + '\\n'\r\n\t\t\t+ 'Size: ' + file.size + '\\n'\r\n\t\t\t+ 'Type: ' + file.type;\r\n\r\n\tvar node = new ht.Node();\r\n\tnode.setName(name);\r\n\tnode.setImage(name);\r\n\tnode.s({\r\n\t\t'note': note,\r\n\t\t'note.position': 3\r\n\t});\r\n\tdataModel.add(node);\r\n\r\n\tif(lastNode){\r\n\t\tvar edge = new ht.Edge(lastNode, node);\r\n\t\tdataModel.add(edge);                    \r\n\t}\r\n\tlastNode = node;                \r\n}<\/pre>\n<p>\u8be5\u4ee3\u7801\u4e3b\u8981\u5bf9window\u6dfb\u52a0\u4e86dragenter\u3001dragexit\u3001dragover\u548cdrop\u7684\u62d6\u62fd\u5904\u7406\uff0c\u5927\u90e8\u5206\u90fd\u662f\u901a\u8fc7e.stopPropagation();\u548cevt.preventDefault();\u963b\u6b62\u9ed8\u8ba4\u884c\u4e3a\uff0c\u6211\u4eec\u4ec5\u9700\u5728\u6700\u540e\u7684drop\u4e8b\u4ef6\u4e2d\u901a\u8fc7e.dataTransfer.files\u5f97\u5230\u6240\u6709\u5f53\u524d\u62d6\u62fd\u6587\u4ef6\u4fe1\u606f\uff0c\u6784\u5efaFileReader\u8fdb\u884c\u52a0\u8f7d\uff0c\u7136\u540e\u5bf9\u52a0\u8f7d\u7684\u4fe1\u606f\u6784\u5efa\u5bf9\u5e94DataModel\u4e2d\u7684ht.Node\u5bf9\u8c61\u548c\u5c5e\u6027\u5c31\u5b8c\u4e8b\u4e86\u3002<\/p>\n<p>\u6700\u540e\u4ee3\u7801\u4e2d\u8fd8\u6709\u51e0\u5904\u4f7f<a href=\"http:\/\/www.hightopo.com\/\">\u7528HT for Web<\/a>\u7684\u6280\u672f\u7ec6\u8282\u503c\u5f97\u63d0\u5230\uff0c\u5de6\u4fa7list\u5217\u8868\u901a\u8fc7\u81ea\u5b9a\u4e49\u77e2\u91cf\u56fe\u6807\uff0c\u5e76\u4e14\u5728\u5b9a\u4e49\u77e2\u91cf\u65f6\u91c7\u7528\u4e86clip\u7684\u529f\u80fd\uff0c\u8fd9\u6837\u5217\u8868\u7684\u56fe\u6807\u5c31\u4f1a\u663e\u793a\u6210clip\u88c1\u526a\u540e\u7684\u5706\u5f62\u6548\u679c\u3002\u91cd\u8f7d\u4e86listView.drawRowBackground\u51fd\u6570\uff0c\u5b9e\u73b0\u9694\u884c\u53d8\u8272\u7684\u5217\u8868\u6548\u679c\u3002\u91cd\u8f7d\u4e86listView.getLabel\u663e\u793a\u4e86\u66f4\u591a\u7684\u52a8\u6001\u6587\u672c\u4fe1\u606f\u3002\u901a\u8fc7listView.setVisibleFunc\u8fc7\u6ee4\u4e0d\u663e\u793a\u8fde\u7ebf\u4fe1\u606f\u5728\u5217\u8868\u4e2d\u3002<\/p>\n<p>\u4ee5\u4e0b\u4e3a\u8be5Base64\u8f6c\u6362\u5de5\u5177\u7684\u64cd\u4f5c\u6548\u679c\u89c6\u9891\u548c\u6293\u56fe\u4f9b\u53c2\u8003\uff1a<a href=\"http:\/\/v.youku.com\/v_show\/id_XODUxNzY3OTA4.html\">http:\/\/v.youku.com\/v_show\/id_XODUxNzY3OTA4.html<\/a><br \/>\n<iframe loading=\"lazy\" src=\"http:\/\/player.youku.com\/embed\/XODUxNzY3OTA4\" height=\"498\" width=\"510\" allowfullscreen=\"\" frameborder=\"0\"><\/iframe><br \/>\n<a href=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.43.41-PM.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-339\" alt=\"Screen Shot 2014-12-18 at 11.43.41 PM\" src=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.43.41-PM.png\" width=\"842\" height=\"773\" srcset=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.43.41-PM.png 842w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.43.41-PM-300x275.png 300w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.43.41-PM-200x183.png 200w\" sizes=\"(max-width: 842px) 100vw, 842px\" \/><\/a><a href=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.51.27-PM.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-340\" alt=\"Screen Shot 2014-12-18 at 11.51.27 PM\" src=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.51.27-PM.png\" width=\"1008\" height=\"798\" srcset=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.51.27-PM.png 1008w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.51.27-PM-300x237.png 300w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.51.27-PM-200x158.png 200w\" sizes=\"(max-width: 1008px) 100vw, 1008px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTML5\u7684Drag and Drop\u662f\u5f88\u4e0d\u9519\u7684\u529f\u80fd\uff0c\u7f51\u4e0a\u4f7f\u7528\u4f8b\u5b50\u8f83\u591a\u5982\u00a0<a href=\"http:\/\/html5demos.com\/drag\">http:\/\/html5demos.com\/drag<\/a>\u00a0\uff0c\u4f46\u8fd9\u4e9b\u4f8b\u5b50\u5927\u90e8\u5206\u6ca1\u5b9e\u9645\u7528\u9014\uff0c\u672c\u6587\u5c06\u641e\u4e2a\u6709\u70b9\u4f7f\u7528\u4ef7\u503c\u7684\u4f8b\u5b50\uff0c\u901a\u8fc7Drag and Drop\u751f\u6210\u56fe\u7247\u7684<a href=\"http:\/\/en.wikipedia.org\/wiki\/Base64\">Base64<\/a>\u7684\u5b57\u7b26\u4e32\u4fe1\u606f\u3002<\/p>\n<p>\u4f7f\u7528<a href=\"http:\/\/en.wikipedia.org\/wiki\/Base64\">Base64<\/a>\u65b9\u5f0f\u7684\u56fe\u7247\u6709\u8bf8\u591a\u597d\u5904\uff0c\u53ef\u5c06\u591a\u4e2a\u56fe\u7247\u4fe1\u606f\u6574\u5408\u5230\u5355\u4e2ajs\u6587\u4ef6\u907f\u514d\u591a\u6b21http\u8bf7\u6c42\uff0c\u53ef\u4ee5\u907f\u514dWebGL\u4f8b\u5b50\u8de8\u57df\u8bbf\u95ee\u7684\u5b89\u5168\u9650\u5236\u65e0\u6cd5\u672c\u5730\u6587\u4ef6\u8fd0\u884c\u7b49\u597d\u5904\uff0c\u5f53\u7136\u5f0a\u7aef\u4e5f\u4e0d\u5c11\u4f8b\u5982\u4e0d\u80fd\u6709\u6548\u5229\u7528\u6d4f\u89c8\u5668\u56fe\u7247\u7f13\u5b58\u673a\u5236\u7b49\u3002\u4f7f<a href=\"http:\/\/www.hightopo.com\/\">\u7528HT for Web<\/a>\u7684\u670b\u53cb\u4f1a\u53d1\u73b0<a href=\"http:\/\/www.hightopo.com\/\">HT<\/a>\u7684\u4f8b\u5b50\u5f88\u591a\u6ce8\u518c\u56fe\u7247\u90fd\u91c7\u7528Base64\u7684\u65b9\u5f0f\uff0c\u8fd9\u4e3b\u8981\u662f\u4e3a\u4e86\u65b9\u4fbf\u7528\u6237\u76f4\u63a5\u672c\u5730\u6587\u4ef6\u6253\u5f00<a href=\"http:\/\/www.hightopo.com\/\">HT<\/a>\u7684\u624b\u518c\u5373\u53ef\u64cd\u4f5c\u6d4f\u89c8\uff0c\u65e0\u9700\u6784\u5efaweb\u670d\u52a1\u5668\u53d1\u5e03\u8fdb\u884c\u8bbf\u95ee\uff0c\u7528\u6237\u5e38\u95ee\u7136\u540e\u5c06\u56fe\u7247\u8f6c\u51faBase64\u4fe1\u606f\uff0c\u6211\u4eec\u4f7f\u7528\u7684\u5c31\u662f\u672c\u6587\u4ecb\u7ecd\u7684\u5c0f\u5de5\u5177\u3002<\/p>\n<p><a href=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.49.18-PM.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-338\" alt=\"Screen Shot 2014-12-18 at 11.49.18 PM\" src=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.49.18-PM.png\" width=\"1010\" height=\"811\" srcset=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.49.18-PM.png 1010w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.49.18-PM-300x240.png 300w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.49.18-PM-200x160.png 200w\" sizes=\"(max-width: 1010px) 100vw, 1010px\" \/><\/a><\/p>\n<p>\u8be5\u5de5\u5177\u7531\u4e00\u4e2a\u5217\u8868\u3001\u4e00\u4e2a\u62d3\u6251\u56fe\u548c\u4e00\u4e2a\u6587\u672c\u6846\u4e09\u90e8\u5206\u7ec4\u6210\uff0c\u7528\u6237\u4efb\u610f\u62d6\u62fd\u672c\u5730\u591a\u56fe\u7247\u6587\u4ef6\u5230\u4efb\u610f\u9875\u9762\u90e8\u5206\uff0cHT\u81ea\u52a8\u5c06\u56fe\u7247\u4fe1\u606f\u751f\u6210\u5bf9\u5e94\u7684DataModel\u6570\u636e\u6a21\u578b\uff0c\u5217\u8868\u663e\u793a\u56fe\u7247\u6548\u679c\u3001\u540d\u79f0\u548c\u5bbd\u9ad8\u4fe1\u606f\uff0c\u62d3\u6251\u663e\u793a\u56fe\u7247\u3001\u4fee\u6539\u65f6\u95f4\u548c\u6587\u4ef6\u5927\u5c0f\u7b49\u4fe1\u606f\uff0c\u6587\u672c\u6846\u751f\u6210\u5bf9\u5e94\u6ce8\u518c\u5230htDefault.setImage\u51fd\u6570\u7684\u4ee3\u7801\u7247\u6bb5\uff0c\u7528\u6237\u76f4\u63a5\u53ef\u4ee5\u5c06\u6587\u672c\u6846\u5185\u7684\u4ee3\u7801\u62f7\u8d1d\u5230\u81ea\u5df1\u7684\u5de5\u7a0b\u7684js\u6587\u4ef6\u8fdb\u884c\u4f7f\u7528\u3002<\/p>\n<pre class=\"&quot;brush:javascript\u201d\">function init(){                                                                 \r\n\tdataModel = new ht.DataModel();                                                                             \r\n\tlistView = new ht.widget.ListView(dataModel); \r\n\tgraphView = new ht.graph.GraphView(dataModel);\r\n\tsplitView = new ht.widget.SplitView(listView, graphView);\r\n\ttextArea = new ht.widget.TextArea(); \r\n\ttextArea.getElement().style.wordWrap = 'normal';\r\n\ttextArea.getElement().style.color = '#777';\r\n\ttextArea.setEditable(false);\r\n\tnew ht.widget.SplitView(splitView, textArea, 'v').addToDOM();    \r\n\tnew ht.layout.ForceLayout(graphView).start();                            \r\n\tlistView.setRowHeight(50);   \r\n\tlistView.drawRowBackground = function(g, data, selected, x, y, width, height){\r\n\t\tif(this.isSelected(data)){\r\n\t\t\tg.fillStyle = '#87A6CB';\r\n\t\t}\r\n\t\telse if(this.getRowIndex(data) % 2 === 0){\r\n\t\t\tg.fillStyle = '#F1F4F7';\r\n\t\t}\r\n\t\telse{\r\n\t\t\tg.fillStyle = '#FAFAFA';\r\n\t\t}\r\n\t\tg.beginPath();\r\n\t\tg.rect(x, y, width, height);\r\n\t\tg.fill();\r\n\t};\r\n\r\n\tht.Default.setImage('icon', {\r\n\t\twidth: 50,\r\n\t\theight: 50,\r\n\t\tclip: function(g, width, height) {   \r\n\t\t\tg.beginPath();\r\n\t\t\tg.arc(width\/2, height\/2, Math.min(width, height)\/2-3, 0, Math.PI * 2, true);\r\n\t\t\tg.clip();                        \r\n\t\t},\r\n\t\tcomps: [\r\n\t\t\t{\r\n\t\t\t\ttype: 'image',\r\n\t\t\t\tstretch: 'uniform',\r\n\t\t\t\trect: [0, 0, 50, 50],\r\n\t\t\t\tname: {func: 'getImage'}\r\n\t\t\t}\r\n\t\t]\r\n\t});\r\n\tlistView.setIndent(60);  \r\n\tlistView.setVisibleFunc(function(data){\r\n\t\treturn data instanceof ht.Node;\r\n\t});\r\n\tlistView.getIcon = function(data){\r\n\t\treturn 'icon';\r\n\t};                                  \r\n\tlistView.getLabel = function(data){\r\n\t\tvar name = data.getName(name);\r\n\t\tvar image = ht.Default.getImage(name);\r\n\t\tif(image){\r\n\t\t\tname += ' ( ' + image.width + ' X ' + image.height + ' )';\r\n\t\t}\r\n\t\treturn name;\r\n\t};\r\n\twindow.addEventListener(\"dragenter\", dragEnter, false);\r\n\twindow.addEventListener(\"dragexit\", dragExit, false);\r\n\twindow.addEventListener(\"dragover\", dragOver, false);\r\n\twindow.addEventListener(\"drop\", drop, false);                                             \r\n}\r\n\r\nfunction dragEnter(evt) {\r\n\tevt.stopPropagation();\r\n\tevt.preventDefault();\r\n}\r\n\r\nfunction dragExit(evt) {\r\n\tevt.stopPropagation();\r\n\tevt.preventDefault();\r\n}\r\n\r\nfunction dragOver(evt) {\r\n\tevt.stopPropagation();\r\n\tevt.preventDefault();\r\n}\r\n\r\nfunction drop(evt) {\r\n\tevt.stopPropagation();\r\n\tevt.preventDefault();\r\n\r\n\tdataModel.clear();\r\n\ttextArea.setText(\"\");\r\n\tlastNode = null;                \r\n\r\n\tvar files = evt.dataTransfer.files;\r\n\tvar count = files.length;                \r\n\tfor (var i = 0; i &lt; count; i++) {\r\n\t\tvar file = files[i];\r\n\t\tvar reader = new FileReader();\r\n\t\treader.onloadend = handleReaderLoadEnd;\r\n\t\treader.file = file;\r\n\t\treader.readAsDataURL(file);\r\n\t}\r\n}\r\n\r\nfunction handleReaderLoadEnd(evt) {\r\n\tvar reader = evt.target;  \r\n\tvar file = reader.file;\r\n\tvar name = file.name;\r\n\tname = name.substr(0, name.length - 4);\r\n\tvar text = \"ht.Default.setImage('\" + name + \"', '\" + reader.result + \"');\\n\";\r\n\ttextArea.setText(textArea.getText() + text);                 \r\n\tht.Default.setImage(name, reader.result); \r\n\r\n\tvar note = 'Date: ' + file.lastModifiedDate.toLocaleString() + '\\n'\r\n\t\t\t+ 'Name: ' + file.name + '\\n'\r\n\t\t\t+ 'Size: ' + file.size + '\\n'\r\n\t\t\t+ 'Type: ' + file.type;\r\n\r\n\tvar node = new ht.Node();\r\n\tnode.setName(name);\r\n\tnode.setImage(name);\r\n\tnode.s({\r\n\t\t'note': note,\r\n\t\t'note.position': 3\r\n\t});\r\n\tdataModel.add(node);\r\n\r\n\tif(lastNode){\r\n\t\tvar edge = new ht.Edge(lastNode, node);\r\n\t\tdataModel.add(edge);                    \r\n\t}\r\n\tlastNode = node;                \r\n}<\/pre>\n<p>\u8be5\u4ee3\u7801\u4e3b\u8981\u5bf9window\u6dfb\u52a0\u4e86dragenter\u3001dragexit\u3001dragover\u548cdrop\u7684\u62d6\u62fd\u5904\u7406\uff0c\u5927\u90e8\u5206\u90fd\u662f\u901a\u8fc7e.stopPropagation();\u548cevt.preventDefault();\u963b\u6b62\u9ed8\u8ba4\u884c\u4e3a\uff0c\u6211\u4eec\u4ec5\u9700\u5728\u6700\u540e\u7684drop\u4e8b\u4ef6\u4e2d\u901a\u8fc7e.dataTransfer.files\u5f97\u5230\u6240\u6709\u5f53\u524d\u62d6\u62fd\u6587\u4ef6\u4fe1\u606f\uff0c\u6784\u5efaFileReader\u8fdb\u884c\u52a0\u8f7d\uff0c\u7136\u540e\u5bf9\u52a0\u8f7d\u7684\u4fe1\u606f\u6784\u5efa\u5bf9\u5e94DataModel\u4e2d\u7684ht.Node\u5bf9\u8c61\u548c\u5c5e\u6027\u5c31\u5b8c\u4e8b\u4e86\u3002<\/p>\n<p>\u6700\u540e\u4ee3\u7801\u4e2d\u8fd8\u6709\u51e0\u5904\u4f7f<a href=\"http:\/\/www.hightopo.com\/\">\u7528HT for Web<\/a>\u7684\u6280\u672f\u7ec6\u8282\u503c\u5f97\u63d0\u5230\uff0c\u5de6\u4fa7list\u5217\u8868\u901a\u8fc7\u81ea\u5b9a\u4e49\u77e2\u91cf\u56fe\u6807\uff0c\u5e76\u4e14\u5728\u5b9a\u4e49\u77e2\u91cf\u65f6\u91c7\u7528\u4e86clip\u7684\u529f\u80fd\uff0c\u8fd9\u6837\u5217\u8868\u7684\u56fe\u6807\u5c31\u4f1a\u663e\u793a\u6210clip\u88c1\u526a\u540e\u7684\u5706\u5f62\u6548\u679c\u3002\u91cd\u8f7d\u4e86listView.drawRowBackground\u51fd\u6570\uff0c\u5b9e\u73b0\u9694\u884c\u53d8\u8272\u7684\u5217\u8868\u6548\u679c\u3002\u91cd\u8f7d\u4e86listView.getLabel\u663e\u793a\u4e86\u66f4\u591a\u7684\u52a8\u6001\u6587\u672c\u4fe1\u606f\u3002\u901a\u8fc7listView.setVisibleFunc\u8fc7\u6ee4\u4e0d\u663e\u793a\u8fde\u7ebf\u4fe1\u606f\u5728\u5217\u8868\u4e2d\u3002<\/p>\n<p>\u4ee5\u4e0b\u4e3a\u8be5Base64\u8f6c\u6362\u5de5\u5177\u7684\u64cd\u4f5c\u6548\u679c\u89c6\u9891\u548c\u6293\u56fe\u4f9b\u53c2\u8003\uff1a<a href=\"http:\/\/v.youku.com\/v_show\/id_XODUxNzY3OTA4.html\">http:\/\/v.youku.com\/v_show\/id_XODUxNzY3OTA4.html<\/a><br \/>\n<iframe loading=\"lazy\" src=\"http:\/\/player.youku.com\/embed\/XODUxNzY3OTA4\" height=\"498\" width=\"510\" allowfullscreen=\"\" frameborder=\"0\"><\/iframe><br \/>\n<a href=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.43.41-PM.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-339\" alt=\"Screen Shot 2014-12-18 at 11.43.41 PM\" src=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.43.41-PM.png\" width=\"842\" height=\"773\" srcset=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.43.41-PM.png 842w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.43.41-PM-300x275.png 300w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.43.41-PM-200x183.png 200w\" sizes=\"(max-width: 842px) 100vw, 842px\" \/><\/a><a href=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.51.27-PM.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-340\" alt=\"Screen Shot 2014-12-18 at 11.51.27 PM\" src=\"http:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.51.27-PM.png\" width=\"1008\" height=\"798\" srcset=\"https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.51.27-PM.png 1008w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.51.27-PM-300x237.png 300w, https:\/\/www.hightopo.com\/blog\/wp-content\/uploads\/2014\/12\/Screen-Shot-2014-12-18-at-11.51.27-PM-200x158.png 200w\" sizes=\"(max-width: 1008px) 100vw, 1008px\" \/><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts\/337"}],"collection":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/comments?post=337"}],"version-history":[{"count":3,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts\/337\/revisions"}],"predecessor-version":[{"id":343,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts\/337\/revisions\/343"}],"wp:attachment":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/media?parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/categories?post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/tags?post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}