Skip to content

Instantly share code, notes, and snippets.

@max19931
Forked from makinde/primer.js
Created July 24, 2019 14:01
Show Gist options
  • Save max19931/9609409968761f12ab57796f7c5e79aa to your computer and use it in GitHub Desktop.
Save max19931/9609409968761f12ab57796f7c5e79aa to your computer and use it in GitHub Desktop.

Revisions

  1. @makinde makinde created this gist Apr 23, 2010.
    57 changes: 57 additions & 0 deletions primer.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    !function() {
    var doc = document,
    htm = doc.documentElement,
    lct = null, // last click target
    nearest = function(elm, tag) {
    while (elm && elm.nodeName != tag) {
    elm = elm.parentNode;
    }
    return elm;
    };

    // Listeners for our most common interations
    htm.onclick = function(e) {
    e = e || window.event;
    lct = e.target || e.srcElement;

    var elem = nearest(lct, 'A') || htm,
    href = elem.getAttribute('ajaxify') || elem.href;

    switch (elem.rel) {
    case 'dialog':
    case 'dialog-post':
    Bootloader.loadComponents('dialog', function() {
    Dialog.bootstrap(href, null, elem.rel == 'dialog');
    });
    break;
    case 'async':
    case 'async-post':
    Bootloader.loadComponents('async', function() {
    AsyncRequest.bootstrap(href, elem);
    });
    break;
    default:
    return;
    }

    return false;
    };

    htm.onsubmit = function(e) {
    e = e || window.event;
    var elem = e.target || e.srcElement;

    if (!elem || elem.nodeName != 'FORM' || !elem.getAttribute('ajaxify')) {
    return;
    }

    Bootloader.loadComponents('dom-form', function() {
    bootstrap_form(elem, lct);
    });

    return false;
    };

    // Remove the no JS class, if it is here
    htm.className = htm.className.replace('no_js', '');
    }();