aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorRedMatrix <info@friendica.com>2015-01-19 10:19:38 +1100
committerRedMatrix <info@friendica.com>2015-01-19 10:19:38 +1100
commit5d30565c665341e6a6a805684cee4d45c1d2fafe (patch)
treefd9b3ff875f7c22a671686d6325dd3da910c936e /library
parent39dad87adc9ea4449c5534e5b3a0fbcc77159a5c (diff)
parenta1ab658df1fc976954cbdd891343867b3ee64629 (diff)
downloadvolse-hubzilla-5d30565c665341e6a6a805684cee4d45c1d2fafe.tar.gz
volse-hubzilla-5d30565c665341e6a6a805684cee4d45c1d2fafe.tar.bz2
volse-hubzilla-5d30565c665341e6a6a805684cee4d45c1d2fafe.zip
Merge pull request #863 from einervonvielen/Fix_bbcode_toc_for_help_pages
Fixed bbode element toc for webpages
Diffstat (limited to 'library')
-rw-r--r--library/tableofcontents/jquery.toc.js55
1 files changed, 31 insertions, 24 deletions
diff --git a/library/tableofcontents/jquery.toc.js b/library/tableofcontents/jquery.toc.js
index d136f5aab..6ef36f49c 100644
--- a/library/tableofcontents/jquery.toc.js
+++ b/library/tableofcontents/jquery.toc.js
@@ -13,7 +13,10 @@
* or implied. See the License for the specific language governing permissions and limitations
* under the License.
*
- * The original script was modified to work within the red#martrix (added var pathname).
+ * The original script was modified to work within the red#martrix
+ * - added var pathname
+ * - added var textHeading: Accept heading with text only
+ * Why? At the moment webpages can contain empty title using h3
*/
(function ($) {
@@ -53,31 +56,35 @@
var elem = $(this), level = $.map(headingSelectors, function (selector, index) {
return elem.is(selector) ? index : undefined;
})[0];
-
- if (level > currentLevel) {
- // If the heading is at a deeper level than where we are, start a new nested
- // list, but only if we already have some list items in the parent. If we do
- // not, that means that we're skipping levels, so we can just add new list items
- // at the current level.
- // In the upside-down stack, unshift = push, and stack[0] = the top.
- var parentItem = stack[0].children("li:last")[0];
- if (parentItem) {
- stack.unshift($("<" + listTag + "/>").appendTo(parentItem));
+
+ // Accept heading with text only
+ var textHeading = elem.text();
+ if(textHeading != '') {
+ if (level > currentLevel) {
+ // If the heading is at a deeper level than where we are, start a new nested
+ // list, but only if we already have some list items in the parent. If we do
+ // not, that means that we're skipping levels, so we can just add new list items
+ // at the current level.
+ // In the upside-down stack, unshift = push, and stack[0] = the top.
+ var parentItem = stack[0].children("li:last")[0];
+ if (parentItem) {
+ stack.unshift($("<" + listTag + "/>").appendTo(parentItem));
+ }
+ } else {
+ // Truncate the stack to the current level by chopping off the 'top' of the
+ // stack. We also need to preserve at least one element in the stack - that is
+ // the containing element.
+ stack.splice(0, Math.min(currentLevel - level, Math.max(stack.length - 1, 0)));
}
- } else {
- // Truncate the stack to the current level by chopping off the 'top' of the
- // stack. We also need to preserve at least one element in the stack - that is
- // the containing element.
- stack.splice(0, Math.min(currentLevel - level, Math.max(stack.length - 1, 0)));
- }
- // the variable pathname was added to the original script.
- var pathname = window.location.pathname;
- // Add the list item
- $("<li/>").appendTo(stack[0]).append(
- $("<a/>").text(elem.text()).attr("href", pathname + "#" + elem.attr("id"))
- );
+ // the variable pathname was added to the original script.
+ var pathname = window.location.pathname;
+ // Add the list item
+ $("<li/>").appendTo(stack[0]).append(
+ $("<a/>").text(elem.text()).attr("href", pathname + "#" + elem.attr("id"))
+ );
- currentLevel = level;
+ currentLevel = level;
+ }
});
});
}, old = $.fn.toc;