Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

local-links

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

local-links - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

2

package.json
{
"name": "local-links",
"description": "Determine cross-browser if an event or anchor element should be handled locally.",
"version": "1.0.4",
"version": "1.0.5",
"author": "Luke Karrys <luke@lukekarrys.com>",

@@ -6,0 +6,0 @@ "bugs": {

@@ -45,3 +45,3 @@ local-links

local.pathname(document.getElementById('hash')) // null
local.pathname(document.getElementById('googe')) // null
local.pathname(document.getElementById('google')) // null

@@ -52,3 +52,3 @@ // `hash()` will return the hash as a string

local.hash(document.getElementById('hash')) // '#hash'
local.hash(document.getElementById('googe')) // null
local.hash(document.getElementById('google')) // null
```

@@ -55,0 +55,0 @@

@@ -5,3 +5,12 @@ var test = require('tape');

function $(id) {
return document.getElementById(id);
}
function e(id) {
return {
target: $(id)
};
}
function setup(html) {

@@ -12,2 +21,3 @@ var container = document.createElement('div');

'<a id="local" href="/local/page/1">Local</a>',
'<a id="local2" href="/local/page/1">Local2</a>',
'<a id="relative" href="page-2">Relative</a>',

@@ -25,12 +35,26 @@ '<a id="global" href="http://google.com/page/number/1">Global</a>',

function $(id) {
return document.getElementById(id);
function triggerClick(el, modified){
var ev = document.createEvent("MouseEvent");
ev.initMouseEvent(
"click",
true /* bubble */,
true /* cancelable */,
window, null,
0, 0, 0, 0, /* coordinates */
!!modified, false, false, false, /* modifier keys */
0 /*left*/,
null
);
el.dispatchEvent(ev);
}
function e(id) {
return {
target: $(id)
};
function attachClick(el, fn) {
if (el.addEventListener) {
el.addEventListener('click', fn, false);
} else if (el.attachEvent) {
el.attachEvent('onclick', fn);
}
}
domready(function () {

@@ -158,2 +182,54 @@ setup();

});
test('Works on link clicks', function (t) {
var local = $('local');
var global = $('global');
var plan = 2;
var count = 0;
var end = function () {
count++;
if (count === plan) {
t.end();
}
};
t.plan(plan);
attachClick(local, function (event) {
event.preventDefault();
t.equal(localLinks.pathname(event), '/local/page/1');
end();
});
attachClick(global, function (event) {
event.preventDefault();
t.equal(localLinks.pathname(event), null);
end();
});
triggerClick(local);
triggerClick(global);
});
test('Works on modified link clicks', function (t) {
var local = $('local2');
var plan = 1;
var count = 0;
var end = function () {
count++;
if (count === plan) {
t.end();
}
};
t.plan(plan);
attachClick(local, function (event) {
event.preventDefault();
t.equal(localLinks.pathname(event), null);
end();
});
triggerClick(local, true);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc