Created
April 3, 2020 13:52
-
-
Save LadyAleena/df139c44ad6fd4b928cac03797f3f9d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************* | |
* Credits go to: (all members in irc.freenode.net ##javascript * | |
* inimino (complete adjustments) * | |
* Maggi (lots of troubleshooting help) * | |
* Typos_King (input on troubleshooting) * | |
* Mordof (compiling final efforts into this document) * | |
*******************************************************************/ | |
function load() { | |
document.getElementById('site_menu').addEventListener('click', list_onclick); | |
} | |
window.onload = load; | |
function list_onclick(e) | |
{ | |
e=e||event; | |
var elm = e.target || e.srcElement; | |
if(elm.nodeType!=1) elm=elm.parentNode; | |
var parent = getAncestor(elm,'tagName',/^(LI|OL|UL)$/i); | |
if(parent) toggleClassPair(parent, 'open', 'closed'); | |
} | |
function getAncestor(elm, prop, regVal, excludeElm) | |
{ | |
if(excludeElm) elm = elm.parentNode; | |
while(elm) | |
{ | |
if(regVal.test(elm[prop])) | |
return elm; | |
elm = elm.parentNode; | |
} | |
} | |
/* written by robdubya in irc.freenode.net ##javascript */ | |
function toggleClassPair(elm, class1, class2) | |
{ | |
elm.className = elm.className.replace(new RegExp('\\b('+class1+'|'+class2+')\\b','g'),function(found){ return found==class1? class2:class1;}); | |
} | |
function toggleClassPair(elm, class1, class2) | |
{ | |
elm.className = elm.className.replace(new RegExp('\\b('+class1+'|'+class2+')\\b','g'),function(found){ return found==class1? class2:class1;}); | |
} | |
function registerListeners(){ | |
console.log($) | |
/* single toggles written by cjohnson in irc.freenode.net ##javascript*/ | |
$('ol.faq').on('click', 'a.toggle', function() { | |
$(this).closest('li').find('span').toggleClass('hide'); | |
return false; | |
}); | |
} | |
$(document).ready(registerListeners) /* goes with line 31 - 47 */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment