Skip to content

Commit d8582b6

Browse files
Update web-forms.js
Support for multiple responses in Action Controls Ability to select parent input places New ability to remove parent tag New ability to fetch cookie And a series of minor changes and improvements
1 parent 681841d commit d8582b6

File tree

1 file changed

+147
-75
lines changed

1 file changed

+147
-75
lines changed

web-forms.js

Lines changed: 147 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* WebFormsJS 1.5 - Providing Infrastructure For Web Controls In CodeBehind Framework Owned By Elanat (elanat.net) */
1+
/* WebFormsJS 1.6 - Providing Infrastructure For Web Controls In CodeBehind Framework Owned By Elanat (elanat.net) */
22

33
/* Start Options */
44

@@ -124,53 +124,26 @@ function PostBack(obj, ViewState)
124124
}
125125

126126
// Create Request Name
127-
var RequestName = "";
127+
var RequestNameForCache = "<";
128+
var RequestName = (FormAction == "") ? window.location.pathname : FormAction;
129+
if (FormAction.length > 0)
130+
{
131+
if (FormAction.substring(0, 1) == '#')
132+
RequestName = window.location.pathname + FormAction;
133+
134+
if (FormAction.Contains("#"))
135+
RequestNameForCache = "#" + FormAction.GetTextAfter("#");
136+
}
128137
if (obj.getAttribute("name"))
129-
RequestName = obj.getAttribute("name") + "|" + TagSubmitValue + "|" + FormAction;
138+
RequestName = obj.getAttribute("name") + "|" + TagSubmitValue + "|" + RequestName;
130139

131140
// Check Cache
132-
var SessionCacheValue = sessionStorage.getItem(RequestName);
133-
if (SessionCacheValue)
134-
{
135-
// Reset Input Type
141+
if (cb_UsedCache(RequestName, RequestNameForCache))
142+
{ // Reset Input Type
136143
setTimeout(function () { (OldObjectType == "submit") ? obj.type = "submit" : obj.type; }, 1);
137-
138-
cb_SetWebFormsValues("", SessionCacheValue, true, true);
139144
return;
140145
}
141146

142-
var LocalCacheValue = localStorage.getItem(RequestName);
143-
if (LocalCacheValue)
144-
{
145-
var LocalCacheDateValue = localStorage.getItem(RequestName + "-date");
146-
if (LocalCacheDateValue)
147-
{
148-
var CacheDate = new Date(LocalCacheDateValue);
149-
var CurrentDate = new Date();
150-
151-
if (CacheDate.getTime() > CurrentDate.getTime())
152-
{
153-
// Reset Input Type
154-
setTimeout(function () { (OldObjectType == "submit") ? obj.type = "submit" : obj.type; }, 1);
155-
156-
cb_SetWebFormsValues("", LocalCacheValue, true, true);
157-
return;
158-
}
159-
else
160-
{
161-
localStorage.removeItem(RequestName);
162-
localStorage.removeItem(RequestName + "-date");
163-
}
164-
}
165-
else
166-
{
167-
// Reset Input Type
168-
setTimeout(function () { (OldObjectType == "submit") ? obj.type = "submit" : obj.type; }, 1);
169-
170-
cb_SetWebFormsValues("", LocalCacheValue, true, true);
171-
return;
172-
}
173-
}
174147

175148
var XMLHttp = new XMLHttpRequest();
176149
XMLHttp.onreadystatechange = function ()
@@ -304,43 +277,21 @@ function GetBack(FormAction, ViewState)
304277

305278

306279
// Create Request Name
307-
var RequestName = (FormAction == "") ? window.location.href : FormAction;
308-
309-
// Check Cache
310-
var SessionCacheValue = sessionStorage.getItem(RequestName);
311-
if (SessionCacheValue)
312-
{
313-
cb_SetWebFormsValues("", SessionCacheValue, true, true);
314-
return;
315-
}
316-
317-
var LocalCacheValue = localStorage.getItem(RequestName);
318-
if (LocalCacheValue)
280+
var RequestNameForCache = "<";
281+
var RequestName = (FormAction == "") ? window.location.pathname : FormAction;
282+
if (FormAction.length > 0)
319283
{
320-
var LocalCacheDateValue = localStorage.getItem(RequestName + "-date");
321-
if (LocalCacheDateValue)
322-
{
323-
var CacheDate = new Date(LocalCacheDateValue);
324-
var CurrentDate = new Date();
284+
if (FormAction.substring(0, 1) == '#')
285+
RequestName = window.location.pathname + FormAction;
325286

326-
if (CacheDate.getTime() > CurrentDate.getTime())
327-
{
328-
cb_SetWebFormsValues("", LocalCacheValue, true, true);
329-
return;
330-
}
331-
else
332-
{
333-
localStorage.removeItem(RequestName);
334-
localStorage.removeItem(RequestName + "-date");
335-
}
336-
}
337-
else
338-
{
339-
cb_SetWebFormsValues("", LocalCacheValue, true, true);
340-
return;
341-
}
287+
if (FormAction.Contains("#"))
288+
RequestNameForCache = "#" + FormAction.GetTextAfter("#");
342289
}
343290

291+
// Check Cache
292+
if (cb_UsedCache(RequestName, RequestNameForCache))
293+
return;
294+
344295

345296
var XMLHttp = new XMLHttpRequest();
346297
XMLHttp.onreadystatechange = function ()
@@ -722,6 +673,18 @@ function cb_SetWebFormsTagsValue(obj)
722673

723674
function cb_SetWebFormsValues(RequestName, WebFormsValues, UsePostBack, WithoutWebFormsSection)
724675
{
676+
// Initialization to Index
677+
var StartIndex = RequestName.Contains("#") ? RequestName.GetTextAfter("#") : "";
678+
var IndexHasStarted = ((StartIndex == "") || (StartIndex == "0"));
679+
var StartIndexIsNumber = (!isNaN(StartIndex) && !isNaN(parseInt(StartIndex)));
680+
var StartIndexIndex = StartIndexIsNumber ? parseInt(StartIndex) : 0;
681+
var IndexForStartIndex = 1;
682+
683+
// Remove Request Name For Cache
684+
if (RequestName.length > 1)
685+
if (RequestName.substring(0, 1) == '<')
686+
RequestName = "";
687+
725688
if (!WithoutWebFormsSection)
726689
WebFormsValues = WebFormsValues.substring(11);
727690

@@ -734,6 +697,29 @@ function cb_SetWebFormsValues(RequestName, WebFormsValues, UsePostBack, WithoutW
734697
if (!WebFormsList[i])
735698
continue;
736699

700+
// Checking Index Process
701+
if (IndexHasStarted)
702+
{
703+
if (WebFormsList[i].substring(0, 1) == '#')
704+
break;
705+
}
706+
else
707+
{
708+
if (StartIndexIsNumber)
709+
{
710+
if (WebFormsList[i].substring(0, 1) == '#')
711+
if (StartIndexIndex == IndexForStartIndex)
712+
IndexHasStarted = true;
713+
else
714+
IndexForStartIndex++;
715+
}
716+
else
717+
if (WebFormsList[i] == ("#=" + StartIndex))
718+
IndexHasStarted = true;
719+
720+
continue;
721+
}
722+
737723
var PreRunner = new Array();
738724
var FirstChar = WebFormsList[i].substring(0, 1);
739725
var PreRunnerIndexer = 0;
@@ -1281,11 +1267,14 @@ function cb_SetValueToInput(ActionOperation, ActionFeature, ActionValue)
12811267
case 'a':
12821268
if (CurrentElement.hasAttribute(Value))
12831269
CurrentElement.removeAttribute(Value);
1284-
12851270
break;
12861271
case 'e':
12871272
if (Value == "1")
12881273
CurrentElement.outerHTML = "";
1274+
break;
1275+
case 'p':
1276+
if (Value == "1")
1277+
CurrentElement.parentElement.outerHTML = "";
12891278
}
12901279
break;
12911280

@@ -1614,6 +1603,28 @@ function cb_GetElementByElementPlace(ElementPlace, obj)
16141603

16151604
return TmpPlace;
16161605

1606+
case '/':
1607+
var i = 0;
1608+
while (ElementPlace.length > 0)
1609+
{
1610+
if (ElementPlace.substring(0, 1) == '/')
1611+
i++;
1612+
else
1613+
break;
1614+
1615+
ElementPlace = ElementPlace.substring(1);
1616+
}
1617+
1618+
var TmpElementPlace = cb_GetElementByElementPlace(ElementPlace);
1619+
1620+
while (i > 0)
1621+
{
1622+
TmpElementPlace = TmpElementPlace.parentElement;
1623+
i--;
1624+
}
1625+
1626+
return TmpElementPlace;
1627+
16171628
default: return FromPlace.getElementById(ElementPlace);
16181629
}
16191630
}
@@ -1661,6 +1672,7 @@ function cb_FetchValue(Value)
16611672
case 'c':
16621673
switch (ActionFeature)
16631674
{
1675+
case 'o': return cb_GetCookie(Value);
16641676
case 's':
16651677
case 'l':
16661678
if (Value.Contains(','))
@@ -1766,6 +1778,66 @@ function cb_SetSession(Name, Value)
17661778

17671779
/* End Fetch Web-Forms */
17681780

1781+
/* Start Cache */
1782+
1783+
function cb_UsedCache(RequestName, RequestNameForCache)
1784+
{
1785+
var SessionCacheValue = sessionStorage.getItem(RequestName);
1786+
if (SessionCacheValue)
1787+
{
1788+
cb_SetWebFormsValues(RequestNameForCache, SessionCacheValue, true, true);
1789+
return true;
1790+
}
1791+
1792+
var LocalCacheValue = localStorage.getItem(RequestName);
1793+
if (LocalCacheValue)
1794+
{
1795+
var LocalCacheDateValue = localStorage.getItem(RequestName + "-date");
1796+
if (LocalCacheDateValue)
1797+
{
1798+
var CacheDate = new Date(LocalCacheDateValue);
1799+
var CurrentDate = new Date();
1800+
1801+
if (CacheDate.getTime() > CurrentDate.getTime())
1802+
{
1803+
cb_SetWebFormsValues(RequestNameForCache, LocalCacheValue, true, true);
1804+
return true;
1805+
}
1806+
else
1807+
{
1808+
localStorage.removeItem(RequestName);
1809+
localStorage.removeItem(RequestName + "-date");
1810+
}
1811+
}
1812+
else
1813+
{
1814+
cb_SetWebFormsValues(RequestNameForCache, LocalCacheValue, true, true);
1815+
return true;
1816+
}
1817+
}
1818+
1819+
return false;
1820+
}
1821+
1822+
/* End Cache */
1823+
1824+
/* Start Other Methods */
1825+
1826+
function cb_GetCookie(Key)
1827+
{
1828+
const Cookies = document.cookie.split(';');
1829+
for (let cookie of Cookies)
1830+
{
1831+
cookie = cookie.trim();
1832+
if (cookie.startsWith(Key + '='))
1833+
return cookie.substring(Key.length + 1);
1834+
}
1835+
1836+
return "";
1837+
}
1838+
1839+
/* End Other Methods */
1840+
17691841
/* Start Extension Methods */
17701842

17711843
String.prototype.toDOM = function ()

0 commit comments

Comments
 (0)