Skip to content

Commit b8b7529

Browse files
committed
ready the first minimal release
1 parent 71929a1 commit b8b7529

File tree

3 files changed

+79
-218
lines changed

3 files changed

+79
-218
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# bikini.js
1+
# dard.js

dard.js

Lines changed: 78 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,73 @@
11
/**
22
* @author Lorand Veres user.email "lorand.mast@gmail.com"
33
*
4-
*
5-
* Select elements by ID , CLASSNAME, TAGNAME
6-
*
7-
* PARAMETER 1 selector should be in the following formats: #ID , .CLASSNAME , TAGNAME
8-
* PARAMETER 2 Optinal, item number should be digit
9-
* PARAMETER 3 Optional, text, attributs and css should be of the format of
10-
*
11-
* Syntax
12-
* $('.className', 0, {text:'text', id:'yourId', style:{bgcolor:blue, font-size:14px}})
13-
*
144
*
155
*/
166

17-
var start, end, $;
18-
start = Date().now || new Date().getTime();
19-
20-
$ = ( function() {
21-
var selector,
22-
args = [],
23-
document = window.document,
24-
25-
idRE = /^#{1}[a-z0-9]+\-*$/i, // id REgex
26-
classNameRE = /^\.{1}[a-z0-9\-\_\s]+$/i, // class REgex
27-
tagNameRE = /^<{1}[a-z]+>{1}$/i, // html tag REgex
28-
29-
$ = {},
30-
fn,
31-
Obj,
32-
toType = {},
33-
toString = toType.toString,
34-
extend,
35-
type;
36-
7+
378
/*
389
* Basic comparison
39-
* and other small useful functions
10+
* and other useful functions
4011
*
4112
*/
42-
43-
function isObj(o) {
13+
14+
(function(){
15+
16+
isObj = function(o) {
4417
return typeof obj === 'object' || toString.call(o).split(/\W/)[2].toLowerCase() === 'object';
45-
}
18+
};
4619

47-
function isArray(a) {
20+
isArray = function(a) {
4821
return Array.isArray(a) || toString.call(a).split(/\W/)[2].toLowerCase() === 'array';
49-
}
22+
};
5023

51-
function isFunc(f) {
24+
isFunc = function (f) {
5225
return typeof f === 'function';
53-
}
26+
};
5427

55-
function varyArgs(arguments){
28+
varyArgs = function(arguments){
5629
return Array.prototype.slice.call(arguments);
57-
}
30+
};
5831

59-
function argsLength(arguments){
32+
argsLength = function(arguments){
6033
return varyArgs(arguments).length;
61-
}
62-
63-
/*
64-
* Useful Object relating functions
65-
*
66-
*/
67-
68-
Obj = function(){
34+
};
35+
36+
setCss = function(el, css){
37+
var k, f ='';
38+
if(isObj(css)){
39+
for(k in css){
40+
if(css.hasOwnProperty(k))
41+
f += k + ':' + css[k] + ';';
42+
}
43+
el.style.cssText = f;
44+
}
6945

70-
/*
71-
* Chek if the key exist in the maned object
72-
* Return true or false
73-
* Usage Obj.keyIn(objectName , "keyToLookFor")
74-
*/
46+
};
47+
48+
toggle = function(el){
49+
if(el.style.display === 'none'){
50+
setCss(el, {display:'block'});
51+
}else{
52+
setCss(el, {display:'none'});
53+
}
54+
};
55+
56+
// Useful Object relating functions
57+
58+
MyObj = {
7559

76-
this.keyIn = function(o, k) {
60+
// Chek if the key exist in the named object
61+
// Return value true or false
62+
63+
keyIn:function(o, k) {
7764
return k.toString(k) in o ? true : false;
78-
};
65+
},
7966

80-
/*
81-
* Return the size of an object
82-
* Usage Obj.size(object);
83-
*/
84-
this.size = function(o) { // o = object
67+
68+
// Return the size of an object
69+
70+
size:function(o) { // o = object
8571
var count = 0,
8672
key;
8773
if ( count = Object.keys(o).length) {
@@ -92,76 +78,39 @@ start = Date().now || new Date().getTime();
9278
}
9379
return count;
9480
}
95-
};
96-
97-
this.keyInline = function(o, callback) {
98-
var p,
99-
kn = [];
100-
for (p in o) p in o ? typeof callback !== undefined && !isObj(o) ? callback(o[p]) : kn.push(p.toString(p)) : kn = false;
101-
return kn;
102-
};
103-
104-
this.keyDeep = function(o) {
105-
var p,
106-
kn = [];
107-
for (p in o) {
108-
if (!isObj(o[p])) {
109-
kn.push(p.toString(p));
110-
} else if (isObj(o[p])) {
111-
kn.push(this.keyDeep(o[p]));
112-
}
113-
}
114-
return kn;
115-
};
116-
117-
this.keyValue = function(o, k) {
118-
return k.toString(k) in o ? o[k.toString(k)] : false;
119-
};
120-
};// end objKeyName
121-
this.Obj = new Obj();
122-
123-
124-
function Ajax() {
125-
return;
126-
}
127-
128-
/*
129-
* Helping functions used inside the MAIN return anonymous function
130-
*
131-
*/
132-
133-
extend = function(obj) {
134-
if ( typeof Object.assign === 'function') {
135-
return Object.assign({}, obj);
13681
}
13782
};
83+
84+
}());// end of basic functions
85+
86+
87+
88+
// the MAIN function
89+
90+
91+
var $ = ( function() {
92+
var args = [],
93+
document = window.document,
13894

95+
idRE = /^#{1}[a-z0-9]+\-*$/i, // id REgex
96+
classNameRE = /^\.{1}[a-z0-9\-\_\s]+$/i, // class REgex
97+
tagNameRE = /^<{1}[a-z]+>{1}$/i, // html tag REgex
98+
99+
toType = {},
100+
toString = toType.toString,
101+
extend,
102+
type;
139103

140-
/*
141-
* Helping function
142-
* A primitive yet practical metod
143-
* Assigning functions to the window object
144-
*/
145-
fn = function () {
146-
this.isObj = isObj;
147-
this.isArray = isArray;
148-
this.isFunc = isFunc;
149-
this.varyArgs = varyArgs;
150-
this.argsLength = argsLength;
151-
};
152-
153-
154-
/*
155-
* Helping function
156-
* Selecting the element from first parameter
157-
*
158-
*/
104+
// Helping functions used inside the MAIN return anonymous function
159105

106+
// Helping function
107+
// Selecting the element from first parameter
108+
160109
function getEl(arg, item){
161110
var el;
162111
if ( typeof arg == 'string'){
163112
if(idRE.test(arg)) el = document.getElementById(arg.substring(1));
164-
if(classNameRE.test(arg)) el = document.getElementsByClassName(arg.substring(1));
113+
if(classNameRE.test(arg)) el = document.getElementsByClassName(arg.substring(1))[item];
165114
if(tagNameRE.test(arg)) el = document.getElementsByTagName(arg.replace(/^<+|>+$/gm,''))[item];
166115
}
167116
return el;
@@ -174,8 +123,9 @@ start = Date().now || new Date().getTime();
174123
*/
175124

176125
function getElItemNo(arg){
177-
if(typeof arg == 'number')
178-
return arg;
126+
var b;
127+
typeof arg === 'number' ? b = arg : b = 0;
128+
return b;
179129
}
180130

181131
/*
@@ -199,56 +149,22 @@ start = Date().now || new Date().getTime();
199149

200150
return function() {
201151
args = varyArgs(arguments);
202-
fn();
203-
var el, o;
152+
var el, o, itemNo, key, cssStyle, fcss ='';
204153

205154
if (args.length > 0) {
206155
itemNo = getElItemNo(args[1]);
207156
el = getEl(args[0], itemNo);
208157
o = getCssText(args);
209158
if(isObj(o)){
210-
if(o.text !== undefined) el.innerHTML = o.text;
211-
if(o.style){
212-
//console
159+
if(o.text !== undefined || o.hasOwnProprty('text')) el.innerHTML = o.text;
160+
if(o.style !== undefined || o.hasOwnProprty('style')){
161+
setCss(el, o.style);
213162
}
214163
}
215164
return el;
216165
}
217166
};
218167

219168
}());
220-
221-
222-
/*
223-
( function() {
224-
if (Dard !== undefined && Dard == window.Dard ) {
225-
if (typeof $ !== undefined) {
226-
var $ = Dard;
227-
}
228-
}
229-
}());
230-
*/
231-
232-
233-
var a = '#one', d, e,
234-
ade = {
235-
text : 'text text aditional to add',
236-
id : 'yourId',
237-
style : {
238-
bgcolor : 'blue',
239-
fontsize : '14px'
240-
}
241-
};
242-
$('#one', {text: 'first text tested'});
243-
//if(d = $('<div>', 2, {text: 'first text tested'})) d.innerHTML = "<p>Dard.js is a small and good function </p>";
244-
//c[ c.length -1 ].innerHTML = "that's a div 3 text.";
245-
246-
247-
//if(e = $('#small'))e.innerHTML = "that's just a note around footer area.";
248-
249-
250-
251-
end = Date.now() || new Date().getTime();
252-
console.log((end - start) + ' miliseconds = time to load the js inside');
253169

254170

index.html

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)