(text, options)
| 76131 | } |
| 76132 | |
| 76133 | function copy(text, options) { |
| 76134 | var debug, |
| 76135 | message, |
| 76136 | reselectPrevious, |
| 76137 | range, |
| 76138 | selection, |
| 76139 | mark, |
| 76140 | success = false; |
| 76141 | if (!options) { |
| 76142 | options = {}; |
| 76143 | } |
| 76144 | debug = options.debug || false; |
| 76145 | try { |
| 76146 | reselectPrevious = deselectCurrent(); |
| 76147 | |
| 76148 | range = document.createRange(); |
| 76149 | selection = document.getSelection(); |
| 76150 | |
| 76151 | mark = document.createElement("span"); |
| 76152 | mark.textContent = text; |
| 76153 | // reset user styles for span element |
| 76154 | mark.style.all = "unset"; |
| 76155 | // prevents scrolling to the end of the page |
| 76156 | mark.style.position = "fixed"; |
| 76157 | mark.style.top = 0; |
| 76158 | mark.style.clip = "rect(0, 0, 0, 0)"; |
| 76159 | // used to preserve spaces and line breaks |
| 76160 | mark.style.whiteSpace = "pre"; |
| 76161 | // do not inherit user-select (it may be `none`) |
| 76162 | mark.style.webkitUserSelect = "text"; |
| 76163 | mark.style.MozUserSelect = "text"; |
| 76164 | mark.style.msUserSelect = "text"; |
| 76165 | mark.style.userSelect = "text"; |
| 76166 | mark.addEventListener("copy", function(e) { |
| 76167 | e.stopPropagation(); |
| 76168 | if (options.format) { |
| 76169 | e.preventDefault(); |
| 76170 | if (typeof e.clipboardData === "undefined") { // IE 11 |
| 76171 | debug && console.warn("unable to use e.clipboardData"); |
| 76172 | debug && console.warn("trying IE specific stuff"); |
| 76173 | window.clipboardData.clearData(); |
| 76174 | var format = clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting["default"] |
| 76175 | window.clipboardData.setData(format, text); |
| 76176 | } else { // all other browsers |
| 76177 | e.clipboardData.clearData(); |
| 76178 | e.clipboardData.setData(options.format, text); |
| 76179 | } |
| 76180 | } |
| 76181 | if (options.onCopy) { |
| 76182 | e.preventDefault(); |
| 76183 | options.onCopy(e.clipboardData); |
| 76184 | } |
| 76185 | }); |
| 76186 | |
| 76187 | document.body.appendChild(mark); |
| 76188 | |
| 76189 | range.selectNodeContents(mark); |
| 76190 | selection.addRange(range); |
searching dependent graphs…