mooTagify

tags management.

by Dimitar Christoff

HTML

<script src="https://rawgithub.com/DimitarChristoff/mooTagify/master/Source/js/mootagify.js"></script>
<div class="main">
    <h1>Enter some tags below</h1>
    <div id="tagWrap" class="hide">
        <div class="left tagLock">
            <div class="tag">public<span class="tagClose"></span></div>
        </div>
        <div class="left">
            <input id="listTags" name="listTags" placeholder="+Add tags" />
        </div>

        <div class="clear"></div>
        <div id="errors"></div>
    </div>
    <div>
        <h1>Get the current tag list from the instance</h1>
        <button id="getTags">get tags</button>
    </div>

</div>

CSS

/*generics*/
html { font-size: 100%; overflow-y: scroll; -webkit-overflow-scrolling: touch; -webkit-tap-highlight-color: rgba(0,0,0,0); -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }

body { margin: 0; font-size: 13px; line-height: 1.231; }

body, button, input, select, textarea { font-family: sans-serif; color: #222; }
button, input, select, textarea { font-size: 100%; margin: 0; vertical-align: baseline; *vertical-align: middle; }

input::-webkit-input-placeholder {
    -webkit-appearance: textfield;
    color: #999;
}

:-moz-placeholder {
    color: #999;
}

/*positional generics*/
.left {
    float: left;
}
.clear {
     clear: both;
}
div.main {
    margin:  20px;
}
/*mooTagify specifics*/
#tagWrap {
    margin: 5px;
    margin-bottom: 0;
    margin-top: 10px;
}
div.tagLock {
    height: 20px !important;
    overflow-y: hidden;
}
#listTags {
    padding: 2px;
    width: 250px;
    border: 0;
    background-color: #fff;
}
div.tag {
    position: relative;
    float: left;
    background: #CFDAE7;
    border: 1px solid #6A6A6A;
    border-top: 0;
    border-left: 0;
    padding-top: 2px;
    padding-right: 21px;
    padding-left: 3px;
    font-weight: bold;
    font-size: 14px;
    text-transform: uppercase;
    margin-right: 6px;
    color: #000;
    border-radius: 3px 3px 3px 3px;
    -ms-border-radius: 3px 3px 3px 3px;
    -o-border-radius: 3px 3px 3px 3px;
    -moz-border-radius: 3px 3px 3px 3px;
    -webkit-border-radius: 3px 3px 3px 3px;
    background-image: -moz-linear-gradient(top, #CFDAE7,#899294);
    background-image: -webkit-linear-gradient(top, #CFDAE7,#899294);
    background-image: -o-linear-gradient(top, #CFDAE7,#899294);
    -webkit-background-clip: padding-box;
    text-shadow: 1px 1px 1px rgba(255,255,255,.3);
    -webkit-text-shadow: 1px 1px 1px rgba(255,255,255,.3);
    -moz--text-shadow: 1px 1px 1px rgba(255,255,255,.3);
}
div.tag:hover {
    border: 1px solid #000;
    border-top: 0;
    border-left: 0;
    background:...

JavaScript

// look at resources, references https://raw.github.com/DimitarChristoff/mooTagify/master/Source/js/mooTagify.js
// in domready....

var log = function(message) {
    new Element("div.error", {
        html: message
    }).inject(document.id("errors"), "top");
};

var tagify = new mooTagify(document.id("tagWrap"), null, {
    autoSuggest: false,
    // addOnBlur: false, // only works via enter to add.
    onInvalidTag: function(invalidTag) {
        log(invalidTag + " was rejected due to length");
    },
    onLimitReached: function(rejectedTag) {
        log(rejectedTag + " was not added, you have reached the maximum allowed tags count of " + this.options.maxItemCount);
    }

});
document.id("getTags").addEvent("click", function() {
    console.log(tagify.getTags(), tagify.getTags().join(","));
})