Professional Documents
Culture Documents
CCCM (1e) PDF
CCCM (1e) PDF
Bhagat Singh
23 March 1931
2
Small Program Library
3
Part I
Programs
5
Chapter 1
Basic Programs
1.1 Calculate the Simple Interest and Compound Interest using a computer program?
1.2 marathon.c
#i n c l u d e < s t d i o . h>
int main ( v o i d )
{
int miles , yards ;
float kilometers ;
miles = 26;
yards = 385;
kilometers = 1.609 ∗ ( miles + yards / 1760.0);
p r i n t f ( " \ nA marathon i s %f k i l o m e t e r s . \ n\n " , kilometers );
return 0;
}
7
8 CHAPTER 1. BASIC PROGRAMS
Projects
9
Part II
11
13
The project was later renamed tobu (with a new noticeboard image ) in it's later run at IIT Delhi while i was the Administrator. Near closure , it was
handled by kala guy for one day owing to his bullying while on that day also it was installed by me only although he requested the technique of setting up the
project be explained to him. Our team totally discredits them as all the contact email-id's had other names that day(As per law code can't be copyrighted). In
my presence , the ownership circulated amongst Shitiz Bansal, Vikas Rana ,Rahul Jain(of Jwala), 2 Vivek Maliks ( one Raj(original amongst those two)and one
Pig Nishant Kumar(the copy)) and Vivek Shrivastav although Vivek was the name they were taking all the time, probably of Niraj Patel as setting the project
was dicult and it was not possible for those people without Niraj Patel to set it up on the server (if crashed).
Programmed by Bill (Babbar Bhangoo) and discssed by him at Nahan, Problem Question worked on by Rajat (kalia). (2002 onwards)
/ / The driver . c file of Todarmal project to be stored in " src " folder
#i n c l u d e " m y u t i l . h"
#i n c l u d e <s y s / s t a t . h>
#i n c l u d e < d i r e n t . h>
s u c c e s s=p p r o t e c t =0;
// p p r o t e c t = password protect
s t r c p y ( mpoint , " / mnt/tmp/ mpoint_ " ) ;
s t r c a t ( mpoint , p i d ) ;
s t r c p y ( t r e e f i l e , " . . / f i l e s /tmp/ t r e e _ " ) ;
s t r c a t ( t r e e f i l e , pid ) ;
r e t=m k d i r ( mpoint , S_IRUSR | S_IWUSR | S_IXUSR ) ;
i f ( r e t <0)
perror (" Error in creating mount pt ");
s t r c p y ( command , " / b i n / tobumount ");
s t r c a t ( command , i p ) ;
s t r c a t ( command , " \"");
s t r c a t ( command , name ) ;
s t r c a t ( command , " \ " \"");
s t r c a t ( command , s h a r e ) ;
s t r c a t ( command , " \ " ");
s t r c a t ( command , p i d ) ;
f p=popen ( command , " r " ) ;
// mount and see output of smbmount
i f ( f p==NULL)
p e r r o r ( " smbmount pipe error ");
w h i l e ( f g e t s ( command , 2 5 6 , f p ) ! =NULL)
{
// i f ( ( c h a r ∗ ) s t r s t r ( command , " ERRbadpw" ) ! =NULL
// | | ( c h a r ∗ ) s t r s t r ( command , " ERRnoaccess " ) ! =NULL)
i f ( ( char ∗ ) s t r s t r ( command , " ERRbadpw" ) ! =NULL)
p p r o t e c t =1;
// has got some passwd
else p r i n t f ( "SMBMNTOUT : %s " , command ) ;
}
/ / i f ( p p r o t e c t ==1)
// p r i n t f ("% s (% s ) −> %s is passwd p r o t e c t e d \ n " , i p , name , s h a r e ) ;
pclose ( fp ) ;
f p=f o p e n ( " / p r o c / mounts " , " r " ) ;
// read / p r o c / mounts to see if u have been able to mount the share
i f ( f p==NULL)
perror (" Error Can ' t read / p r o c / mounts ");
w h i l e ( f g e t s ( command , 2 5 6 , f p ) ! =NULL)
{
i f ( ( char ∗ ) s t r s t r ( command , p i d ) ! =NULL)
s u c c e s s =1; // so we have mounted that share
}
f c l o s e ( fp ) ;
i f ( success || pprotect )
{
14
i f ( s u c c e s s ==1)
{
p r i n t f (" Building t r e e %s (% s ) −> %s \ n " , i p , name , s h a r e ) ;
f f l u s h ( stdout ) ;
}
s t r c p y ( command , " . / t r e e ");
s t r c a t ( command , m p o i n t ) ; // local mount point
s t r c a t ( command , " > ");
s t r c a t ( command , t r e e f i l e ) ;
s y s t e m ( command ) ; // build tree
s t r c p y ( command , " / b i n / t o b u f r e e "); // a root setuid script
s t r c a t ( command , p i d ) ;
i f ( s u c c e s s ==1)
{
s y s t e m ( command ) ; // umount mpoint
}
}
r e t=r m d i r ( m p o i n t ) ; // remove local mount pt
i f ( r e t <0)
perror (" Error in removing mount pt ");
return ( success || pprotect ) ;
}
∗ i f comp i s c o n n e c t e d . . .
∗ then s h a r e s are w r i t t e r n i n . . / f i l e s / s h a r e s / i p
∗ and t r e e o f s h a r e s i s b u i l t i n n e x t s t a g e
∗ t h i s s t a g e a l s o d e l e t e s t h e t r e e f i l e s which c o r r e s p o n d to ...
∗ s h a r e d f o l d e r s w h i c h a r e no l o n g e r s h a r e d
∗/
FILE ∗ f p ;
DIR ∗ dp ;
struct dirent ∗ dinfo ;
c h a r f i l e n a m e [ 2 5 6 ] , ∗ f i l e i p , ∗ f i l e s h a r e , command [ 2 5 6 ] ;
s t r u c t l i s t n o d e ∗p , ∗ f i l e l i s t ;
f i l e l i s t =p=NULL ;
strcpy ( filename , " . . / f i l e s / shares /");
s t r c a t ( filename , ip ) ;
f p=f o p e n ( f i l e n a m e , " w " ) ;
// write list of shares ...
i f ( f p==NULL) {
f p r i n t f ( stderr , " Error Can ' t write shares f o r %s " , i p ) ;
perror ("");
return ;
}
// null list implies empty shares file
// as file was opened w i t h MODE "w"
f o r ( p= s h a r e l i s t ; p !=NULL ; p=p−>n e x t )
f p r i n t f ( f p ,"% s \ n " , p−>k e y ) ;
f c l o s e ( fp ) ;
dp=o p e n d i r ( " . . / f i l e s / t r e e " ) ;
i f ( dp==NULL)
perror (" Error Can ' t open dir ( sync share list ) ");
w h i l e ( d i n f o=r e a d d i r ( dp ) ) {
i f ( s t r c m p ( d i n f o −>d_name , " . " ) = = 0 || s t r c m p ( d i n f o −>d_name , " . . " ) = = 0 )
continue ; // skip these two files
f i l e l i s t = a d d t o l i s t ( f i l e l i s t , d i n f o −>d_name , " " ) ;
} c l o s e d i r ( dp ) ;
f o r ( p= f i l e l i s t ; p !=NULL ; p=p−>n e x t )
{
s t r c p y ( f i l e n a m e , p−>k e y ) ; // filename has format i p _ a d d r e s s%s h a r e n a m e
f i l e i p =( c h a r ∗ ) s t r t o k ( f i l e n a m e ,"%\ n " ) ;
i f ( strcmp ( f i l e i p , i p ) ! = 0 ) continue ;
f i l e s h a r e =( c h a r ∗ ) s t r t o k (NULL,"%\ n " ) ;
i f ( ( char ∗) s e a r c h l i s t ( s h a r e l i s t , f i l e s h a r e )==NULL)
{
p r i n t f ( " Removing %s : no longer s h a r e d \ n " , p−>k e y ) ;
s t r c p y ( command , " rm \"");
s t r c a t ( command , " . . / f i l e s / t r e e / " ) ;
s t r c a t ( command , p−>k e y ) ;
s t r c a t ( command , " \ " " ) ;
s y s t e m ( command ) ;
}
} freelist ( f i l e l i s t ); // regain memory }
struct listnode ∗ f i n d s h a r e s ( c h a r ∗ name , c h a r ∗ i p )
{
struct listnode ∗ s h a r e l i s t =NULL ;
char command [ 2 5 6 ] , i n p u t [ 2 5 6 ] ;
FILE ∗ pipe ;
int s u c c e s s =0;
s t r c p y ( command , " s m b c l i e n t −L \"");
s t r c a t ( command , name ) ;
s t r c a t ( command , " \ " −I ");
s t r c a t ( command , i p ) ;
s t r c a t ( command , " −N " ) ;
p i p e=popen ( command , " r " ) ; / / command used as junk space below
w h i l e ( f g e t s ( i n p u t , 2 5 6 , p i p e ) ! =NULL)
{ // add some smart error parsing here
i f ( ( char ∗) s t r s t r ( input , " Domain =")!=NULL
&& ( c h a r ∗) s t r s t r ( input , " OS=")!=NULL
&& ( c h a r ∗) s t r s t r ( input , " S e r v e r =")!=NULL)
s u c c e s s =1;
i f ( ( char ∗) s t r s t r ( input , " Sharename " ) ! =NULL
&& ( c h a r ∗) s t r s t r ( input , " Type " ) ! =NULL
&& ( c h a r ∗) s t r s t r ( input , " Comment " ) ! =NULL)
s u c c e s s =1;
s t r c p y ( command , i p ) ;
s t r c a t ( command , " : 1 3 9 " ) ;
i f ( ( char ∗) s t r s t r ( input , command ) ! =NULL
&& ( c h a r ∗) s t r s t r ( input , " ( Connection r e f u s e d " ) ! =NULL)
s u c c e s s =1; // so connection was refused
i f ( ( char ∗) s t r s t r ( input ," Called name not p r e s e n t " ) ! =NULL)
// this happens when name of the system has changed
// Sharry says split the lines here but alas program would stop working , kindly regroup at convenience . . . .
s t r c p y ( command , " rm . . / f i l e s / names / " ) ;
s t r c a t ( command , i p ) ;
s y s t e m ( command ) ;
// name of comp removed
16
t i m e (& c t i m e ) ;
i f ( ( r e t >=0)
&& ( c t i m e − f i l e b u f . st_mtime < 3 6 0 0 ∗ 4 )
&& ( s t r c m p ( a r g v [ 2 ] , " −1")!=0))
{
// we have info about shares
f p=f o p e n ( f i l e n a m e , " r " ) ;
i f ( f p==NULL)
{
f p r i n t f ( stderr , " Error in reading old shares o f %s " , i p ) ;
perror ("");
exit (1);
}
w h i l e ( f g e t s ( s h a r e n a m e , 2 5 6 , f p ) ! =NULL)
{
rem_spaces ( sharename ) ;
i f ( strcmp ( sharename ,"")==0) continue ;
// now sharename has no traling spaces
s h a r e l i s t=a d d t o l i s t ( s h a r e l i s t , sharename , " " ) ;
}
f c l o s e ( fp ) ;
}
else
{
p r i n t f (" Finding share list o f %s (% s ) \ n " , i p , name ) ;
s h a r e l i s t =f i n d s h a r e s ( name , i p ) ;
} i f ( s h a r e l i s t==NULL) exit (0); // sharelist is NULL
// cool ... we have the share list .. time to build tree .
f o r ( p= s h a r e l i s t ; p !=NULL ; p=p−>n e x t )
{
strcpy ( filename , " . . / f i l e s / tree /");
s t r c a t ( filename , ip ) ;
s t r c a t ( filename ,"%");
s t r c a t ( f i l e n a m e , p−>k e y ) ;
r e t=s t a t ( f i l e n a m e ,& f i l e b u f ) ;
t i m e (& c t i m e ) ;
i f ( ( r e t >=0) && ( c t i m e − f i l e b u f . st_mtime < 3 6 0 0 ∗ 6 )
&& ( s t r c m p ( a r g v [ 2 ] , " −1")!=0))
continue ; // skip this share
p r i n t f ( " Attempt to mount %s (% s ) −> %s \ n " , i p , name , p−>k e y ) ;
s p r i n t f ( p i d j u n k ,"% d " , ( i n t ) g e t p i d ( ) ) ;
r e t=b u i l d t r e e ( p−>key , name , i p , p i d j u n k ) ;
i f ( r e t ==0)
continue ; // comp was not connected
s t r c p y ( f i l e n a m e , " . . / f i l e s /tmp/ t r e e _ " ) ;
s t r c a t ( filename , pidjunk ) ;
s t r c p y ( command , " mv ");
s t r c a t ( command , f i l e n a m e ) ; // tree file
s t r c a t ( command , " \"");
strcpy ( filename , " . . / f i l e s / tree /");
s t r c a t ( filename , ip ) ;
s t r c a t ( filename ,"%");
s t r c a t ( f i l e n a m e , p−>k e y ) ;
s t r c a t ( command , f i l e n a m e ) ;
s t r c a t ( command , " \ " " ) ;
s y s t e m ( command ) ;
}
freelist ( sharelist );
}
This program is basically blackia deamon looped over the entire hostel network.
18
Part III
19
21
r e p o r t c a r d . php
<!DOCTYPE h t m l PUBLIC " − //W3C/ /DTD XHTML 1 . 0 T r a n s i t i o n a l / /EN" " h t t p : / /www . w3 . o r g /TR/ x h t m l 1 /DTD/ xhtml1 − t r a n s i t i o n a l . d t d">
<h t m l x m l n s=" h t t p : / /www . w3 . o r g / 1 9 9 9 / x h t m l">
<head>
<meta h t t p − e q u i v ="C o n t e n t −Type " c o n t e n t =" t e x t / h t m l ; c h a r s e t=u t f −8" />
<?php $dbname = ' r a j a t k a l _ a c t ' ;
$ l i n k=m y s q l i _ c o n n e c t ( " l o c a l h o s t " , " r a j a t k a l _ r k " , " ManasI4URajat " )
or d i e ( " Couldn ' t make connection . " ) ;
$db = m y s q l i _ s e l e c t _ d b ( $ l i n k , $dbname )
or d i e ( " Couldn ' t select database " ) ;
$result = mysqli_query ( $ l i n k , 'SELECT ∗ FROM s t u r e c o r d where r o l l n o = " ' .$_GET [ ' r o l l n o ' ] . ' " ' )
or d i e (" Fetch Failed :" . mysql_error ( ) ) ;
echo ' Report Card of − ';
while ( $row = m y s q l i _ f e t c h _ a r r a y ( $ r e s u l t , MYSQLI_ASSOC ) )
{
echo $row [ " name " ] ;
}
$ r e s u l t 2 = mysqli_query ( $ l i n k , 'SELECT ∗ FROM t e s t r e c where r o l l n o = " ' .$_GET [ ' r o l l n o ' ] . ' " ' ) or d i e (" Fetch Failed :" . mysql_error ( )
echo '< t a b l e > ' ;
$score = 0;
echo '< t r ><td>T e s t ID</td><td>Marks</td><td>Maximum Marks</td><td>P e r c e n t a g e </td ></t r > ' ;
while ( $row2 = m y s q l i _ f e t c h _ a r r a y ( $ r e s u l t 2 , MYSQLI_ASSOC ) )
{
$ p e r c e n t a g e = 1 0 0 ∗ $row2 [ " marks " ] / $row2 [ " t e s t t o t a l m a r k s " ] ;
echo '< t r ><td><a h r e f =" h t t p s : / /www . a l p h a c l a s s e s . com/ com par e . php ? tname = ' . $row2 [ " tname " ] . ' " > ' . $row2 [ " tname " ] .
' </ a></td><td > ' . $row2 [ " marks " ] . ' < / td><td > ' . $row2 [ " t e s t t o t a l m a r k s " ] . ' < / td><td > ' . $ p e r c e n t a g e . ' < / t r > ' ;
$ r e s u l t 4 = mysqli_query ( $ l i n k , 'UPDATE t e s t r e c SET percentage =" '. $percentage . ' " where r o l l n o = " ' .$_GET [ ' r o l l n o ' ] .
' " AND tname = " ' . $row2 [ " tname " ] . ' " ' ) or d i e (" Fetch Failed :" . mysql_error ( ) ) ;
$score = $score + $row2 [ " g r a d e n o r m a l i z e d " ] ∗ $row2 [ " c r e d i t s " ] ;
}
$ r e s u l t 3 = mysqli_query ( $ l i n k , 'UPDATE s t u r e c o r d SET s c o r e =" '. $ s c o r e . ' " where r o l l n o =" '.
$_GET [ ' r o l l n o ' ] . ' " ' ) or d i e (" Fetch Failed :" . mysql_error ( ) ) ;
echo ' </ t a b l e >
<i f r a m e w i d t h=80% h e i g h t =65% s r c =" h t t p s : / /www . a l p h a c l a s s e s . com/ g u e s t b o o k . php ? i d = ' .$_GET[ " r o l l n o " ] . ' " >
</ i f r a m e > ' ;
?>
s t u d e n t s . php
<!DOCTYPE h t m l PUBLIC " − //W3C/ /DTD XHTML 1 . 0 T r a n s i t i o n a l / /EN" " h t t p : / /www . w3 . o r g /TR/ x h t m l 1 /DTD/ xhtml1 − t r a n s i t i o n a l . d t d">
<h t m l x m l n s=" h t t p : / /www . w3 . o r g / 1 9 9 9 / x h t m l">
<head>
<meta h t t p − e q u i v ="C o n t e n t −Type " c o n t e n t =" t e x t / h t m l ; c h a r s e t=u t f −8" />
< t i t l e >S t u d e n t s </ t i t l e >
<META NAME=" D e s c r i p t i o n " CONTENT="Top Students preparing for I I T −JEE , AIEEE , DCE , Olympiads exams .
Previous Year Students for I I T −JEE E n t e r a n c e ">
<META NAME="k e y w o r d s " c o n t e n t =" I I T Coaching , What Studnets Say about IITJEE , Studnet Record for I I T " />
<l i n k r e l =" s h o r t c u t icon " href ="../../ alphalogo . ico " /> </head>
<body>
<img s r c =" h t t p s : / /www . a l p h a c l a s s e s . com/ world_map . g i f " a l t ="w o r l d " l o n g d e s c =" h t t p : / /www . a l p h a c l a s s e s . com" />
<t a b l e b o r d e r ="0">< t r >
<?php
$dbname = ' r a j a t k a l _ a c t ' ; $ l i n k=m y s q l i _ c o n n e c t ( " l o c a l h o s t " , " r a j a t k a l _ r k " , " ManasI4URajat " )
or d i e ( " Couldn ' t make connection . " ) ;
$db = m y s q l i _ s e l e c t _ d b ( $ l i n k , $dbname ) or d i e ( " Couldn ' t select database " ) ;
$result = mysqli_query ( $ l i n k , ' SELECT ∗ FROM s t u r e c o r d ORDER BY s c o r e DESC ' )
or d i e (" Fetch Failed :" . mysql_error ( ) ) ;
$ c t r =0;
p r i n t f (" Affected rows : %d \ n " , mysqli_affected_rows ( $ l i n k ) ) ;
while ( $row = m y s q l i _ f e t c h _ a r r a y ( $ r e s u l t , MYSQLI_ASSOC ) )
{
echo '< td><t r ><d i v ><td><img
s r c =" h t t p s : / /www . a l p h a c l a s s e s . com/ S t u d e n t P i c s / ' . $row [ " y e a r " ] . " / " . $row [ " p i c t u r e i d " ] . ' " ' .
' w i d t h =150 h e i g h t =200 /></ t r ><t r ></td><td><a h r e f =" h t t p s : / /www . a l p h a c l a s s e s . com/ r e p o r t c a r d . php ? r o l l n o = ' .
$row [ " r o l l n o " ] . ' " > ' . $row [ " name " ] . ' < / a></td ></d i v ></t r ></td > ' ;
$ctr = $ctr + 1;
if ( $ c t r % 5 == 0 ) echo ' </ t r ><t r > ' ;
}
?> </ t a b l e > </body> </html>
g u e s t b o o k . php
<html>
<head>
< t i t l e >G u e s t Book</ t i t l e >
<meta h t t p − e q u i v =" c o n t e n t −t y p e " c o n t e n t =" t e x t / h t m l ; c h a r s e t=ISO −8859 −15">
<meta h t t p − e q u i v =" c o n t e n t − s t y l e −t y p e " c o n t e n t =" t e x t / c s s ">
<meta h t t p − e q u i v =" c o n t e n t − s c r i p t −t y p e " c o n t e n t =" t e x t / j a v a s c r i p t ">
<meta name=" d e s c r i p t i o n " c o n t e n t ="G u e s t Book">
<meta name=" c o p y r i g h t " c o n t e n t =" R a j a t Kalia − www . r a j a t k a l i a . com">
<meta name=" a u t h o r " c o n t e n t =" R a j a t Kalia − www . r a j a t k a l i a . com">
<l i n k r e l =" s h o r t c u t icon " href ="../../ alphalogo . ico " />
</head><body m a r g i n w i d t h ="0" m a r g i n h e i g h t ="0" t o p m a r g i n ="0" l e f t m a r g i n ="0" >
<f o r m a c t i o n=h t t p s : / /www . a l p h a c l a s s e s . com/ g u e s t b o o k . php ? i d =<?php e c h o $_GET[ " i d " ] ; ?> method=POST >
<i n p u t t y p e=t e x t name=name>Name</ i n p u t ><br>
<i n p u t t y p e=t e x t a r e a name=m e s s a g e>M e s s a g e </ i n p u t ><br>
<b u t t o n t y p e=s u b m i t name=s u b m i t v a l u e=1>Submit </b u t t o n >
22
</form>
<?php $dbname = ' r a j a t k a l _ a c t ' ; $ l i n k=m y s q l i _ c o n n e c t ( " l o c a l h o s t " , " r a j a t k a l _ r k " , " ManasI4URajat " )
or d i e ( " Couldn ' t make connection . " ) ;
$db = m y s q l i _ s e l e c t _ d b ( $ l i n k , $dbname ) or d i e ( " Couldn ' t select database " ) ;
i f ($_POST [ " s u b m i t " ] )
{
date_default_timezone_set ( ' Asia / Calcutta ' ) ;
$ d at e = d a t e ( "F j , Y, g: i a ");
$ r e s u l t 2 = mysqli_query ( $ l i n k , ' INSERT INTO g u e s t b o o k ( id , name , message , date ) values
( " ' . $_GET[ " i d " ] . ' " , " ' . $_POST [ " name " ] . ' " , " ' . $_POST [ " m e s s a g e " ] . ' " , " ' . $date . ' " ) ' ) ;
}
$result = mysqli_query ( $ l i n k , 'SELECT ∗ FROM g u e s t b o o k where i d = " ' .$_GET [ ' i d ' ] . ' " ORDER BY d a t e DESC ' )
or d i e (" Fetch Failed :" . mysql_error ( ) ) ;
while ( $row = m y s q l i _ f e t c h _ a r r a y ( $ r e s u l t , MYSQLI_ASSOC ) )
{
echo '< f o n t c o l o r=b l u e > ' . $row [ " name " ] .
' </ f o n t > p o s t e d a message on < f o n t c o l o r=g r e e n > ' . $row [ " d a t e " ] .
' </ f o n t ><br > ' . $row [ " m e s s a g e " ] . ' < br><br > ' ;
}
?>
Part IV
23
25
Programmed by Sher1.0(T-799) on Suraj's request although he didn't program the 3rd level loop. (2017) Script Installed and html written by Saloni (
maami-shivi duo )
/ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ /
/∗ 5 grid 0.3.2 by n33 . c o | MIT+GPLv2 ∗/ license licensed
/∗ init . js : Init script ∗/
/ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ /
/ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ /
/∗ O b j e c t Setup ∗/
/ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ /
var _5gridC = f u n c t i o n ( ) {
t h i s . e v e n t s = new Array ( ) ;
t h i s . isReady = false ;
this . isMobile = false ;
t h i s . isDesktop = false ;
this . isFluid = false ;
t h i s . is1000px = false ;
t h i s . is1200px = false ; }
_5gridC . p r o t o t y p e . b i n d = f u n c t i o n ( name , f) {
if ( ! t h i s . e v e n t s [ name ] )
t h i s . e v e n t s [ name ] = new Array ( ) ;
t h i s . e v e n t s [ name ] . p u s h ( f ) ;
}
_5gridC . p r o t o t y p e . t r i g g e r = f u n c t i o n ( name ) {
if ( ! t h i s . isReady || ! t h i s . e v e n t s [ name ] || t h i s . e v e n t s [ name ] . l e n g t h < 1 )
return ;
for ( i in t h i s . e v e n t s [ name ] )
( t h i s . e v e n t s [ name ] [ i ] ) ( ) ;
}
_5gridC . p r o t o t y p e . r e a d y = f u n c t i o n ( f ) {
t h i s . bind ( ' ready ' , f );
}
_5gridC . p r o t o t y p e . o r i e n t a t i o n C h a n g e = f u n c t i o n ( f )
{ t h i s . bind ( ' orientationChange ' , f );
} _5gridC . p r o t o t y p e . mobileUINavOpen = f u n c t i o n ( f )
{ t h i s . b i n d ( ' mobileUINavOpen ' , f );
} _5gridC . p r o t o t y p e . m o b i l e U I N a v C l o s e = f u n c t i o n ( f )
{ t h i s . bind ( ' mobileUINavClose ' , f );
}
_5gridC . p r o t o t y p e . r e a d y C h e c k = f u n c t i o n ( ) {
var x = this ;
window . s e t T i m e o u t ( f u n c t i o n ( ) {
if ( x . isReady )
x . t r i g g e r ( ' ready ' ) ;
else
x . readyCheck ( ) ; }, 50); }
var _ 5 g r i d = new _5gridC ;
( function () {
/ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ /
/∗ Initialize ∗/
/ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ /
// Vars
var _baseURL ,
_opts ,
_fluid ,
_1000px ,
_1200px ,
_mobile ,
_desktop ,
_mobileOnly ,
_window = j Q u e r y ( window ) ,
_head = j Q u e r y ( ' head ' ) ,
_document = j Q u e r y ( document ) ,
_headQueue = new Array ( ) ,
_isLocked = f a l s e ,
_isTouch = ! ! ( ' ontouchstart ' in window ) ,
_eventType = ( _isTouch ? ' touchend ' : ' click ') ,
v, w, x, y;
// Shortcut methods
_headQueue . p u s h I _ 5 g r i d = f u n c t i o n ( s )
{ _headQueue . p u s h ( { type : 'i ' , value : s }); };
_headQueue . p u s h E _ 5 g r i d = f u n c t i o n ( s ) {
_headQueue . p u s h ( { type : 'e ' , value : s }); };
_headQueue . p r o c e s s _ 5 g r i d = f u n c t i o n ( ) {
var doE ;
if ( document . c r e a t e S t y l e S h e e t )
doE = f u n c t i o n ( s ) { document . c r e a t e S t y l e S h e e t ( s ) ; };
else
doE = f u n c t i o n ( s ) { _head . append ( ' < l i n k r e l =" s t y l e s h e e t " h r e f =" ' + s + '" / > '); };
for (x in _headQueue ) {
if ( _headQueue [ x ] . t y p e == 'i ')
_head . append ( ' < s t y l e > ' + _headQueue [ x ] . v a l u e + ' </ s t y l e > ' ) ;
else if ( _headQueue [ x ] . t y p e == 'e ')
( doE ) ( _headQueue [ x ] . v a l u e ) ;
} };
26
jQuery . f n . d i s a b l e S e l e c t i o n _ 5 g r i d = f u n c t i o n ( ) {
return j Q u e r y ( t h i s ) . c s s ( ' u s e r −s e l e c t ' ,
' none ' ) . c s s ( ' − khtml −u s e r − s e l e c t ' ,
' none ' ) . c s s ( ' − moz−u s e r − s e l e c t ' ,
' none ' ) . c s s ( ' − o−u s e r − s e l e c t ' ,
' none ' ) . c s s ( ' − w e b k i t −u s e r − s e l e c t ' ,
' none ' ) ;
}
jQuery . f n . e n a b l e S e l e c t i o n _ 5 g r i d = f u n c t i o n ( )
{
return j Q u e r y ( t h i s ) . c s s ( ' u s e r −s e l e c t ' ,
' a u t o ' ) . c s s ( ' − khtml −u s e r − s e l e c t ' ,
' a u t o ' ) . c s s ( ' − moz−u s e r − s e l e c t ' ,
' a u t o ' ) . c s s ( ' − o−u s e r − s e l e c t ' ,
' a u t o ' ) . c s s ( ' − w e b k i t −u s e r − s e l e c t ' ,
' auto ' ) ;
}
jQuery . f n . a c c e l e r a t e _ 5 g r i d = f u n c t i o n ( ) {
return j Q u e r y ( t h i s ) . c s s ( ' − w e b k i t −t r a n s f o r m ' ,
' t r a n s l a t e Z ( 0 ) ' ) . c s s ( ' − w e b k i t −b a c k f a c e − v i s i b i l i t y ' ,
' h i d d e n ' ) . c s s ( ' − w e b k i t −p e r s p e c t i v e ' , '1000 '); }
// Determine b a s e URL,
opts x = jQuery ( ' s c r i p t ' ) . f i l t e r ( f u n c t i o n ( ) {
return t h i s . s r c . match ( / 5 g r i d \ / i n i t \ . j s / ) ; }). f i r s t ();
y = x . attr ( ' src ' ) . s p l i t ( ' ? ' ) ;
_baseURL = y [ 0 ] . r e p l a c e ( / 5 g r i d \ / i n i t \ . j s / , ' ');
_opts = new Array ( ) ;
// Default opts
_opts [ ' u s e ' ] = ' mobile , desktop ' ;
_opts [ ' p r e f i x ' ] = ' style ' ;
_opts [ ' m o b i l e U I ' ] = 0;
_opts [ ' m o b i l e U I . f o r c e ' ] = 0;
_opts [ ' m o b i l e U I . t i t l e B a r H e i g h t ' ] = 44;
_opts [ ' m o b i l e U I . t i t l e B a r O v e r l a i d ' ] = 0;
_opts [ ' m o b i l e U I . o p e n e r W i d t h ' ] = 60;
_opts [ ' m o b i l e U I . o p e n e r T e x t ' ] = '= ';
_opts [ ' m o b i l e U I . t i t l e B a r F i x e d ' ] = 1;
_opts [ ' m o b i l e U I . theme ' ] = ' beveled ' ;
_opts [ ' m o b i l e U I . t h e m e T i t l e B a r C o l o r ' ] = '#444444 ';
_opts [ ' m o b i l e U I . themeNavColor ' ] = '#272727 ';
_opts [ ' m o b i l e U I . h i d e A d d r e s s B a r ' ] = 0;
_opts [ ' v i e w p o r t . i s 1 0 0 0 p x ' ] = 1040;
_opts [ ' v i e w p o r t . i s 1 2 0 0 p x ' ] = 1280;
_opts [ ' debug . noExtLoad ' ] = 0;
// Custom opts
if ( y . length > 1)
{
x = y [ 1 ] . s p l i t ( '& ');
for (v in x)
{
w = x [ v ] . s p l i t ( '= ');
_opts [ w [ 0 ] ] = w[ 1 ] ;
}
}
// Debug options
if ( _opts [ ' debug . noExtLoad ' ] == 1 )
_headQueue . p u s h E _ 5 g r i d = f u n c t i o n ( s ) { };
// Determine viewing modes
_ d e s k t o p = _ m ob i le = _ f l u i d = _1000px = _1200px = _mob ileOnl y = false ;
v = _opts [ ' u s e ' ] . s p l i t ( ' , ' ) ;
if ( jQuery . inArray ( ' f l u i d ' , v) > −1)
fluid = true ;
if ( jQuery . inArray ( ' desktop ' , v) > −1)
_desktop = t r u e ;
if ( j Q u e r y . i n A r r a y ( ' 1 0 0 0 px ' , v) > −1)
_1000px = t r u e ;
if ( j Q u e r y . i n A r r a y ( ' 1 2 0 0 px ' , v) > −1)
_1200px = t r u e ;
if ( jQuery . inArray ( ' mobile ' , v) > −1)
_ mo b il e = t r u e ;
if ( _m o bi le && ! _ f l u i d && ! _1000px && ! _1200px && ! _ d e s k t o p )
_mo bileOn ly = t r u e ;
// _desktop = t r u e ;
/ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ /
/∗ Core ∗/
/ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ /
// Legacy IE fixes
if ( jQuery . browser . msie )
{
/ / HTML5 S h i v
if ( jQuery . browser . v e r s i o n < 9)
_head . append ( ' < s c r i p t t y p e =" t e x t / j a v a s c r i p t " s r c =" ' + _baseURL + '5 grid / html5shiv . j s " / > ');
// Versions that don ' t support CSS3 pseudo classes
if ( jQuery . browser . v e r s i o n < 8)
27
{
jQuery ( f u n c t i o n ( )
{
jQuery ( ' . 5 g r i d , . 5 g r i d −l a y o u t , . do −5 g r i d ' ) . a f t e r ( ' < d i v s t y l e =" c l e a r : b o t h ;"></ d i v > ' ) ;
});
} }
// Insert stylesheets
_headQueue . p u s h E _ 5 g r i d ( _baseURL + '5 grid / core . css ' )
_headQueue . p u s h E _ 5 g r i d ( _baseURL + _opts [ ' p r e f i x ' ] + ' . css ' ) ;
/ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ /
/∗ Responsive ∗/
/ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ /
( function () {
v a r ww = _window . w i d t h ( ) ,
sw = s c r e e n . w i d t h ,
o r i e n t a t i o n = window . o r i e n t a t i o n ;
// Fix : On iOS , s c r e e n . width is always the width of the device held in portrait mode .
// Android , however , sets it to the width of the device in its current orientation .
// This ends up breaking our detection on HD d e v i c e s held in landscape mode , so we
// do a little trick here to detect this condition and make things right .
if ( s c r e e n . width > screen . height
&& Math . a b s ( o r i e n t a t i o n ) == 9 0 )
sw = s c r e e n . h e i g h t ;
// Mobile ( exclusive )
if ( ( _m o bi l e && (ww <= 4 8 0 || sw <= 4 8 0 ) ) || _ mobileO nly ) {
_5grid . i s M o b i l e = t r u e ;
_head . p r e p e n d ( ' < meta name=" v i e w p o r t " c o n t e n t =" i n i t i a l −s c a l e = 1 . 0 ; minimum− s c a l e = 1 . 0 ; maximum− s c a l e = 1 . 0 ; " / > ');
_headQueue . p u s h E _ 5 g r i d ( _baseURL + ' 5 g r i d / c o r e −m o b i l e . c s s ' ) ;
if ( _opts [ ' m o b i l e U I ' ] == 1 ) {
_opts [ ' m o b i l e U I . f o r c e ' ] = 1;
if ( _opts [ ' m o b i l e U I . theme ' ] != ' none ' ) {
_headQueue . p u s h E _ 5 g r i d ( _baseURL + ' 5 g r i d / m o b i l e U I − ' + _opts [ ' m o b i l e U I . theme ' ] + ' . css ' ) ;
if ( _opts [ ' m o b i l e U I . t h e m e T i t l e B a r C o l o r ' ] )
_headQueue . p u s h I _ 5 g r i d ( '# m o b i l e U I − s i t e −t i t l e b a r { background : ' +
_opts [ ' m o b i l e U I . t h e m e T i t l e B a r C o l o r ' ] + '; } ');
if ( _opts [ ' m o b i l e U I . themeNavColor ' ] )
_headQueue . p u s h I _ 5 g r i d ( '# m o b i l e U I − s i t e −nav { background : ' + _opts [ ' m o b i l e U I . themeNavColor ' ] + '; } ');
_headQueue . p u s h E _ 5 g r i d ( _baseURL + _opts [ ' p r e f i x ' ] + '− m o b i l e . c s s ' ) ; }
else { // Fluid ( exclusive )
if ( _fluid ) {
_5grid . i s F l u i d = t r u e ;
_head . p r e p e n d ( ' < meta name=" v i e w p o r t " c o n t e n t ="w i d t h = ' + _opts [ ' v i e w p o r t . i s 1 2 0 0 p x ' ] + '" / > ');
_headQueue . p u s h E _ 5 g r i d ( _baseURL + ' 5 g r i d / c o r e −d e s k t o p . c s s ' ) ;
_headQueue . p u s h E _ 5 g r i d ( _baseURL + '5 g r i d / core −f l u i d . c s s ' ) ;
_headQueue . p u s h E _ 5 g r i d ( _baseURL + _opts [ ' p r e f i x ' ] + '− f l u i d . c s s ' ) ;
} // Desktop
else if ( _desktop ) {
_5grid . i s D e s k t o p = t r u e ;
_headQueue . p u s h E _ 5 g r i d ( _baseURL + ' 5 g r i d / c o r e −d e s k t o p . c s s ' ) ;
_headQueue . p u s h E _ 5 g r i d ( _baseURL + _opts [ ' p r e f i x ' ] + '− d e s k t o p . c s s ' ) ;
// 1 2 0 0 px
if (ww >= 1 2 0 0 )
{
_5grid . i s 1 2 0 0 p x = t r u e ;
_head . p r e p e n d ( ' < meta name=" v i e w p o r t " c o n t e n t ="w i d t h = ' + _opts [ ' v i e w p o r t . i s 1 2 0 0 p x ' ] + '" / > ');
_headQueue . p u s h E _ 5 g r i d ( _baseURL + '5 g r i d / core − 1200 px . c s s ');
// Load 1 2 0 0 px stylesheet if 1 2 0 0 px was explicitly enabled
if ( _1200px )
_headQueue . p u s h E _ 5 g r i d ( _baseURL + _opts [ ' p r e f i x ' ] + ' − 1200 px . c s s ' ) ;
} // 1 0 0 0 px
else {
_5grid . i s 1 0 0 0 p x = t r u e ;
_head . p r e p e n d ( ' < meta name=" v i e w p o r t " c o n t e n t ="w i d t h = ' + _opts [ ' v i e w p o r t . i s 1 0 0 0 p x ' ] + '" / > ');
_headQueue . p u s h E _ 5 g r i d ( _baseURL + '5 g r i d / core − 1000 px . c s s ');
// Load 1 0 0 0 px stylesheet if 1 0 0 0 px was explicitly enabled
if ( _1000px )
_headQueue . p u s h E _ 5 g r i d ( _baseURL + _opts [ ' p r e f i x ' ] + ' − 1000 px . c s s ' ) ;
}
}
else
{ // 1 0 0 0 px ( exclusive )
if ( _1000px && (ww < 1 2 0 0 || ! _1200px ) )
{
_5grid . i s D e s k t o p = t r u e ;
_5grid . i s 1 0 0 0 p x = t r u e ;
_head . p r e p e n d ( ' < meta name=" v i e w p o r t " c o n t e n t ="w i d t h = ' +
_opts [ ' v i e w p o r t . i s 1 0 0 0 p x ' ] + '" / > ');
_headQueue . p u s h E _ 5 g r i d ( _baseURL + ' 5 g r i d / c o r e −d e s k t o p . c s s ' ) ;
_headQueue . p u s h E _ 5 g r i d ( _baseURL + '5 g r i d / core − 1000 px . c s s ' ) ;
_headQueue . p u s h E _ 5 g r i d ( _baseURL + _opts [ ' p r e f i x ' ] + ' − 1000 px . c s s ');
} // 1 2 0 0 px ( exclusive )
else if ( _1200px && (ww >= 1 2 0 0 || ! _1000px ) ) {
_5grid . i s D e s k t o p = t r u e ;
_5grid . i s 1 2 0 0 p x = t r u e ;
28
_head . p r e p e n d ( ' < meta name=" v i e w p o r t " c o n t e n t ="w i d t h = ' + _opts [ ' v i e w p o r t . i s 1 2 0 0 p x ' ] + '" / > ');
_headQueue . p u s h E _ 5 g r i d ( _baseURL + ' 5 g r i d / c o r e −d e s k t o p . c s s ' ) ;
_headQueue . p u s h E _ 5 g r i d ( _baseURL + '5 g r i d / core − 1200 px . c s s ' ) ;
_headQueue . p u s h E _ 5 g r i d ( _baseURL + _opts [ ' p r e f i x ' ] + ' − 1200 px . c s s '); }
jQuery ( f u n c t i o n ( ) { j Q u e r y ( ' . 5 g r i d −l a y o u t ' ) . a d d C l a s s ( ' 5 g r i d ' ) ; }); })();
/ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ / /∗ MobileUI ∗/ / ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ /
if ( _opts [ ' m o b i l e U I . f o r c e ' ] == 1 )
jQuery ( f u n c t i o n ( ) {
var body = j Q u e r y ( ' body ' ) ,
speed = 0 ,
easing = ' swing ' ;
var mobileUI_site_nav ,
mobileUI_site_nav_opener ,
mobileUI_site_titlebar ,
mobileUI_site_wrapper ,
mobileUI_site_group ;
body . w r a p I n n e r ( ' < d i v i d ="m o b i l e U I − s i t e −w r a p p e r " / > ');
// Move primary content
var m a i n _ c o n t e n t = j Q u e r y ( ' . m o b i l e U I −main−c o n t e n t ' ) ,
m a i n _ c o n t e n t _ t a r g e t = j Q u e r y ( ' . m o b i l e U I −main−c o n t e n t − t a r g e t ' ) ;
if ( main_content . l e n g t h > 0 )
if ( main_content_target . l e n g t h > 0)
main_content . prependTo ( m a i n _ c o n t e n t _ t a r g e t ) ;
else
main_content . prependTo ( main_content . p a r e n t ( ) ) ;
// Get site name , nav options
var x = j Q u e r y ( ' . m o b i l e U I−s i t e −name ' ) ,
site_name = ( x . l e n g t h > 0 ? x . html ( ) : ' ');
var s i t e _ n a v _ o p t i o n s = new Array ( ) ;
j Q u e r y ( ' . m o b i l e U I−s i t e −nav a ' ) . each ( f u n c t i o n ( ) {
var t = jQuery ( t h i s ) , indent ;
i n d e n t = Math . max ( 0 , t . p a r e n t s ( ' l i ' ) . l e n g t h − 1);
s i t e _ n a v _ o p t i o n s . push (
'< a h r e f =" ' + t . a t t r ( ' h r e f ' ) + '">< s p a n c l a s s =" i n d e n t −' + i n d e n t + '"></ span > '
+ t . t e x t ( ) + ' </ a > ' ); }
if ( site_nav_options . length > 0) {
mobileUI_site_nav = jQuery ( ' < div i d ="m o b i l e U I − s i t e −nav"><nav > ' +
s i t e _ n a v _ o p t i o n s . j o i n ( ' ' ) + ' </ nav></d i v > ' ) ;
mobileUI_site_nav_opener = jQuery ( ' < d i v i d ="m o b i l e U I − s i t e −nav−o p e n e r " > ' +
_opts [ ' m o b i l e U I . o p e n e r T e x t ' ] + ' </ d i v > ' ) ;
}
else {
mobileUI_site_nav = jQuery ( ) ;
mobileUI_site_nav_opener = jQuery ( ) ;
}
// Configure elements
m o b i l e U I _ s i t e _ t i t l e b a r = jQuery ( ' < div i d ="m o b i l e U I − s i t e − t i t l e b a r ">< d i v i d ="m o b i l e U I − s i t e − t i t l e ">'
s i t e _ n a m e + ' </ d i v ></d i v > ' ) ;
m o b i l e U I _ s i t e _ w r a p p e r = j Q u e r y ( '# m o b i l e U I − s i t e −w r a p p e r ');
m o b i l e U I _ s i t e _ g r o u p = j Q u e r y ( ) . add ( m o b i l e U I _ s i t e _ w r a p p e r ) . add ( m o b i l e U I _ s i t e _ t i t l e b a r ) ;
body . b i n d ( ' touchmove ' , function ( e ) {
if ( mobileUI_site_nav . isOpen_5grid ) {
e . stopPropagation ( ) ;
e . preventDefault ( ) ; } }
// Mobile Site Wrapper
mobileUI_site_wrapper
. css ( ' position ' , ' relative ')
. c s s ( ' z −i n d e x ' , '100 ')
. c s s ( ' top ' , ( _opts [ ' m o b i l e U I . t i t l e B a r O v e r l a i d ' ] == 1 ? 0 :
_opts [ ' m o b i l e U I . t i t l e B a r H e i g h t ' ] + ' px ' ) )
. c s s ( ' width ' , '100% ')
. b i n d ( _eventType , function ( e ) {
if ( mobileUI_site_nav . isOpen_5grid )
{
e . preventDefault ( ) ;
body . t r i g g e r ( ' 5 g r i d _ c l o s e N a v ' ) ;
} })
. bind ( ' 5 grid_top ' , function ( e ) {
if ( _isLocked )
return ;
_isLocked = t r u e ;
body . a n i m a t e ( { scrollTop : 0 }, 400 , ' swing ' , function () { _isLocked = false ;
});
});
// Mobile Site Nav Opener
mobileUI_site_nav_opener
. css ( ' position ' , ' absolute ' )
. c s s ( ' z −i n d e x ' , '152 ')
. css ( ' cursor ' , ' pointer ' )
. disableSelection_5grid ()
. appendTo ( m o b i l e U I _ s i t e _ t i t l e b a r )
. b i n d ( _eventType , function ( e ) {
e . stopPropagation ( ) ;
e . preventDefault ( ) ;
29
mobileUI_site_nav
. css ( ' left ' , −1 ∗ mobileUI_site_nav . width ( ) )
. hide ()
. click ( function ( e ) {
e . stopPropagation ( ) ;
});
if ( url )
window . s e t T i m e o u t ( f u n c t i o n ( ) {
window . l o c a t i o n . h r e f = u r l ;
}, 150);
});
});
/ / Window
_window
. bind ( ' o r i e n t a t i o n c h a n g e ' , function ( e ) {
if ( mobileUI_site_nav . isOpen_5grid ) {
var nw = j Q u e r y ( window ) . w i d t h ( ) − _opts [ ' m o b i l e U I . o p e n e r W i d t h ' ] ;
mobileUI_site_nav . c s s ( ' width ' , nw ) ;
mobileUI_site_group . c s s ( ' l e f t ' , nw ) ;
}
_5grid . t r i g g e r ( ' o r i e n t a t i o n C h a n g e ' ) ;
});
// Remove m o b i l e U I −h i d e elements
j Q u e r y ( ' . m o b i l e U I −h i d e ' ) . remove ( ) ;
// Remove address bar
if ( _opts [ ' m o b i l e U I . h i d e A d d r e s s B a r ' ] == 1 && _window . s c r o l l T o p ( ) == 0 )
window . s c r o l l T o ( 0 , 1); });
/ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ / /∗ Head Queue ∗/ / ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ /
_headQueue . p r o c e s s _ 5 g r i d ( ) ;
_5grid . isReady = t r u e ;
jQuery ( f u n c t i o n ( ) { _5grid . readyCheck ( ) ; });
})();