Policy 1707 commit to LF
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / CSS / bootstrap / docs / assets / js / vendor / anchor.js
diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/docs/assets/js/vendor/anchor.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/docs/assets/js/vendor/anchor.js
new file mode 100644 (file)
index 0000000..e5ddfa7
--- /dev/null
@@ -0,0 +1,48 @@
+/*!
+ * AnchorJS - v0.1.0 - 2014-08-17
+ * https://github.com/bryanbraun/anchorjs
+ * Copyright (c) 2014 Bryan Braun; Licensed MIT
+ */
+
+function addAnchors(selector) {
+  'use strict';
+
+  // Sensible default selector, if none is provided.
+  if (!selector) {
+    selector = 'h1, h2, h3, h4, h5, h6';
+  } else if (typeof selector !== 'string') {
+    throw new Error('AnchorJS accepts only strings; you used a ' + typeof selector);
+  }
+
+  // Select any elements that match the provided selector.
+  var elements = document.querySelectorAll(selector);
+
+  // Loop through the selected elements.
+  for (var i = 0; i < elements.length; i++) {
+    var elementID;
+
+    if (elements[i].hasAttribute('id')) {
+      elementID = elements[i].getAttribute('id');
+    } else {
+      // We need to create an ID on our element. First, we find which text selection method is available to the browser.
+      var textMethod = document.body.textContent ? 'textContent' : 'innerText';
+
+      // Get the text inside our element
+      var roughText = elements[i][textMethod];
+
+      // Refine it so it makes a good ID. Makes all lowercase and hyphen separated.
+      // Ex. Hello World > hello-world
+      var tidyText = roughText.replace(/\s+/g, '-').toLowerCase();
+
+      // Assign it to our element.
+      // Currently the setAttribute element is only supported in IE9 and above.
+      elements[i].setAttribute('id', tidyText);
+
+      // Grab it for use in our anchor.
+      elementID = tidyText;
+    }
+    var anchor = '<a class="anchorjs-link" href="#' + elementID + '"><span class="anchorjs-icon"></span></a>';
+
+    elements[i].innerHTML += anchor;
+  }
+}