Sci Fi Mountain Range
Completely pointless but I learnt a bit about html canvas doing it! Just hit the draw range button to get draw a new one 🙂
Completely pointless but I learnt a bit about html canvas doing it! Just hit the draw range button to get draw a new one 🙂
Here’s my little function to return a random number between two numbers:
1 2 3 4 5 6 7 8 9 |
function randomNumberBetween(from, to, allowZero){ var diff=(to+1)-from; var rnum = Math.floor((Math.random() * diff)); rnum+=from; if(rnum==0 && allowZero===false){ rnum=from==0?1:from; // just make it easy for now } return rnum; } |
The ‘allowZero’ flag does just that.. though if you use this function you may wish to change what it does if it does generate a zero. It’ll work on […]
Let’s start with an example of what we’re trying to achieve – click the rows to show and hide a detail row: I figured this would be pretty straight forward with lots of examples out there in the wild but unless […]
JavaScript code to generate a document map/table of contents from the document structure. NB – Sorry I need to update this to get the examples working in WordPress This page generates the following document map: [jscript]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
[brushjs] function get_my_navigation(use_body, html_text, do_bookmarks, heading_level, show_level) { //var all_elements = document.getElementsByTagName("*"); var all_elements; if (use_body == 1) all_elements = document.getElementsByTagName("*"); else if (html_text!=""){ html_div = document.createElement("div"); html_div.innerHTML = html_text; all_elements = html_div.getElementsByTagName("*"); } if ((heading_level==null) || (heading_level=="")) heading_level=3; if (show_level==null) show_level=0; var hopen="<h"+heading_level+">"; var hclose="</h"+heading_level+">"; structure = ""; first_level = 0; level_no = 0; this_level = 0; last_level = 0; current_level = 0; for (i = 0; i < all_elements.length; i++) { h_message = ""; element_text = ""; a = all_elements[i]; if (document.all) { element_text = a.innerText; } else { element_text = a.textContent; } node_name = all_elements[i].nodeName; if (node_name == "H1" || node_name == "H2" || node_name == "H3" || node_name == "H4" || node_name == "H5" || node_name == "H6") { level_no++; this_level = parseInt(all_elements[i].nodeName.substring(1, 2)); if (level_no == 1) first_level = this_level; if (show_level==1) element_text+=" ("+this_level+")"; // if we are bookmarking the contents if (do_bookmarks==1) element_text = "<a href='#generated_link_" + i + "'>" + element_text + "</a>"; if (this_level == last_level) { if (first_level == this_level) structure += hopen + element_text + hclose; else structure += "<li>" + element_text + "</li>"; } else if (this_level > last_level) { current_level++; difference = this_level - last_level; if (difference > 1) { h_message = " (bad heading structure)</li>"; } if (first_level == this_level) structure += hopen + element_text + hclose; else structure += "<ul><li>" + element_text + h_message + "</li>"; } else if (this_level < last_level) { difference = last_level - this_level; for (z = 0; z < difference; z++) { current_level--; structure += "</ul>"; } structure += "</ul>"; if (current_level < 0) structure += "<li>" + element_text + "</li> (bad heading structure)"; else { if (first_level == this_level) structure += hopen + element_text + hclose; else structure += "<ul><li>" + element_text + "</li>"; } } if (do_bookmarks == 1) { var lnk = document.createElement("a"); lnk.name = "generated_link_" + i; lnk.id = "generated_link_" + i; all_elements[i].appendChild(lnk); } last_level = this_level; } } for (z = 0; z < current_level; z++) { structure += "</ul>"; } return structure; } |
You’ll want a […]
I wanted to be able to insert tokens using a drop down in CKEditor. I wanted tokens in brackets that would be replaced later by an application with something meaningful – so [name] for example would be replaced with a […]