Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List manager #15

Open
jnbdz opened this issue Nov 9, 2015 · 0 comments
Open

List manager #15

jnbdz opened this issue Nov 9, 2015 · 0 comments
Labels

Comments

@jnbdz
Copy link
Member

jnbdz commented Nov 9, 2015

/*

---
description: List manager. Add and remove element in a list created with li's or div's.

license: MIT-style

authors:
- Jean-Nicolas Boulay Desjardins (http://jean-nicolas.name/)

requires:
- core/1.3:   '*'

provides: listManager

...
*/

var listManager = new Class({

Implements: [Options, Events],

options: {
    listElement: 'li', // or any other element...
    rowHTML: '',
    addWhere: 'after', // 'top', 'bottom', 'after', or 'before'
    target: null,
noTargetAddWhere: 'top'
},

initialize: function(el, options){
    this.element = document.id(el);
    this.setOptions(options);
},

add: function(options){

    this.options = Object.merge(this.options, options);

    if (typeOf(this.options.target) !== 'null'){

        var rowPosition = document.id(this.options.target);
        var rowWhere = this.options.addWhere;
        this.options.target = null;

    } else {

        var rowPosition = this.element;
        var rowWhere = this.options.noTargetAddWhere;

    }

    var newRow = new Element(this.options.listElement, {
        'class': 'listmanager-row'
    }).adopt(this.options.rowHTML).inject(rowPosition, rowWhere);

    this.fireEvent('addedRow', [newRow]);

},

remove: function(row){

    var removedRow = row;
    document.id(row).destroy();
    this.fireEvent('removedRow', [removedRow]);

},

removeAll: function(){

    var removedRows = this.element.getChildren('.listmanager-row');
    this.element.empty();
    this.fireEvent('removedAllRows', [removedRows]);

}

});
@jnbdz jnbdz added the Proposal label Nov 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant