Created
July 15, 2011 12:20
-
-
Save ossxp-com/1084591 to your computer and use it in GitHub Desktop.
Add toggle button at the anchor with .click-more style
This file contains 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
// ==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 = '更多...'; | |
} | |
}) | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
啊啊