UNPKG

nestablejs

Version:

NestableJS is a javascript library for creating drag & drop heirarchical lists.

285 lines (252 loc) 14.7 kB
<!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <link href="https://mobius1.github.io/NestableJS/assets/css/pace.min.css" rel="stylesheet"> <link href="https://mobius1.github.io/NestableJS/assets/fontawesome/css/all.css" rel="stylesheet"> <link rel="stylesheet" href="//cdn.materialdesignicons.com/4.5.95/css/materialdesignicons.min.css"> <link href="https://mobius1.github.io/NestableJS/assets/themify-icons/themify-icons.min.css" rel="stylesheet"> <link href="https://mobius1.github.io/NestableJS/assets/css/metisMenu.min.css" rel="stylesheet"> <link href="https://mobius1.github.io/NestableJS/assets/css/github.min.css" rel="stylesheet"> <link href="https://mobius1.github.io/NestableJS/assets/css/prism.css" rel="stylesheet"> <link href="https://mobius1.github.io/NestableJS/assets/css/style.css" rel="stylesheet"> <link href="https://mobius1.github.io/NestableJS/assets/css/events.css" rel="stylesheet"> <title>NestableJS - DOCS</title> <!-- Favicon --> <link rel="icon" type="image/png" href="https://mobius1.github.io/NestableJS/assets/img/favicon.png" /> </head> <body class="sidebar-layout"> <nav class="navbar navbar-top"> <a class="navbar-brand" href="index-2.html"> <img src="https://mobius1.github.io/NestableJS/assets/img/logo.png" alt=""> </a> <button class="navbar-toggler" type="button" id="sidebarCollapse"> <span class="navbar-toggler-icon"></span> </button> </nav> <nav id="sidebar"> <div class="sidebar-header"> <h3><i class="mdi mdi-format-list-bulleted-square"></i><span>Nestable</span>JS</h3> <div class="dropdown version"> <a class="ver-drop dropdown-toggle" href="#" role="button" id="versionDropdownMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> v0.13.1 </a> <div class="dropdown-menu" aria-labelledby="versionDropdownMenu"> <div>Versions</div> </div> </div> <div class="form-group has-search"> <span class="ti-search form-control-feedback"></span> <input type="text" class="form-control" placeholder="Search docs ..."> </div> <!-- /.Actual search box --> </div> <ul class="metismenu sidebarMenu list-unstyled" id="sidebarMenu"> <li><a href="https://mobius1.github.io/SelectableJS/index.html">Home</a></li> <li> <a class="has-arrow" href="#" aria-expanded="false">Overview</a> <ul aria-expanded="false"> <li><a href="api/index.html">Introduction</a></li> <li><a href="api/getting-started.html">Getting Started</a></li> </ul> </li> <li class="active"> <a class="has-arrow" href="api/#" aria-expanded="true">API</a> <ul aria-expanded="true"> <li> <a class="has-arrow" href="api/options.html">Options</a> <ul aria-expanded="true"> </ul> </li> <li> <a href="api/public-methods.html">Public Methods</a> <ul aria-expanded="true"> </ul> </li> <li><a href="api/events.html">Events</a><ul></ul></li> </ul> </li> </ul> </nav> <!-- /.End of Sidebar Holder --> <div class="page-content"> <div class="content-wrapper"> <div class="row"> <div class="col-md-9 content"> <nav aria-label="breadcrumb"> <ol class="breadcrumb"> <li class="breadcrumb-item"><a href="#">Home</a></li> <li class="breadcrumb-item"><a href="#">API</a></li> <li class="breadcrumb-item active"><a href="#">Events</a></li> </ol> </nav> <!-- /.End of breadcrumb --> <div class="doc-content"> <h1 class="logo-title"><i class="mdi mdi-format-list-bulleted-square"></i> Events</h1> <hr /> <p>Nestable fires a number of custom events that you can listen for.</p> <p>You can attach a number of custom event listeners using the <a href="api/methods/on.html"><code>on()</code></a> method and pass the event name and a callback as the first two arguments:</p> <pre><code class="javascript language-javascript">const instance = new Nestable("#myList"); instance.on('XXXX', fn); </code></pre> <p>Event listeners can be detached by calling the <a href="api/methods/off.html"><code>off()</code></a> method with the same arguments:</p> <pre><code class="javascript language-javascript">instance.off('XXXX', fn); </code></pre> <hr /> <p>Both the <code>on()</code> and <code>off()</code> methods function the same as the native <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener"><code>addEventListener</code></a> and <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener"><code>removeEventListener</code></a> methods respectively. </p> <p>This means that in order to remove a custom event listener from the instance, you must pass the same <a href="https://developer.mozilla.org/en-US/docs/web/JavaScript/Reference/Operators/function">function expression</a> to the <code>off()</code> method as you did to the <code>on()</code> method - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function">declared / anonymous functions</a> cannot be removed.</p> <h3 id="incorrect">Incorrect</h3> <pre><code class="javascript language-javascript">instance.on('stop', () =&gt; { counter.innerHTML = selected.length; }); </code></pre> <h3 id="correct">Correct</h3> <pre><code class="javascript language-javascript">const updateDisplay = () =&gt; { counter.innerHTML = selected.length; }; // attach the event listener instance.on('stop', updateDisplay); // detach the event listener instance.off('stop', updateDisplay); </code></pre> <hr /> <h2 id="eventreference">Event reference</h2> <table class="table table-striped table-bordered"> <thead> <tr> <th>Event Name</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><a href="api/events/init.html"><code>init</code></a></td> <td>Fires when the instance is ready to be used.</td> </tr> <tr> <td><a href="api/events/start.html"><code>start</code></a></td> <td>Fired on mousedown / touchstart.</td> </tr> <tr> <td><a href="api/events/move.html"><code>move</code></a></td> <td>Fired on mousemove / touchmove.</td> </tr> <tr> <td><a href="api/events/stop.html"><code>stop</code></a></td> <td>Fired on mouseup / touchend.</td> </tr> <tr> <td><a href="api/events/nest.html"><code>nest</code></a></td> <td>Fired when an item is nested.</td> </tr> <tr> <td><a href="api/events/unnest.html"><code>unnest</code></a></td> <td>Fired when an item is unnested.</td> </tr> <tr> <td><a href="api/events/reorder.html"><code>reorder</code></a></td> <td>Fired when an item is reordered.</td> </tr> <tr> <td><a href="api/events/error.maxdepth.html"><code>error.maxdepth</code></a></td> <td>Fires when nesting is attemped when max nesting is already reached.</td> </tr> <tr> <td><a href="api/events/error.disabled.html"><code>error.disabled</code></a></td> <td>Fires when dropping or nesting is attemped in a disabled item.</td> </tr> <tr> <td><a href="api/events/error.collapsed.html"><code>error.collapsed</code></a></td> <td>Fires when nesting is attemped in a collapsed item.</td> </tr> <tr> <td><a href="api/events/error.confined.html"><code>error.confined</code></a></td> <td>Fires when attempting to move a confined item out of it's parent.</td> </tr> </tbody> </table> <hr /> <h5 id="demo">Events Demo</h5> <div id="container-demo"> <p> <ol id="myList" class="list"> <li data-id="1" class="item">Item 1</li> <li data-id="2" class="item">Item 2 <ol> <li data-id="3" class="item">Item 3</li> <li data-id="4" class="item">Item 4 <ol> <li data-id="5" class="item">Item 5</li> <li data-id="6" class="item">Item 6</li> </ol> </li> </ol> </li> <li data-id="7" class="item">Item 7</li> <li data-id="8" class="item">Item 8</li> <li data-id="9" class="item">Item 9 <ol> <li data-id="10" class="item">Item 10</li> <li data-id="11" class="item">Item 11</li> </ol> </li> <li data-id="12" class="item">Item 12</li> </ol> </p> <p> <h5>Events</h5> <div id="events"></div> </p> </div> <hr /> </div> <!-- /.End of documentation text content --> <div class="footer-btn d-flex justify-content-between"> <a href="recalculate.html" class="btn"><i class="fas fa-arrow-circle-left"></i>Previous</a> <a href="off.html" class="btn">Next<i class="fas fa-arrow-circle-right"></i></a> </div> <!-- /.End of footer button --> </div> <div class="col-md-3 d-none d-sm-none d-md-block rightSidebar"> <ul class="section-nav" id="section-nav"> </ul> <!-- /.End of section nav --> </div> </div> </div> <footer class="site-footer"> <div class="row align-items-center "> <div class="col-md-7 order-md-first order-last"> <div class="Copyright-text"> <p class="m-0">Copyright © 2018 <a href="#" target="_blank">Karl Saunders</a>. All rights reserved. </p> <p class="m-0 d-none d-sm-block">Built with <a href="#" target="_blank">bdtask </a> using a <a href="#" target="_blank">theme</a> provided by <a href="#" target="_blank">docBanao.</a></p> </div> </div> <div class="col-md-5"> <ul class="footer-menu"> <li><a href="#">Terms of use </a></li> <li><a href="changelog.html">Changelog</a></li> </ul> </div> </div> </footer><!-- /.End of site footer --> </div><!-- /.Page Content Holder --> <!-- Optional JavaScript --> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> <script src="https://mobius1.github.io/NestableJS/assets/js/pace.min.js"></script> <script src="https://mobius1.github.io/NestableJS/assets/js/jquery.dd.min.js"></script> <script src="https://mobius1.github.io/NestableJS/assets/js/metisMenu.min.js"></script> <script src="https://mobius1.github.io/NestableJS/assets/js/ResizeSensor.min.js"></script> <script src="https://mobius1.github.io/NestableJS/assets/js/theia-sticky-sidebar.min.js"></script> <script type="text/javascript" src="https://mobius1.github.io/NestableJS/assets/js/prism.min.js"></script> <script id="main-js" type="text/javascript" src="https://unpkg.com/nestablejs@0.2.0/dist/nestable.js"></script> <script src="https://mobius1.github.io/NestableJS/assets/js/script.js"></script> <script src="https://mobius1.github.io/NestableJS/assets/js/events.js"></script> </body> </html>