SHARE
TWEET

Untitled

a guest Jan 15th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function() {
  2.     var searchParams = new URLSearchParams(location.search);
  3.     var anchor = searchParams.get('anchor');
  4.     if (!anchor) {
  5.         throw new TypeError('There is no "anchor" parameter in the URL');
  6.     }
  7.     openCollapse(anchor).done(function () {
  8.         var element =  document.getElementById(anchor);
  9.         element.scrollIntoView({
  10.             behavior: 'smooth',
  11.             block: 'start'
  12.         });
  13.         console.log('It worked on main function');
  14.     });
  15. });
  16.  
  17. function openCollapse (elementId) {
  18.     var promises = [];
  19.     var targetCollapse = $('#' + elementId);
  20.     if (!targetCollapse.hasClass('collapse')) {
  21.         throw new TypeError('error');
  22.     }
  23.     var parents = targetCollapse.parents('.panel-collapse').toArray().reverse();
  24.     parents.push(targetCollapse[0]);
  25.  
  26.     $.each(parents, function (key, object) {
  27.         var dfd = new $.Deferred();
  28.         $(object).collapse('show');
  29.         $(object).on('shown.bs.collapse', function () {
  30.             dfd.resolve();
  31.         });
  32.         promises.push(dfd);
  33.     });
  34.  
  35.     return $.when.apply($, promises).promise();
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top