Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
e07fcdcf
Commit
e07fcdcf
authored
Mar 27, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(ui) add some javascript helper functions, related to
https://github.com/opnsense/core/issues/840
parent
685746bd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
opnsense.js
src/opnsense/www/js/opnsense.js
+50
-0
No files found.
src/opnsense/www/js/opnsense.js
View file @
e07fcdcf
...
...
@@ -217,3 +217,53 @@ function ajaxGet(url,sendData,callback) {
data
:
sendData
});
}
/**
* set cookie value by key
* @param key cookie key
* @param value cookie value
* @param expire time to live
*/
function
setCookie
(
key
,
value
,
expire
)
{
var
expires
=
new
Date
();
if
(
expire
==
undefined
)
{
expire
=
3600000
;
// expire in 1 hour
}
expires
.
setTime
(
expires
.
getTime
()
+
expire
);
// 1 hour
document
.
cookie
=
key
+
'
=
'
+
value
+
'
;expires=
'
+
expires
.
toUTCString
();
}
/**
* get cookie value
* @param key cookie key
* @return cookie value (or null if not found)
*/
function
getCookie
(
key
)
{
var
keyValue
=
document
.
cookie
.
match
(
'
(^|;) ?
'
+
key
+
'
=([^;]*)(;|$)
'
);
return
keyValue
?
keyValue
[
2
]
:
null
;
}
/**
* watch scroll position and set to last known on page load
*/
function
watchScrollPosition
()
{
function
current_location
()
{
// concat url pieces to indentify this page and parameters
return
window
.
location
.
href
.
replace
(
/
\/
|
\:
|
\.
|
\?
|
\#
/gi
,
''
);
}
// link on scroll event handler
$
(
window
).
scroll
(
function
(){
setCookie
(
'
scrollpos
'
,
current_location
()
+
"
|
"
+
$
(
window
).
scrollTop
());
});
// move to last known position on page load
$
(
document
).
ready
(
function
()
{
var
scrollpos
=
getCookie
(
'
scrollpos
'
);
if
(
scrollpos
!=
null
)
{
if
(
scrollpos
.
split
(
'
|
'
)[
0
]
==
current_location
())
{
$
(
window
).
scrollTop
(
scrollpos
.
split
(
'
|
'
)[
1
]);
}
}
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment