Subversion Repositories oidplus

Rev

Rev 642 | Rev 876 | Go to most recent revision | View as "text/javascript" | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.  * OIDplus 2.0
  3.  * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17.  
  18. var OIDplusPagePublicWhois = {
  19.  
  20.         copyToClipboard: function(elem) {
  21.                 // Source: https://stackoverflow.com/questions/22581345/click-button-copy-to-clipboard-using-jquery
  22.  
  23.                 // create hidden text element, if it doesn't already exist
  24.                 var targetId = "_hiddenCopyText_";
  25.                 var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
  26.                 var origSelectionStart, origSelectionEnd;
  27.                 if (isInput) {
  28.                         // can just use the original source element for the selection and copy
  29.                         target = elem;
  30.                         origSelectionStart = elem.selectionStart;
  31.                         origSelectionEnd = elem.selectionEnd;
  32.                 } else {
  33.                         // must use a temporary form element for the selection and copy
  34.                         target = document.getElementById(targetId);
  35.                         if (!target) {
  36.                                 var target = document.createElement("textarea");
  37.                                 target.style.position = "absolute";
  38.                                 target.style.left = "-9999px";
  39.                                 target.style.top = "0";
  40.                                 target.id = targetId;
  41.                                 document.body.appendChild(target);
  42.                         }
  43.                         target.textContent = elem.textContent;
  44.                 }
  45.                 // select the content
  46.                 var currentFocus = document.activeElement;
  47.                 target.focus();
  48.                 target.setSelectionRange(0, target.value.length);
  49.  
  50.                 // copy the selection
  51.                 var succeed;
  52.                 try {
  53.                         succeed = document.execCommand("copy");
  54.                 } catch(e) {
  55.                         succeed = false;
  56.                 }
  57.                 // restore original focus
  58.                 if (currentFocus && typeof currentFocus.focus === "function") {
  59.                         currentFocus.focus();
  60.                 }
  61.  
  62.                 if (isInput) {
  63.                         // restore prior selection
  64.                         elem.setSelectionRange(origSelectionStart, origSelectionEnd);
  65.                 } else {
  66.                         // clear temporary content
  67.                         target.textContent = "";
  68.                 }
  69.                 return succeed;
  70.         },
  71.  
  72.         refresh_whois_url_bar: function() {
  73.                 $("#whois_url_bar_section")[0].style.display = "Block"; // because of NoScript
  74.  
  75.                 var format = "";
  76.                 var radios = $("[name=format]");
  77.  
  78.                 for (var i = 0, length = radios.length; i < length; i++) {
  79.                         if (radios[i].checked) {
  80.                                 format = radios[i].value;
  81.                         }
  82.                 }
  83.  
  84.                 $("#whois_url_bar")[0].innerHTML = getSystemUrl() + 'plugins/viathinksoft/publicPages/100_whois/whois/webwhois.php?format=' + format + '&query=' + encodeURIComponent($("#whois_query")[0].value);
  85.         }
  86.  
  87. };
  88.