Skip to content

Commit a475d7d

Browse files
committed
First release minimal functionality . Stable.
1 parent b8b7529 commit a475d7d

File tree

3 files changed

+245
-0
lines changed

3 files changed

+245
-0
lines changed

dard.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/dard.js

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/**
2+
* @author Lorand Veres user.email "lorand.mast@gmail.com"
3+
*
4+
*
5+
*/
6+
7+
/*
8+
* Basic comparison
9+
* and other useful functions
10+
*
11+
*/
12+
13+
(function(){
14+
15+
isObj = function(o) {
16+
return typeof obj === 'object' || toString.call(o).split(/\W/)[2].toLowerCase() === 'object';
17+
};
18+
19+
isArray = function(a) {
20+
return Array.isArray(a) || toString.call(a).split(/\W/)[2].toLowerCase() === 'array';
21+
};
22+
23+
isFunc = function (f) {
24+
return typeof f === 'function';
25+
};
26+
27+
varyArgs = function(arguments){
28+
return Array.prototype.slice.call(arguments);
29+
};
30+
31+
argsLength = function(arguments){
32+
return varyArgs(arguments).length;
33+
};
34+
35+
setCss = function(el, css){
36+
var k, f ='';
37+
if(isObj(css)){
38+
for(k in css){
39+
if(css.hasOwnProperty(k))
40+
f += k + ':' + css[k] + ';';
41+
}
42+
el.style.cssText = f;
43+
}
44+
45+
};
46+
47+
toggle = function(el){
48+
if(el.style.display === 'none'){
49+
setCss(el, {display:'block'});
50+
}else{
51+
setCss(el, {display:'none'});
52+
}
53+
};
54+
55+
// Useful Object relating functions
56+
57+
MyObj = {
58+
59+
// Chek if the key exist in the named object
60+
// Return value true or false
61+
62+
keyIn:function(o, k) {
63+
return k.toString(k) in o ? true : false;
64+
},
65+
66+
67+
// Return the size of an object
68+
69+
size:function(o) { // o = object
70+
var count = 0,
71+
key;
72+
if ( count = Object.keys(o).length) {
73+
return count;
74+
} else {
75+
for (key in o) {
76+
o.hasOwnProperty(key) ? count++ : null;
77+
}
78+
return count;
79+
}
80+
}
81+
};
82+
83+
}());// end of basic functions
84+
85+
86+
87+
// the MAIN function
88+
89+
90+
$ = ( function() {
91+
var args = [],
92+
document = window.document,
93+
94+
idRE = /^#{1}[a-z0-9]+\-*$/i, // id REgex
95+
classNameRE = /^\.{1}[a-z0-9\-\_\s]+$/i, // class REgex
96+
tagNameRE = /^<{1}[a-z]+>{1}$/i, // html tag REgex
97+
98+
toType = {},
99+
toString = toType.toString,
100+
extend,
101+
type;
102+
103+
// Helping functions used inside the MAIN return anonymous function
104+
105+
// Helping function
106+
// Selecting the element from first parameter
107+
108+
function getEl(arg, item){
109+
var el;
110+
if ( typeof arg == 'string'){
111+
if(idRE.test(arg)) el = document.getElementById(arg.substring(1));
112+
if(classNameRE.test(arg)) el = document.getElementsByClassName(arg.substring(1))[item];
113+
if(tagNameRE.test(arg)) el = document.getElementsByTagName(arg.replace(/^<+|>+$/gm,''))[item];
114+
}
115+
return el;
116+
}
117+
118+
/*
119+
* Helping function
120+
* Selecting the elementTagName item number from parameters
121+
*
122+
*/
123+
124+
function getElItemNo(arg){
125+
var b;
126+
typeof arg === 'number' ? b = arg : b = 0;
127+
return b;
128+
}
129+
130+
/*
131+
* Helping function
132+
* Selecting the text and css from possible
133+
* second or third parameter handled over
134+
* in a object
135+
*
136+
*/
137+
138+
function getCssText(arg){
139+
var csstext;
140+
if ( arg.length === 2 && isObj(arg[1]))
141+
csstext = arg[1];
142+
if ( arg.length === 3 && isObj(arg[2]))
143+
csstext = arg[2];
144+
return csstext;
145+
}
146+
147+
148+
149+
return function() {
150+
args = varyArgs(arguments);
151+
var el, o, itemNo, key, cssStyle, fcss ='';
152+
153+
if (args.length > 0) {
154+
itemNo = getElItemNo(args[1]);
155+
el = getEl(args[0], itemNo);
156+
o = getCssText(args);
157+
if(isObj(o)){
158+
if(o.text !== undefined || o.hasOwnProprty('text')) el.innerHTML = o.text;
159+
if(o.style !== undefined || o.hasOwnProprty('style')){
160+
setCss(el, o.style);
161+
}
162+
}
163+
return el;
164+
}
165+
};
166+
167+
}());
168+
169+
var text = 'First text tested introduced inside a html element. Also the css style changed. All this using dardjs.';
170+
var css = {width:'95%', height:'45px', margin:'2% 0 2% 0', 'background-color':'#aaa', padding:'1em'};
171+
172+
$("#small", {text: text , style :css });
173+
174+
175+
176+
177+
178+

example/index.html

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
6+
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
7+
Remove this if you use the .htaccess -->
8+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
9+
10+
<title>index</title>
11+
<meta name="description" content="">
12+
<meta name="author" content="Lorand">
13+
14+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
15+
16+
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
17+
<link rel="shortcut icon" href="/favicon.ico type="image/x-icon"">
18+
</head>
19+
20+
<body>
21+
<div id="wrap">
22+
<header>
23+
<h1>index</h1>
24+
</header>
25+
<nav id="nav">
26+
<p class="home">
27+
<a href="/">Home</a>
28+
</p>
29+
<p class="contact">
30+
<a href="/contact">Contact</a>
31+
</p>
32+
</nav>
33+
34+
<div id="content">
35+
<div class="one">
36+
<h2>Div id one</h2>
37+
<p>
38+
Dardjs is a small minimal js framework intendet to be used in small web pages.
39+
It is a very small and fast library, also a good start point to develop your own.
40+
</p>
41+
42+
</div>
43+
<div class ="one">
44+
<h2>Div id two</h2>
45+
<p>
46+
Can be used to understand some basic principles of javascript.
47+
You are free to do what you would like with. Hope you enjoy it.
48+
</p>
49+
<button onclick="toggle($('#nav'));">
50+
toggle links
51+
</button>
52+
</div>
53+
</div>
54+
<div id="small">
55+
Small div
56+
</div>
57+
58+
<footer class="feet">
59+
<p>
60+
&copy; Copyright by Lorand
61+
</p>
62+
</footer>
63+
</div>
64+
<script src="dard.js" type="text/javascript"></script>
65+
</body>
66+
</html>

0 commit comments

Comments
 (0)