wildstring
Advanced tools
Comparing version
@@ -0,0 +0,0 @@ /* ============================================================ |
@@ -7,6 +7,8 @@ (function($) { | ||
var container = $(opts.container); | ||
var tocs = []; | ||
var headings = $(opts.selectors, container); | ||
var headingOffsets = []; | ||
var activeClassName = opts.prefix+'-active'; | ||
var activeClassName = 'active'; | ||
var navbarHeight = $('.navbar').height(); | ||
var ANCHOR_PREFIX = "__anchor"; | ||
@@ -17,5 +19,6 @@ var scrollTo = function(e) { | ||
var elScrollTo = $(e.target).attr('href'); | ||
var $el = $(elScrollTo); | ||
var offsetTop = $el.offset().top - navbarHeight; | ||
var $el = $(elScrollTo.replace('#.', '#\\.') + ANCHOR_PREFIX); | ||
var offsetTop = $el.offset().top - (navbarHeight + opts.navbarOffset); | ||
$('body,html').animate({ scrollTop: offsetTop }, 400, 'swing', function() { | ||
@@ -29,2 +32,10 @@ location.hash = elScrollTo; | ||
var calcHadingOffsets = function() { | ||
headingOffsets = []; | ||
headings.each(function(i, heading) { | ||
var top = $(heading).prev("span").offset().top - (navbarHeight + opts.navbarOffset); | ||
headingOffsets.push(top > 0 ? top : 0); | ||
}); | ||
} | ||
//highlight on scroll | ||
@@ -40,6 +51,6 @@ var timeout; | ||
for (var i = 0, c = headingOffsets.length; i < c; i++) { | ||
if (headingOffsets[i] >= top) { | ||
if (headingOffsets[i] >= top || (headingOffsets[i + 1] && headingOffsets[i + 1] > top)) { | ||
$('li', self).removeClass(activeClassName); | ||
if (i > 0) { | ||
highlighted = $('li:eq('+(i-1)+')', self).addClass(activeClassName); | ||
if (i >= 0) { | ||
highlighted = tocs[i].addClass(activeClassName); | ||
opts.onHighlight(highlighted); | ||
@@ -54,3 +65,6 @@ } | ||
$(window).bind('scroll', highlightOnScroll); | ||
highlightOnScroll(); | ||
$(window).bind('load resize', function() { | ||
calcHadingOffsets(); | ||
highlightOnScroll(); | ||
}); | ||
} | ||
@@ -62,8 +76,7 @@ | ||
var ul = $('<ul/>'); | ||
headings.each(function(i, heading) { | ||
var $h = $(heading); | ||
headingOffsets.push($h.offset().top - opts.highlightOffset); | ||
//add anchor | ||
var anchor = $('<span/>').attr('id', opts.anchorName(i, heading, opts.prefix)).insertBefore($h); | ||
var anchor = $('<span/>').attr('id', opts.anchorName(i, heading, opts.prefix) + ANCHOR_PREFIX).insertBefore($h); | ||
@@ -74,3 +87,3 @@ //build TOC item | ||
.attr('href', '#' + opts.anchorName(i, heading, opts.prefix)) | ||
.bind('click', function(e) { | ||
.bind('click', function(e) { | ||
scrollTo(e); | ||
@@ -84,6 +97,13 @@ el.trigger('selected', $(this).attr('href')); | ||
tocs.push(li); | ||
ul.append(li); | ||
}); | ||
el.html(ul); | ||
calcHadingOffsets(); | ||
}); | ||
}; | ||
@@ -99,3 +119,3 @@ | ||
highlightOnScroll: true, | ||
highlightOffset: 100, | ||
navbarOffset: 0, | ||
anchorName: function(i, heading, prefix) { | ||
@@ -102,0 +122,0 @@ return prefix+i; |
@@ -29,3 +29,3 @@ 'use strict'; | ||
destination: 'documentation', | ||
template : 'node_modules/grunt-jsdoc/node_modules/ink-docstrap/template', | ||
template : 'node_modules/ink-docstrap/template', | ||
configure : 'jsdoc.conf.json' | ||
@@ -32,0 +32,0 @@ } |
@@ -270,2 +270,14 @@ 'use strict'; | ||
}); | ||
it('should be able to see the same character as a wildcard', function() { | ||
// Given: a string with the same character multiple times, and a pattern with a wildcard and some of the same character | ||
var pattern = '*zz', | ||
string = 'zzz'; | ||
// When: we call wildstring.match | ||
var result = wildstring.match(pattern, string); | ||
// Then: we should see that they match | ||
assert.equal(result, true); | ||
}); | ||
}); | ||
@@ -272,0 +284,0 @@ |
{ | ||
"name": "wildstring", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "Simple String Wildcard Handling", | ||
@@ -32,2 +32,3 @@ "main": "wildstring.js", | ||
"chai": "^3.2.0", | ||
"grunt": "^0.4.5", | ||
"grunt-cli": "^0.1.13", | ||
@@ -49,5 +50,5 @@ "grunt-contrib-jshint": "^0.11.0", | ||
"mocha": "^2.2.5", | ||
"phantomjs": "^1.9.18", | ||
"phantomjs": "^2.1.0", | ||
"time-grunt": "^1.1.0" | ||
} | ||
} |
@@ -264,2 +264,14 @@ 'use strict'; | ||
}); | ||
it('should be able to see the same character as a wildcard', function() { | ||
// Given: a string with the same character multiple times, and a pattern with a wildcard and some of the same character | ||
var pattern = '*zz', | ||
string = 'zzz'; | ||
// When: we call wildstring.match | ||
var result = wildstring.match(pattern, string); | ||
// Then: we should see that they match | ||
assert.equal(result, true); | ||
}); | ||
}); | ||
@@ -266,0 +278,0 @@ |
@@ -33,3 +33,2 @@ 'use strict'; | ||
rollbackStrings.pop(); | ||
break; | ||
} | ||
@@ -36,0 +35,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
3587120
11.72%55
1.85%131651
6.92%22
4.76%2
100%2
Infinity%