Skip to content

Instantly share code, notes, and snippets.

@ossxp-com
Created July 15, 2011 12:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ossxp-com/1084591 to your computer and use it in GitHub Desktop.
Save ossxp-com/1084591 to your computer and use it in GitHub Desktop.
Add toggle button at the anchor with .click-more style
// ==UserScript==
// @name Click more for toggle
// @namespace gotgit
// @description Add a toogle effect at the location where anchor with a click-more css.
// @include http://www.worldhello.net/gotgit/demo*
// @include http://gotgit.github.com/gotgit/demo*
// @include http://www.ossxp.com/doc/gotgit/demo*
// @require http://code.jquery.com/jquery-1.6.2.min.js
// ==/UserScript==
// Host on https://gist.github.com/1084591
// Copyright 2011, Jiang Xin
$(function(){
$('.click-more').each(function(i) {
contentNode = this.parentNode.nextSibling;
if (contentNode.nodeType ==
(typeof(Node) === "undefined" ? 3: Node.TEXT_NODE)) {
contentNode = contentNode.nextSibling;
}
contentNode.parentNode.removeChild(contentNode);
divNode = $('<div class="click-more-contents">').hide();
divNode.append(contentNode);
button = $('<div class="click-more-button-closed">更多...</div>');
button.addClass('click-more-button');
$(this.parentNode).append(button);
$(this.parentNode).append(divNode);
})
$('.click-more').parent().each(function(i) {
$('.click-more-button', this).bind('click', function() {
divNode = $('div.click-more-contents', this.parentNode);
divNode.toggle();
button = $('.click-more-button', this.parentNode)
if (divNode.is(':visible')) {
button.removeClass('click-more-button-closed');
button.addClass('click-more-button-opened');
button[0].textContent = '收起...';
} else {
button.removeClass('click-more-button-opened');
button.addClass('click-more-button-closed');
button[0].textContent = '更多...';
}
})
});
})
@fbli
Copy link

fbli commented Dec 2, 2016

啊啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment