2_features.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>jsMind</title>
  7. <link type="text/css" rel="stylesheet" href="../style/jsmind.css" />
  8. <style type="text/css">
  9. li{margin-top:2px; margin-bottom:2px;}
  10. button{width:140px;}
  11. select{width:140px;}
  12. #layout{width:1230px;}
  13. #jsmind_nav{width:210px;height:600px;border:solid 1px #ccc;overflow:auto;float:left;}
  14. .file_input{width:100px;}
  15. button.sub{width:100px;}
  16. #jsmind_container{
  17. float:left;
  18. width:1000px;
  19. height:600px;
  20. border:solid 1px #ccc;
  21. background:#f4f4f4;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. <div id="layout">
  27. <div id="jsmind_nav">
  28. <div>1. Open</div>
  29. <ol type='A'>
  30. <li><button onclick="open_json();">open example</button></li>
  31. <li><button onclick="open_ajax();">open remote</button></li>
  32. <li><button onclick="prompt_info('see 6.Multi Format');">open local file</button></li>
  33. <li><button onclick="prompt_info('see 6.Multi Format');">save local file</button></li>
  34. <li><button onclick="screen_shot();">screenshot</button></li>
  35. </ol>
  36. </ol>
  37. <div>2. Select &amp; Toggle</div>
  38. <ol type='A'>
  39. <li><button onclick="select_node();">select a node</button></li>
  40. <li><button onclick="prompt_info('please try click a node');">try click a node</button></li>
  41. <li><button onclick="show_selected();">get the selected</button></li>
  42. </ol>
  43. <div>3. Edit</div>
  44. <ol type='A'>
  45. <li><button onclick="toggle_editable(this);">disable editable</button></li>
  46. <li><button onclick="add_node();">add a node</button></li>
  47. <li><button onclick="add_image_node();">add a image node</button></li>
  48. <li><button onclick="modify_node();">modify node</button></li>
  49. <li><button onclick="prompt_info('please try double click a node');">try double click</button></li>
  50. <li><button onclick="move_node();">move a node</button></li>
  51. <li><button onclick="move_to_first();">move to first</button></li>
  52. <li><button onclick="move_to_last();">move to last</button></li>
  53. <li><button onclick="remove_node();">remove node</button></li>
  54. </ol>
  55. <div>4. Style</div>
  56. <ol type='A'>
  57. <li><button onclick="change_text_font();">change font</button></li>
  58. <li><button onclick="change_text_color();">change color</button></li>
  59. <li><button onclick="change_background_color();">change bg-color</button></li>
  60. <li><button onclick="change_background_image();">change background</button></li>
  61. </ol>
  62. <div>5. Theme</div>
  63. <ol type='A'>
  64. <li>
  65. <select onchange="set_theme(this.value);">
  66. <option value="">default</option>
  67. <option value="primary">primary</option>
  68. <option value="warning">warning</option>
  69. <option value="danger">danger</option>
  70. <option value="success">success</option>
  71. <option value="info">info</option>
  72. <option value="greensea" selected="selected">greensea</option>
  73. <option value="nephrite">nephrite</option>
  74. <option value="belizehole">belizehole</option>
  75. <option value="wisteria">wisteria</option>
  76. <option value="asphalt">asphalt</option>
  77. <option value="orange">orange</option>
  78. <option value="pumpkin">pumpkin</option>
  79. <option value="pomegranate">pomegranate</option>
  80. <option value="clouds">clouds</option>
  81. <option value="asbestos">asbestos</option>
  82. </select>
  83. </li>
  84. </ol>
  85. <div>6. Adjusting</div>
  86. <ol type='A'>
  87. <li><button onclick="change_container();">resize container</button>
  88. <button onclick="resize_jsmind();">adusting</button></li>
  89. <li>expand/collapse</li>
  90. <ol>
  91. <li><button class="sub" onclick="expand();">expand node</button></li>
  92. <li><button class="sub" onclick="collapse();">collapse node</button></li>
  93. <li><button class="sub" onclick="toggle();">toggle node</button></li>
  94. <li><button class="sub" onclick="expand_to_level2();">expand to level 2</button></li>
  95. <li><button class="sub" onclick="expand_to_level3();">expand to level 3</button></li>
  96. <li><button class="sub" onclick="expand_all();">expand all</button></li>
  97. <li><button class="sub" onclick="collapse_all();">collapse all</button></li>
  98. </ol>
  99. <li>zoom</li>
  100. <button id="zoom-in-button" style="width:50px" onclick="zoomIn();">
  101. In
  102. </button>
  103. <button id="zoom-out-button" style="width:50px" onclick="zoomOut();">
  104. Out
  105. </button>
  106. </ol>
  107. <div>7. Multi Format</div>
  108. <ol type='A'>
  109. <li>node_tree(default)</li>
  110. <ol>
  111. <li><button class="sub" onclick="show_data();">show data</button></li>
  112. <li><button class="sub" onclick="save_file();">save file</button></li>
  113. <li><input id="file_input" class="file_input" type="file"/></li>
  114. <li><button class="sub" onclick="open_file();">open file</button></li>
  115. </ol>
  116. <li>node_array</li>
  117. <ol>
  118. <li><button class="sub" onclick="get_nodearray_data();">show data</button></li>
  119. <li><button class="sub" onclick="save_nodearray_file();">save file</button></li>
  120. <li><input id="file_input_nodearray" class="file_input" type="file"/></li>
  121. <li><button class="sub" onclick="open_nodearray();">open file</button></li>
  122. </ol>
  123. <li>freemind(.mm)</li>
  124. <ol>
  125. <li><button class="sub" onclick="get_freemind_data();">show data</button></li>
  126. <li><button class="sub" onclick="save_freemind_file();">save file</button></li>
  127. <li><input id="file_input_freemind" class="file_input" type="file"/></li>
  128. <li><button class="sub" onclick="open_freemind();">open file</button></li>
  129. </ol>
  130. </ol>
  131. </div>
  132. <div id="jsmind_container"></div>
  133. <div style="display:none">
  134. <input class="file" type="file" id="image-chooser" accept="image/*"/>
  135. </div>
  136. </div>
  137. <script type="text/javascript" src="../js/jsmind.js"></script>
  138. <script type="text/javascript" src="../js/jsmind.draggable.js"></script>
  139. <script type="text/javascript" src="../js/jsmind.screenshot.js"></script>
  140. <script type="text/javascript">
  141. var _jm = null;
  142. function open_empty(){
  143. var options = {
  144. container:'jsmind_container',
  145. theme:'greensea',
  146. editable:true
  147. }
  148. _jm = jsMind.show(options);
  149. // _jm = jsMind.show(options,mind);
  150. }
  151. function open_json(){
  152. var mind = {
  153. "meta":{
  154. "name":"jsMind remote",
  155. "author":"hizzgdev@163.com",
  156. "version":"0.2"
  157. },
  158. "format":"node_tree",
  159. "data":{"id":"root","topic":"jsMind","children":[
  160. {"id":"easy","topic":"Easy","direction":"left","children":[
  161. {"id":"easy1","topic":"Easy to show"},
  162. {"id":"easy2","topic":"Easy to edit"},
  163. {"id":"easy3","topic":"Easy to store"},
  164. {"id":"easy4","topic":"Easy to embed"},
  165. {"id":"other3","background-image":"ant.png", "width": "100", "height": "100"}
  166. ]},
  167. {"id":"open","topic":"Open Source","direction":"right","children":[
  168. {"id":"open1","topic":"on GitHub", "background-color":"#eee", "foreground-color":"blue"},
  169. {"id":"open2","topic":"BSD License"}
  170. ]},
  171. {"id":"powerful","topic":"Powerful","direction":"right","children":[
  172. {"id":"powerful1","topic":"Base on Javascript"},
  173. {"id":"powerful2","topic":"Base on HTML5"},
  174. {"id":"powerful3","topic":"Depends on you"}
  175. ]},
  176. {"id":"other","topic":"test node","direction":"left","children":[
  177. {"id":"other1","topic":"I'm from local variable"},
  178. {"id":"other2","topic":"I can do everything"}
  179. ]}
  180. ]}
  181. }
  182. _jm.show(mind);
  183. }
  184. function open_ajax(){
  185. var mind_url = 'data_example.json';
  186. jsMind.util.ajax.get(mind_url,function(mind){
  187. _jm.show(mind);
  188. });
  189. }
  190. function screen_shot(){
  191. _jm.screenshot.shootDownload();
  192. }
  193. function show_data(){
  194. var mind_data = _jm.get_data();
  195. var mind_string = jsMind.util.json.json2string(mind_data);
  196. prompt_info(mind_string);
  197. }
  198. function save_file(){
  199. var mind_data = _jm.get_data();
  200. var mind_name = mind_data.meta.name;
  201. var mind_str = jsMind.util.json.json2string(mind_data);
  202. jsMind.util.file.save(mind_str,'text/jsmind',mind_name+'.jm');
  203. }
  204. function open_file(){
  205. var file_input = document.getElementById('file_input');
  206. var files = file_input.files;
  207. if(files.length > 0){
  208. var file_data = files[0];
  209. jsMind.util.file.read(file_data,function(jsmind_data, jsmind_name){
  210. var mind = jsMind.util.json.string2json(jsmind_data);
  211. if(!!mind){
  212. _jm.show(mind);
  213. }else{
  214. prompt_info('can not open this file as mindmap');
  215. }
  216. });
  217. }else{
  218. prompt_info('please choose a file first')
  219. }
  220. }
  221. function select_node(){
  222. var nodeid = 'other';
  223. _jm.select_node(nodeid);
  224. }
  225. function show_selected(){
  226. var selected_node = _jm.get_selected_node();
  227. if(!!selected_node){
  228. prompt_info(selected_node.topic);
  229. }else{
  230. prompt_info('nothing');
  231. }
  232. }
  233. function get_selected_nodeid(){
  234. var selected_node = _jm.get_selected_node();
  235. if(!!selected_node){
  236. return selected_node.id;
  237. }else{
  238. return null;
  239. }
  240. }
  241. function add_node(){
  242. var selected_node = _jm.get_selected_node(); // as parent of new node
  243. if(!selected_node){prompt_info('please select a node first.');return;}
  244. var nodeid = jsMind.util.uuid.newid();
  245. var topic = '* Node_'+nodeid.substr(nodeid.length-6)+' *';
  246. var node = _jm.add_node(selected_node, nodeid, topic);
  247. }
  248. var imageChooser = document.getElementById('image-chooser');
  249. imageChooser.addEventListener('change', function (event) {
  250. // Read file here.
  251. var reader = new FileReader();
  252. reader.onloadend = (function () {
  253. var selected_node = _jm.get_selected_node();
  254. var nodeid = jsMind.util.uuid.newid();
  255. var topic = undefined;
  256. var data = {
  257. "background-image": reader.result,
  258. "width": "100",
  259. "height": "100"};
  260. var node = _jm.add_node(selected_node, nodeid, topic, data);
  261. //var node = _jm.add_image_node(selected_node, nodeid, reader.result, 100, 100);
  262. //add_image_node:function(parent_node, nodeid, image, width, height, data, idx, direction, expanded){
  263. });
  264. var file = imageChooser.files[0];
  265. if (file) {
  266. reader.readAsDataURL(file);
  267. };
  268. }, false);
  269. function add_image_node(){
  270. var selected_node = _jm.get_selected_node(); // as parent of new node
  271. if(!selected_node){
  272. prompt_info('please select a node first.');
  273. return;
  274. }
  275. imageChooser.focus();
  276. imageChooser.click();
  277. }
  278. function modify_node(){
  279. var selected_id = get_selected_nodeid();
  280. if(!selected_id){prompt_info('please select a node first.');return;}
  281. // modify the topic
  282. _jm.update_node(selected_id, '--- modified ---');
  283. }
  284. function move_to_first(){
  285. var selected_id = get_selected_nodeid();
  286. if(!selected_id){prompt_info('please select a node first.');return;}
  287. _jm.move_node(selected_id,'_first_');
  288. }
  289. function move_to_last(){
  290. var selected_id = get_selected_nodeid();
  291. if(!selected_id){prompt_info('please select a node first.');return;}
  292. _jm.move_node(selected_id,'_last_');
  293. }
  294. function move_node(){
  295. // move a node before another
  296. _jm.move_node('other','open');
  297. }
  298. function remove_node(){
  299. var selected_id = get_selected_nodeid();
  300. if(!selected_id){prompt_info('please select a node first.');return;}
  301. _jm.remove_node(selected_id);
  302. }
  303. function change_text_font(){
  304. var selected_id = get_selected_nodeid();
  305. if(!selected_id){prompt_info('please select a node first.');return;}
  306. _jm.set_node_font_style(selected_id, 28);
  307. }
  308. function change_text_color(){
  309. var selected_id = get_selected_nodeid();
  310. if(!selected_id){prompt_info('please select a node first.');return;}
  311. _jm.set_node_color(selected_id, null, '#000');
  312. }
  313. function change_background_color(){
  314. var selected_id = get_selected_nodeid();
  315. if(!selected_id){prompt_info('please select a node first.');return;}
  316. _jm.set_node_color(selected_id, '#eee', null);
  317. }
  318. function change_background_image(){
  319. var selected_id = get_selected_nodeid();
  320. if(!selected_id){prompt_info('please select a node first.');return;}
  321. _jm.set_node_background_image(selected_id, 'ant.png', 100, 100);
  322. }
  323. function set_theme(theme_name){
  324. _jm.set_theme(theme_name);
  325. }
  326. var zoomInButton = document.getElementById("zoom-in-button");
  327. var zoomOutButton = document.getElementById("zoom-out-button");
  328. function zoomIn() {
  329. if (_jm.view.zoomIn()) {
  330. zoomOutButton.disabled = false;
  331. } else {
  332. zoomInButton.disabled = true;
  333. };
  334. };
  335. function zoomOut() {
  336. if (_jm.view.zoomOut()) {
  337. zoomInButton.disabled = false;
  338. } else {
  339. zoomOutButton.disabled = true;
  340. };
  341. };
  342. function toggle_editable(btn){
  343. var editable = _jm.get_editable();
  344. if(editable){
  345. _jm.disable_edit();
  346. btn.innerHTML = 'enable editable';
  347. }else{
  348. _jm.enable_edit();
  349. btn.innerHTML = 'disable editable';
  350. }
  351. }
  352. // this method change size of container, perpare for adjusting jsmind
  353. function change_container(){
  354. var c = document.getElementById('jsmind_container');
  355. c.style.width = '800px';
  356. c.style.height = '500px';
  357. }
  358. function resize_jsmind(){
  359. _jm.resize();
  360. }
  361. function expand(){
  362. var selected_id = get_selected_nodeid();
  363. if(!selected_id){prompt_info('please select a node first.');return;}
  364. _jm.expand_node(selected_id);
  365. }
  366. function collapse(){
  367. var selected_id = get_selected_nodeid();
  368. if(!selected_id){prompt_info('please select a node first.');return;}
  369. _jm.collapse_node(selected_id);
  370. }
  371. function toggle(){
  372. var selected_id = get_selected_nodeid();
  373. if(!selected_id){prompt_info('please select a node first.');return;}
  374. _jm.toggle_node(selected_id);
  375. }
  376. function expand_all(){
  377. _jm.expand_all();
  378. }
  379. function expand_to_level2(){
  380. _jm.expand_to_depth(2);
  381. }
  382. function expand_to_level3(){
  383. _jm.expand_to_depth(3);
  384. }
  385. function collapse_all(){
  386. _jm.collapse_all();
  387. }
  388. function get_nodearray_data(){
  389. var mind_data = _jm.get_data('node_array');
  390. var mind_string = jsMind.util.json.json2string(mind_data);
  391. prompt_info(mind_string);
  392. }
  393. function save_nodearray_file(){
  394. var mind_data = _jm.get_data('node_array');
  395. var mind_name = mind_data.meta.name;
  396. var mind_str = jsMind.util.json.json2string(mind_data);
  397. jsMind.util.file.save(mind_str,'text/jsmind',mind_name+'.jm');
  398. }
  399. function open_nodearray(){
  400. var file_input = document.getElementById('file_input_nodearray');
  401. var files = file_input.files;
  402. if(files.length > 0){
  403. var file_data = files[0];
  404. jsMind.util.file.read(file_data,function(jsmind_data, jsmind_name){
  405. var mind = jsMind.util.json.string2json(jsmind_data);
  406. if(!!mind){
  407. _jm.show(mind);
  408. }else{
  409. prompt_info('can not open this file as mindmap');
  410. }
  411. });
  412. }else{
  413. prompt_info('please choose a file first')
  414. }
  415. }
  416. function get_freemind_data(){
  417. var mind_data = _jm.get_data('freemind');
  418. var mind_string = jsMind.util.json.json2string(mind_data);
  419. alert(mind_string);
  420. }
  421. function save_freemind_file(){
  422. var mind_data = _jm.get_data('freemind');
  423. var mind_name = mind_data.meta.name || 'freemind';
  424. var mind_str = mind_data.data;
  425. jsMind.util.file.save(mind_str,'text/xml',mind_name+'.mm');
  426. }
  427. function open_freemind(){
  428. var file_input = document.getElementById('file_input_freemind');
  429. var files = file_input.files;
  430. if(files.length > 0){
  431. var file_data = files[0];
  432. jsMind.util.file.read(file_data, function(freemind_data, freemind_name){
  433. if(freemind_data){
  434. var mind_name = freemind_name;
  435. if(/.*\.mm$/.test(mind_name)){
  436. mind_name = freemind_name.substring(0,freemind_name.length-3);
  437. }
  438. var mind = {
  439. "meta":{
  440. "name":mind_name,
  441. "author":"hizzgdev@163.com",
  442. "version":"1.0.1"
  443. },
  444. "format":"freemind",
  445. "data":freemind_data
  446. };
  447. _jm.show(mind);
  448. }else{
  449. prompt_info('can not open this file as mindmap');
  450. }
  451. });
  452. }else{
  453. prompt_info('please choose a file first')
  454. }
  455. }
  456. function prompt_info(msg){
  457. alert(msg);
  458. }
  459. open_empty();
  460. </script>
  461. </body>
  462. </html>