moksha/api/widgets/global_resources/widget.py | 2 moksha/public/javascript/jquery.expander.js | 152 ---------------------- moksha/widgets/expander.py | 26 --- moksha/widgets/expander/__init__.py | 1 moksha/widgets/expander/expander.py | 28 ++++ moksha/widgets/expander/static/jquery.expander.js | 152 ++++++++++++++++++++++ 6 files changed, 182 insertions(+), 179 deletions(-)
New commits: commit afcc18a734343c7e891e93cba333902bc5caf8c8 Author: Luke Macken lmacken@redhat.com Date: Sun May 31 19:14:00 2009 -0400
Fix a typo in a docstring
diff --git a/moksha/api/widgets/global_resources/widget.py b/moksha/api/widgets/global_resources/widget.py index f9f1b46..5faef64 100644 --- a/moksha/api/widgets/global_resources/widget.py +++ b/moksha/api/widgets/global_resources/widget.py @@ -39,7 +39,7 @@ class GlobalResourceInjectionWidget(Widget):
:Note: Global Widget injection will only work when the global_resource widget is actually rendered in the template. Otherwise, only JS - and CSS resources fill get injected. Moksha's index.mak template + and CSS resources will get injected. Moksha's index.mak template handles this for us, otherwise you can import the `global_resources` widget from this module and do it yourself. """ diff --git a/moksha/widgets/expander.py b/moksha/widgets/expander.py deleted file mode 100644 index b283216..0000000 --- a/moksha/widgets/expander.py +++ /dev/null @@ -1,26 +0,0 @@ -# This file is part of Moksha -# Copyright (C) 2008-2009 Red Hat, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see http://www.gnu.org/licenses/. - -""" -:mod:`fedoracommunity.widgets.expander` -- An Expander Widget -============================================================= - -http://plugins.learningjquery.com/expander -""" - -from tw.api import JSLink - -expander_js = JSLink(link='/javascript/jquery.expander.js')
commit 1dfdb07aff31da0073a0dc57655baff61906a348 Author: Luke Macken lmacken@redhat.com Date: Sun May 31 19:13:23 2009 -0400
Improve the expander plugin, have it require jquery, and move it's static resource
diff --git a/moksha/public/javascript/jquery.expander.js b/moksha/public/javascript/jquery.expander.js deleted file mode 100644 index f56eef0..0000000 --- a/moksha/public/javascript/jquery.expander.js +++ /dev/null @@ -1,152 +0,0 @@ -/* - * jQuery Expander plugin - * Version 0.4 (12/09/2008) - * @requires jQuery v1.1.1+ - * - * Dual licensed under the MIT and GPL licenses: - * http://www.opensource.org/licenses/mit-license.php - * http://www.gnu.org/licenses/gpl.html - * - */ - - -(function($) { - - $.fn.expander = function(options) { - - var opts = $.extend({}, $.fn.expander.defaults, options); - var delayedCollapse; - return this.each(function() { - var $this = $(this); - var o = $.meta ? $.extend({}, opts, $this.data()) : opts; - var cleanedTag, startTags, endTags; - var allText = $this.html(); - var startText = allText.slice(0, o.slicePoint).replace(/\w+$/,''); - startTags = startText.match(/<\w[^>]*>/g); - if (startTags) {startText = allText.slice(0,o.slicePoint + startTags.join('').length).replace(/\w+$/,'');} - - if (startText.lastIndexOf('<') > startText.lastIndexOf('>') ) { - startText = startText.slice(0,startText.lastIndexOf('<')); - } - var endText = allText.slice(startText.length); - // create necessary expand/collapse elements if they don't already exist - if (!$('span.details', this).length) { - // end script if text length isn't long enough. - if ( endText.replace(/\s+$/,'').split(' ').length < o.widow ) { return; } - // otherwise, continue... - if (endText.indexOf('</') > -1) { - endTags = endText.match(/<(/)?[^>]*>/g); - for (var i=0; i < endTags.length; i++) { - - if (endTags[i].indexOf('</') > -1) { - var startTag, startTagExists = false; - for (var j=0; j < i; j++) { - startTag = endTags[j].slice(0, endTags[j].indexOf(' ')).replace(/(\w)$/,'$1>'); - if (startTag == rSlash(endTags[i])) { - startTagExists = true; - } - } - if (!startTagExists) { - startText = startText + endTags[i]; - var matched = false; - for (var s=startTags.length - 1; s >= 0; s--) { - if (startTags[s].slice(0, startTags[s].indexOf(' ')).replace(/(\w)$/,'$1>') == rSlash(endTags[i]) - && matched == false) { - cleanedTag = cleanedTag ? startTags[s] + cleanedTag : startTags[s]; - matched = true; - } - }; - } - } - } - - endText = cleanedTag && cleanedTag + endText || endText; - } - $this.html([ - startText, - '<span class="read-more">', - o.expandPrefix, - '<a href="#">', - o.expandText, - '</a>', - '</span>', - '<span class="details">', - endText, - '</span>' - ].join('') - ); - } - var $thisDetails = $('span.details', this), - $readMore = $('span.read-more', this); - $thisDetails.hide(); - $readMore.find('a').click(function() { - $readMore.hide(); - - if (o.expandEffect === 'show' && !o.expandSpeed) { - o.beforeExpand($this); - $thisDetails.show(); - o.afterExpand($this); - delayCollapse(o, $thisDetails); - } else { - o.beforeExpand($this); - $thisDetails[o.expandEffect](o.expandSpeed, function() { - $thisDetails.css({zoom: ''}); - o.afterExpand($this); - delayCollapse(o, $thisDetails); - }); - } - return false; - }); - if (o.userCollapse) { - $this - .find('span.details').append('<span class="re-collapse">' + o.userCollapsePrefix + '<a href="#">' + o.userCollapseText + '</a></span>'); - $this.find('span.re-collapse a').click(function() { - - clearTimeout(delayedCollapse); - var $detailsCollapsed = $(this).parents('span.details'); - reCollapse($detailsCollapsed); - o.onCollapse($this, true); - return false; - }); - } - }); - function reCollapse(el) { - el.hide() - .prev('span.read-more').show(); - } - function delayCollapse(option, $collapseEl) { - if (option.collapseTimer) { - delayedCollapse = setTimeout(function() { - reCollapse($collapseEl); - option.onCollapse($collapseEl.parent(), false); - }, - option.collapseTimer - ); - } - } - function rSlash(rString) { - return rString.replace(///,''); - } - }; - // plugin defaults - $.fn.expander.defaults = { - slicePoint: 100, // the number of characters at which the contents will be sliced into two parts. - // Note: any tag names in the HTML that appear inside the sliced element before - // the slicePoint will be counted along with the text characters. - widow: 4, // a threshold of sorts for whether to initially hide/collapse part of the element's contents. - // If after slicing the contents in two there are fewer words in the second part than - // the value set by widow, we won't bother hiding/collapsing anything. - expandText: 'read more', // text displayed in a link instead of the hidden part of the element. - // clicking this will expand/show the hidden/collapsed text - expandPrefix: '… ', - collapseTimer: 0, // number of milliseconds after text has been expanded at which to collapse the text again - expandEffect: 'fadeIn', - expandSpeed: '', // speed in milliseconds of the animation effect for expanding the text - userCollapse: true, // allow the user to re-collapse the expanded text. - userCollapseText: '[collapse expanded text]', // text to use for the link to re-collapse the text - userCollapsePrefix: ' ', - beforeExpand: function($thisEl) {}, - afterExpand: function($thisEl) {}, - onCollapse: function($thisEl, byUser) {} - }; -})(jQuery); diff --git a/moksha/widgets/expander/__init__.py b/moksha/widgets/expander/__init__.py new file mode 100644 index 0000000..9bccce2 --- /dev/null +++ b/moksha/widgets/expander/__init__.py @@ -0,0 +1 @@ +from expander import expander_js diff --git a/moksha/widgets/expander/expander.py b/moksha/widgets/expander/expander.py new file mode 100644 index 0000000..78b9536 --- /dev/null +++ b/moksha/widgets/expander/expander.py @@ -0,0 +1,28 @@ +# This file is part of Moksha +# Copyright (C) 2008-2009 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. + +""" +:mod:`fedoracommunity.widgets.expander` -- An Expander Widget +============================================================= + +http://plugins.learningjquery.com/expander +""" + +from tw.api import JSLink +from tw.jquery import jquery_js + +expander_js = JSLink(filename='static/jquery.expander.js', + modname=__name__, javascript=[jquery_js]) diff --git a/moksha/widgets/expander/static/jquery.expander.js b/moksha/widgets/expander/static/jquery.expander.js new file mode 100644 index 0000000..f56eef0 --- /dev/null +++ b/moksha/widgets/expander/static/jquery.expander.js @@ -0,0 +1,152 @@ +/* + * jQuery Expander plugin + * Version 0.4 (12/09/2008) + * @requires jQuery v1.1.1+ + * + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + * + */ + + +(function($) { + + $.fn.expander = function(options) { + + var opts = $.extend({}, $.fn.expander.defaults, options); + var delayedCollapse; + return this.each(function() { + var $this = $(this); + var o = $.meta ? $.extend({}, opts, $this.data()) : opts; + var cleanedTag, startTags, endTags; + var allText = $this.html(); + var startText = allText.slice(0, o.slicePoint).replace(/\w+$/,''); + startTags = startText.match(/<\w[^>]*>/g); + if (startTags) {startText = allText.slice(0,o.slicePoint + startTags.join('').length).replace(/\w+$/,'');} + + if (startText.lastIndexOf('<') > startText.lastIndexOf('>') ) { + startText = startText.slice(0,startText.lastIndexOf('<')); + } + var endText = allText.slice(startText.length); + // create necessary expand/collapse elements if they don't already exist + if (!$('span.details', this).length) { + // end script if text length isn't long enough. + if ( endText.replace(/\s+$/,'').split(' ').length < o.widow ) { return; } + // otherwise, continue... + if (endText.indexOf('</') > -1) { + endTags = endText.match(/<(/)?[^>]*>/g); + for (var i=0; i < endTags.length; i++) { + + if (endTags[i].indexOf('</') > -1) { + var startTag, startTagExists = false; + for (var j=0; j < i; j++) { + startTag = endTags[j].slice(0, endTags[j].indexOf(' ')).replace(/(\w)$/,'$1>'); + if (startTag == rSlash(endTags[i])) { + startTagExists = true; + } + } + if (!startTagExists) { + startText = startText + endTags[i]; + var matched = false; + for (var s=startTags.length - 1; s >= 0; s--) { + if (startTags[s].slice(0, startTags[s].indexOf(' ')).replace(/(\w)$/,'$1>') == rSlash(endTags[i]) + && matched == false) { + cleanedTag = cleanedTag ? startTags[s] + cleanedTag : startTags[s]; + matched = true; + } + }; + } + } + } + + endText = cleanedTag && cleanedTag + endText || endText; + } + $this.html([ + startText, + '<span class="read-more">', + o.expandPrefix, + '<a href="#">', + o.expandText, + '</a>', + '</span>', + '<span class="details">', + endText, + '</span>' + ].join('') + ); + } + var $thisDetails = $('span.details', this), + $readMore = $('span.read-more', this); + $thisDetails.hide(); + $readMore.find('a').click(function() { + $readMore.hide(); + + if (o.expandEffect === 'show' && !o.expandSpeed) { + o.beforeExpand($this); + $thisDetails.show(); + o.afterExpand($this); + delayCollapse(o, $thisDetails); + } else { + o.beforeExpand($this); + $thisDetails[o.expandEffect](o.expandSpeed, function() { + $thisDetails.css({zoom: ''}); + o.afterExpand($this); + delayCollapse(o, $thisDetails); + }); + } + return false; + }); + if (o.userCollapse) { + $this + .find('span.details').append('<span class="re-collapse">' + o.userCollapsePrefix + '<a href="#">' + o.userCollapseText + '</a></span>'); + $this.find('span.re-collapse a').click(function() { + + clearTimeout(delayedCollapse); + var $detailsCollapsed = $(this).parents('span.details'); + reCollapse($detailsCollapsed); + o.onCollapse($this, true); + return false; + }); + } + }); + function reCollapse(el) { + el.hide() + .prev('span.read-more').show(); + } + function delayCollapse(option, $collapseEl) { + if (option.collapseTimer) { + delayedCollapse = setTimeout(function() { + reCollapse($collapseEl); + option.onCollapse($collapseEl.parent(), false); + }, + option.collapseTimer + ); + } + } + function rSlash(rString) { + return rString.replace(///,''); + } + }; + // plugin defaults + $.fn.expander.defaults = { + slicePoint: 100, // the number of characters at which the contents will be sliced into two parts. + // Note: any tag names in the HTML that appear inside the sliced element before + // the slicePoint will be counted along with the text characters. + widow: 4, // a threshold of sorts for whether to initially hide/collapse part of the element's contents. + // If after slicing the contents in two there are fewer words in the second part than + // the value set by widow, we won't bother hiding/collapsing anything. + expandText: 'read more', // text displayed in a link instead of the hidden part of the element. + // clicking this will expand/show the hidden/collapsed text + expandPrefix: '… ', + collapseTimer: 0, // number of milliseconds after text has been expanded at which to collapse the text again + expandEffect: 'fadeIn', + expandSpeed: '', // speed in milliseconds of the animation effect for expanding the text + userCollapse: true, // allow the user to re-collapse the expanded text. + userCollapseText: '[collapse expanded text]', // text to use for the link to re-collapse the text + userCollapsePrefix: ' ', + beforeExpand: function($thisEl) {}, + afterExpand: function($thisEl) {}, + onCollapse: function($thisEl, byUser) {} + }; +})(jQuery);
moksha-commits@lists.fedorahosted.org