-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
192 lines (144 loc) · 6.43 KB
/
index.js
File metadata and controls
192 lines (144 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//index.js
$(function(){
//declare variables
var myArray;
var inputLength;
var reading = false;
var counter;
var action;
var frequency = 200;
//on page load hide elements we don't need, leave only text area and start button
$("#new").hide();
$("#resume").hide();
$("#pause").hide();
$("#controls").hide();//pure div ko ek sath hi hide kr dia...iske loye hi div bnaya tha
$("#result").hide();
$("#error").hide();
//click on Start Reading
$("#start").click(function(){
//get text and split it to words inside an array
//\s matches spaces, tabs, new lines, etc and + means one or more.
myArray = $("#userInput").val().split(/\s+/);/*here we used regular expression*/
//get the number of words
inputLength = myArray.length;
if(inputLength>1){//there is enough input
//move to reading mode
reading = true;
//hide Start/error/userInput, show New/Pause/Controls
$("#start").hide();
$("#error").hide();
$("#userInput").hide();
$("#new").show();
$("#pause").show();
$("#controls").show();
//set progress slider max ye max attribue ko change kia h
$("#progressslider").attr("max", inputLength-1);
//start the counter at zero
counter = 0;
//show reading box with the first word
$("#result").show();
/*yaha se hum uss div ke andr text bhr rhe hai*/
$("#result").text(myArray[counter]);
//start reading from the first word..ab hum ek loop krenge jo hr fixed time ke baad execute hoga
action = setInterval(read, frequency);
/*read ek fucntion hai jisko hum neeche define krenge*/
/*frequency means jaise hum speed set kr denge..to yaha se hume interval mil jaega jitne mei hume text change krte rehna hai*/
}else{//not enough text input
$("#error").show();
}
});
//Click on New
$("#new").click(function(){
//reload page
location.reload();//ye page reload krne ka function hai
});
//Click on Pause
$("#pause").click(function(){
//stop reading and switch to none reading mode
clearInterval(action);//yo to obvious hai
reading = false;
//hide pause and show resume and abhume uski jagah pe resume dikhega
$("#pause").hide();
$("#resume").show();
});
//Click on Resume
$("#resume").click(function(){
//iss function se jo bhi humne pause ke time pe changes kiye the sbko revert kr denge
//start reading
action = setInterval(read, frequency);
//go back to reading mode
reading = true;
//hide resume and show pause
$("#resume").hide();
$("#pause").show();
});
//Change fontSize
/*jb hum usko silde krte krte ruk jaye tb vo event pura hoga*/
$("#fontsizeslider").on("slidestop", function(event,ui){/*ye event or ui ka koi kaam nhi hai..lekin jb hum koi event aise likh rhe hi..tb hume ye syntax lihna hu pdta hai*/
//refresh the slider
$("#fontsizeslider").slider("refresh");//refresh krenge as ye to krna pdta hai sliders ke sath
//get the value of slider
var slidervalue = parseInt($("#fontsizeslider").val());
$("#result").css("fontSize", slidervalue);
/*fontsize span hai jaha pe font ki value update hoke lgegi*/
$("#fontsize").text(slidervalue);
});
//change speed
$("#speedslider").on("slidestop", function(event,ui){
//refresh the slider
$("#speedslider").slider("refresh");
//get the value of slider
var slidervalue = parseInt($("#speedslider").val());
$("#speed").text(slidervalue);
//stop reading
clearInterval(action);//as hume interval ki value change krni pdegi to jo abhi reading chl rhi hai usko rok do
//change frequency
frequency = 60000/slidervalue;
//resume reading if we are in reading mode
//and according to the status of reading ...resume our services with the new interval
if(reading){
action = setInterval(read, frequency);
}
});
//progress slider
$("#progressslider").on("slidestop", function(event,ui){
//refresh the slider
$("#progressslider").slider("refresh");
//get the value of slider
var slidervalue = parseInt($("#progressslider").val());
//stop reading
clearInterval(action);
//change counter
counter = slidervalue;
//jaha ab hume slider jake roka hai..uske correspoding jo vhi counter value hai hume vahi word display krna hai
//hum chahte to iske neech wale code ke liye fucntion bhi ba skte the as ye baar baar use ho rha hai
//change word
$("#result").text(myArray[counter]);
//change value of progress
$("#percentage").text(Math.floor(counter/(inputLength-1)*100));
//resume reading if we are in reading mode
if(reading){
action = setInterval(read, frequency);
}
});
//functions
function read()
{
if(counter == inputLength-1){//last word
clearInterval(action);/*set interval ka counter part h ye..clearinterval */
reading = false; //move to non-reading mode
$("#pause").hide();/*as hume sirf new buttuon dikhega*/
}
else
{
//counter goes up by one
counter++;
//get word
$("#result").text(myArray[counter]);
//change progress slider value and refresh
/*hum slider ka max ek baar fix kr denge and fir ye slider counter ko dekh ke apne aap apni jagah bna lega*/$("#progressslider").val(counter).slider('refresh');/*and ye tareka hai ki agar slider ki value chnage krni hai to refresh kro usko*/
//change text of percentage
$("#percentage").text(Math.floor(counter/(inputLength-1)*100));/*ye to obvious calculation hai*/
}
}
});