showAticleMapというwordpressのプラグインで読み込みが遅いので初期状態時、チェックボックスのチェックを外した状態にしたいのですが、
js
1checked="checked"
の記述を削除してみましたが、チェックボックスのチェックは消えたものの、状態としてはチェックが付いている状態になってしまいました。
どのように記述すればよろしいでしょうか?
js
1var dataset = JSON.parse(eval("jQuery('#show-article-map-dataset').text()")); 2var nodedata = dataset[0]; 3var edgedata = dataset[1]; 4var nodes = new vis.DataSet(nodedata); 5var edges = new vis.DataSet(edgedata); 6var container = document.getElementById('mynetwork'); 7var data = { nodes: nodes, edges: edges }; 8var options = { 9 nodes: { shape: "box" }, 10 edges: { arrows: { to: { enabled: true, scaleFactor: 1, type: 'arrow' } } }, 11 manipulation: { enabled: true }, 12}; 13var network = new vis.Network(container, data, options); 14 15network.on('doubleClick', function(e) { 16 var nodeID = e.nodes.toString(); 17 var url = jQuery(data.nodes.get(nodeID).title).attr('href'); 18 window.open(url, '_blank'); 19}); 20 21jQuery('#searchnodebutton').on('click', function() { 22 var search = jQuery('#searchnodequery').val(); 23 24 // serch nodes by node label 25 var hitNodes = nodes.get({ 26 filter: function(item) { 27 var label = item.label.replace("\r\n", ""); 28 return label.indexOf(search) != -1; 29 } 30 }); 31 var hitNodeIDs = []; 32 for (i = 0; i < hitNodes.length; i++) { 33 hitNodeIDs.push(hitNodes[i].id); 34 }; 35 36 // select 37 network.selectNodes(hitNodeIDs); 38}); 39jQuery('#searchnodequery').keypress(function(e) { 40 if (e.which == 13) { //Enter key pressed 41 jQuery('#searchnodebutton').click(); //Trigger search button click event 42 } 43}); 44 45//initialize group list 46var groupList = nodes.distinct('group').sort(); 47for (var i = 0; i < groupList.length; i++) { 48 jQuery('#groupList').append('<input type="checkbox" name="visibleGroups" value="' + groupList[i] + '" checked="checked" style="margin-left:15px;">' + groupList[i]); 49} 50 51// prepare node data by group 52var nodeGroups = []; 53for (var i = 0; i < groupList.length; i++) { 54 nodeGroups[groupList[i]] = nodes.get({ filter: function(item) { return item.group == groupList[i]; } }); 55} 56 57// apply group change 58jQuery('#groupList>input').on('change', function() { 59 var currentGroupNames = nodes.distinct('group'); 60 var visibleGroupNames = []; 61 jQuery("#groupList :checkbox:checked").each(function() { 62 visibleGroupNames.push(this.value); 63 }); 64 var diffGroupNames = diffArray(currentGroupNames, visibleGroupNames); 65 if (currentGroupNames.length < visibleGroupNames.length) { 66 for (i = 0; i < diffGroupNames.length; i++) { 67 nodes.add(nodeGroups[diffGroupNames[i]]); 68 } 69 } 70 else if (currentGroupNames.length > visibleGroupNames.length) { 71 for (i = 0; i < diffGroupNames.length; i++) { 72 nodes.remove(nodeGroups[diffGroupNames[i]]); 73 } 74 } 75 else { 76 77 } 78}); 79 80function diffArray(arr1, arr2) { 81 return arr1.concat(arr2).filter(item => !arr1.includes(item) || !arr2.includes(item)); 82} 83 84// toggle physics 85jQuery('#togglepBlur').on('click', function() { 86 var physicsEnabled = network.physics.options.enabled; 87 var buttonText = physicsEnabled ? "Start" : "Stop"; 88 network.setOptions({ physics: { enabled: !physicsEnabled } }); 89 jQuery(this).text(buttonText); 90}); 91 92// download CSV 93jQuery('#downloadCSV').on('click', function() { 94 95 // build CSV 96 var csv = 'fromID, fromURL, fromGroup, fromTitle, toID, toURL, toGroup, toTitle\n'; 97 edges.forEach(function(e) { 98 var fromNode = nodes.get(e['from']); 99 var toNode = nodes.get(e['to']); 100 csv += 101 fromNode['id'] + ',' + 102 fromNode['title'].match(/href="(.+?)"/)[1] + ',' + 103 fromNode['group'] + ',' + 104 fromNode['label'].replace('\r\n', '') + ',' + 105 toNode['id'] + ',' + 106 toNode['title'].match(/href="(.+?)"/)[1] + ',' + 107 toNode['group'] + ',' + 108 toNode['label'].replace('\r\n', '') + '\n'; 109 }); 110 111 //download 112 var blob = new Blob([csv], { "type": "text/plain" }); 113 if (window.navigator.msSaveBlob) { 114 window.navigator.msSaveBlob(blob, "ShowArticleMap.csv"); 115 116 // msSaveOrOpenBlobの場合はファイルを保存せずに開ける 117 window.navigator.msSaveOrOpenBlob(blob, "ShowArticleMap.csv"); 118 } 119 else { 120 jQuery('#downloadCSV').attr('href', window.URL.createObjectURL(blob)); 121 } 122});
回答1件
あなたの回答
tips
プレビュー