// HI, everyone
// simple to use
// a updated version
//----------------------------------------------------------------------------------------------------------------
// manual & Doc
//
// API just three: sa() ga() ra()
//
//
// sa() set a label, or set many labels; --- NOT modified the
jQuery Object of the current Set
//
// ga() get a label, or many labels, and they add into the
current Set or remove from the current Set
// --------- YES ga() api has modified the jQuery Object of the
current Set
//
// ra() remove a label, or many labels to NULL, clean it; -----
NOT modified the jQuery Object of the current Set
//
// details manual
var storage = cache;
// usage:
// sa("aLabel") // save a label, set a label for
the current Set into storage;
// sa("aLabel", opt_clean ) // set it NULL, clean a label,
in cache
// sa("aL1","aL2","aL3", ..., opt_clean)
// set many labels to NULL, clean them NULL in storage;
// "opt_clean" only accept "opt_clean = null"
// sa() --- NOT modified the jQuery Object of the current Set
// ga("aLabel") // get a label, add it into the
current set
// ga("aL1","aL2","aL3", ... ) // get
many labels, add them into the current set
// ga("aLabel", opt_decrease) // get a label,
decrease it from the current set ;
// ga("aL1","aL2","aL3", ...,
opt_decrease) // get many labels in total, to decrease from the
current set
// "opt_decrease" = boolean true or false or
"-------"any piece
// --------- YES ga() api has modified the jQuery Object of the
current Set
// ra("aLabel") // remove a label in storage, clean it to
NULL
// ra("aL1", 'aL2', "aL3", ... ) //
remove many labels in storage, clean them to NULL
// ra(); // remove all, the storage to be clean empty
// this api --- NOT modified the jQuery Object of the current Set
// further more,
// to input many labels, you can do like this,
// list single
// api ( aL1, aL2, aL3, ... ) as the above
// or array
// api ( [ aL1, aL2, aL3, ...] )
// or mix
// api ( [L1, L2, L3,....], L21, L22, ..... [L31, L32, L33, ....] )
// example
// $(selector).sa(alabel).other_jQuery_api()
// jQuery("a[href]").sa("123").css(...).text()
//
$("p[id^=c11]").ga("123").css(..).on("click", callback).other_api();
// ....more....
// $.ra(); "if you dont need them";
//------------------------------------------------------------------------------------------------------------------
;(function power_mark_current_set(){
-
var cache = {} // storage
-
jQuery.fn.sa = function set_a_label_ON_or_Clean(label,
opt_clean) {
var g = rich_arg(arguments);
if
(g.length == 1) {
cache[label] = this;
}
else if (g.pop() === null) {
g.forEach(function (p, j)
{
if (p || p === 0)
delete
cache[p];
});
} else {}
return
this;
}
-
jQuery.fn.ga = function
get_label_to_addIn_or_decreaseFrom__the_current_set(label,
opt_decrease) {
var g = rich_arg(arguments);
var
last = g.pop();
var out = this;
var action =
"";
if (last === true || last === false || last
== "----" || /^\-+$/.test(last)) {
action =
"not";
} else if (last || last === 0 || last ===
"") {
g.push(last);
action =
"add";
} else {}
if (action) {
g.forEach(function (_label, j) {
if
(_label || _label === 0) {
out =
out[action](cache[_label]);
}
});
}
return out;
}
-
jQuery.fn.ra = function remove_label_from_storage(label)
{
var g = rich_arg(arguments);
if (g.length)
{
g.forEach(function (p, j) {
if (p
|| p === 0)
delete cache[p];
});
} else {
for (var p in cache) {
delete cache[p];
}
}
return this;
}
-
function rich_arg(_arguments) {
var g =
[].slice.call(_arguments);
var out = [].concat.apply([],
g);
return out;
};
-
var meth = ["sa", "ga",
"ra"];
meth.forEach(function (p, j) {
jQuery[p] = function real_handler() {
var g =
[].slice.call(arguments);
var _this = jQuery();
return jQuery.fn[p].apply(_this, g);
};
});
// version 2014-12-06 RC
// my song writer going on ...
})();
//-----------------------------------------------------------------------------------------------
// just, enjoy it
// writing less, do more