Git Product home page Git Product logo

table-link's Introduction

Table Link

Build Status Coverage Status Made with vim

The easiest way to add links in your table rows, cells or elements that are not anchors!

Yeah man... Html can't do that for you out of the box. And it's sad. Very sad.

I KNOW THAT FEEL BRO...

Don't worry bro here is the solution:

Instalation

With npm:

npm install --save table-link

With bower:

bower install --save table-link

Or you can just download a ZIP.

Setup

Browserify
var TableLink = require('table-link');
Browser (Global)
<script src="table-link.min.js"></script>
Some CSS (Optional)
[data-href] {
  cursor: pointer;
}

table [data-href]:hover,
table [data-href]:hover > * {
  background-color: #AAB7D1; // Put whatever color you want... Or none.
}

Usage

In your table:

<tr data-href="http://google.com">
    <td>Some random crazy data.</td>
</tr>

In your Javascript file:

TableLink.init();
// Soooooo simple...

You can make use of blank and self (default) for targeting the link:

<tr data-href="http://google.com" data-target="self">
    <td>Some random crazy data.</td>
</tr>
<tr data-href="http://google.com" data-target="blank">
    <td>Some random crazy data.</td>
</tr>

Using in other elements

Put the selector to find those as the first TableLink.init() parameter like this:
TableLink.init('h1, div, span');
<h1 data-href="http://google.com"></h1>

<div data-href="http://google.com"></div>

<span data-href="http://google.com"></span>

Before and After events

The 'before' event can cancel the link opening by returning false.

The "element" argument is the delegate target, which can be td, tr, th or any element that matches the selector, if it was passed. The "target" argument is the real event target. The sencond can be used to see if the clicked element is the delegated element or some other element inside the delegated element.

TableLink.before(function(element, target) {
    return confirm('Can i open this link?');
});
TableLink.before(function(element, target) {
  // Cancel the action if the clicked element (maybe a cell inside a row[data-href])
  // has the ```.no-link``` class.
  return !target.classList.contains('no-link');
});
TableLink.after(function(element, target) {
    console.log('The link was opened!');
});

License

This repository is under the MIT License

table-link's People

Contributors

brunoti avatar mahezer avatar matheusnaldi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

table-link's Issues

Create a debug mode for better browser visualization and maybe an options feature

It could be activated like:

TableLink.init({debug: true})

Than the selector:

TableLink.init({
  debug: true,
  selector: 'div',
})

Maybe other things:

TableLink.init({
  debug: true,
  selector: '[role="link"]',
  useDefaultSelectors: false,
  defaultAnchorBehavior: true, // Like: middle-click and click pressing ctrl (or cmd) or shift
  delegateContainer: document.body // Maybe also pass a selector like ".tables-with-TableLink"
  before() {},
  after() {}
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.