Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Arnaud Véron
slapos.core
Commits
44540112
Commit
44540112
authored
Jul 24, 2012
by
Thomas Lechauve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move route.js and url.js in lib directory
parent
da7cc548
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
276 additions
and
0 deletions
+276
-0
vifib/js/lib/route.js
vifib/js/lib/route.js
+150
-0
vifib/js/lib/url.js
vifib/js/lib/url.js
+126
-0
No files found.
vifib/js/lib/route.js
0 → 100644
View file @
44540112
/*global window, jQuery */
/*!
* route.js v1.0.0
*
* Copyright 2012, Romain Courteaud
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Date: Mon Jul 16 2012
*/
"
use strict
"
;
(
function
(
window
,
$
)
{
$
.
extend
({
StatelessDeferred
:
function
()
{
var
doneList
=
$
.
Callbacks
(
"
memory
"
),
promise
=
{
done
:
doneList
.
add
,
// Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object
promise
:
function
(
obj
)
{
var
i
,
keys
=
[
'
done
'
,
'
promise
'
];
if
(
obj
===
undefined
)
{
obj
=
promise
;
}
else
{
for
(
i
=
0
;
i
<
keys
.
length
;
i
+=
1
)
{
obj
[
keys
[
i
]]
=
promise
[
keys
[
i
]];
}
}
return
obj
;
}
},
deferred
=
promise
.
promise
({});
deferred
.
resolveWith
=
doneList
.
fireWith
;
// All done!
return
deferred
;
}
});
var
routes
=
[],
current_priority
=
0
,
methods
=
{
add
:
function
(
pattern
,
priority
)
{
var
i
=
0
,
inserted
=
false
,
length
=
routes
.
length
,
dfr
=
$
.
StatelessDeferred
(),
context
=
$
(
this
),
escapepattern
,
matchingpattern
;
if
(
priority
===
undefined
)
{
priority
=
0
;
}
if
(
pattern
!==
undefined
)
{
// http://simonwillison.net/2006/Jan/20/escape/
escapepattern
=
pattern
.
replace
(
/
[\-\[\]
{}()*+?.,
\\\^
$|#
\s]
/g
,
"
\\
$&
"
);
matchingpattern
=
escapepattern
.
replace
(
/<int:
\w
+>/g
,
"
(
\\
d+)
"
)
.
replace
(
/<path:
\w
+>/g
,
"
(.+)
"
)
.
replace
(
/<
\w
+>/g
,
"
([^/]+)
"
);
while
(
!
inserted
)
{
if
((
i
===
length
)
||
(
priority
>=
routes
[
i
][
2
]))
{
routes
.
splice
(
i
,
0
,
[
new
RegExp
(
'
^
'
+
matchingpattern
+
'
$
'
),
dfr
,
priority
,
context
]);
inserted
=
true
;
}
else
{
i
+=
1
;
}
}
}
return
dfr
.
promise
();
},
go
:
function
(
path
,
min_priority
)
{
var
dfr
=
$
.
Deferred
(),
context
=
$
(
this
),
result
;
if
(
min_priority
===
undefined
)
{
min_priority
=
0
;
}
setTimeout
(
function
()
{
var
i
=
0
,
found
=
false
,
slice_index
=
-
1
,
slice_priority
=
-
1
;
for
(
i
=
0
;
i
<
routes
.
length
;
i
+=
1
)
{
if
(
slice_priority
!==
routes
[
i
][
2
])
{
slice_priority
=
routes
[
i
][
2
];
slice_index
=
i
;
}
if
(
routes
[
i
][
2
]
<
min_priority
)
{
break
;
}
else
if
(
routes
[
i
][
0
].
test
(
path
))
{
result
=
routes
[
i
][
0
].
exec
(
path
);
dfr
=
routes
[
i
][
1
];
context
=
routes
[
i
][
3
];
current_priority
=
routes
[
i
][
2
];
found
=
true
;
break
;
}
}
if
(
i
===
routes
.
length
)
{
slice_index
=
i
;
}
if
(
slice_index
>
-
1
)
{
routes
=
routes
.
slice
(
slice_index
);
}
if
(
found
)
{
dfr
.
resolveWith
(
context
,
result
.
slice
(
1
)
);
}
else
{
dfr
.
rejectWith
(
context
);
}
});
return
dfr
.
promise
();
},
};
$
.
routereset
=
function
()
{
routes
=
[];
current_priority
=
0
;
};
$
.
routepriority
=
function
()
{
return
current_priority
;
};
$
.
fn
.
route
=
function
(
method
)
{
var
result
;
if
(
methods
.
hasOwnProperty
(
method
))
{
result
=
methods
[
method
].
apply
(
this
,
Array
.
prototype
.
slice
.
call
(
arguments
,
1
)
);
}
else
{
$
.
error
(
'
Method
'
+
method
+
'
does not exist on jQuery.route
'
);
}
return
result
;
};
}(
window
,
jQuery
));
vifib/js/lib/url.js
0 → 100644
View file @
44540112
/*!
* url.js v1.0.0
*
* Copyright 2012, Romain Courteaud
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Date: Mon Jul 16 2012
*/
"
use strict
"
;
(
function
(
window
,
$
)
{
var
hashchangeinitialized
=
false
,
previousurl
,
currentcallback
,
getRawHash
=
function
()
{
return
window
.
location
.
toString
().
split
(
'
#
'
)[
1
];
},
callbackwrapper
=
function
()
{
if
(
previousurl
!==
window
.
location
.
hash
)
{
previousurl
=
window
.
location
.
hash
;
if
(
currentcallback
!==
undefined
)
{
currentcallback
();
}
}
},
timeoutwrapper
=
function
()
{
callbackwrapper
();
window
.
setTimeout
(
timeoutwrapper
,
500
);
};
function
UrlHandler
()
{}
UrlHandler
.
prototype
=
{
'
generateUrl
'
:
function
(
path
,
options
)
{
var
pathhash
,
hash
=
'
#
'
,
key
;
if
(
path
!==
undefined
)
{
hash
+=
encodeURIComponent
(
path
);
}
hash
=
hash
.
replace
(
/%2F/g
,
'
/
'
);
pathhash
=
hash
;
for
(
key
in
options
)
{
if
(
options
.
hasOwnProperty
(
key
))
{
if
(
hash
===
pathhash
)
{
hash
=
hash
+
'
?
'
;
}
else
{
hash
=
hash
+
'
&
'
;
}
hash
+=
encodeURIComponent
(
key
)
+
'
=
'
+
encodeURIComponent
(
options
[
key
]);
}
}
return
hash
;
},
'
go
'
:
function
(
path
,
options
)
{
window
.
location
.
hash
=
this
.
generateUrl
(
path
,
options
);
},
'
redirect
'
:
function
(
path
,
options
)
{
var
host
=
window
.
location
.
protocol
+
'
//
'
+
window
.
location
.
host
+
window
.
location
.
pathname
+
window
.
location
.
search
;
window
.
location
.
replace
(
host
+
this
.
generateUrl
(
path
,
options
));
// window.location.replace(window.location.href.replace(/#.*/, ""));
},
'
getPath
'
:
function
()
{
var
hash
=
getRawHash
(),
result
=
''
;
if
(
hash
!==
undefined
)
{
result
=
decodeURIComponent
(
hash
.
split
(
'
?
'
)[
0
]);
}
return
result
;
},
'
getOptions
'
:
function
()
{
var
options
=
{},
hash
=
getRawHash
(),
subhashes
,
subhash
,
index
,
keyvalue
;
if
(
hash
!==
undefined
)
{
hash
=
hash
.
split
(
'
?
'
)[
1
];
if
(
hash
!==
undefined
)
{
subhashes
=
hash
.
split
(
'
&
'
);
for
(
index
in
subhashes
)
{
if
(
subhashes
.
hasOwnProperty
(
index
))
{
subhash
=
subhashes
[
index
];
if
(
subhash
!==
''
)
{
keyvalue
=
subhash
.
split
(
'
=
'
);
if
(
keyvalue
.
length
===
2
)
{
options
[
decodeURIComponent
(
keyvalue
[
0
])]
=
decodeURIComponent
(
keyvalue
[
1
]);
}
}
}
}
}
}
return
options
;
},
'
onhashchange
'
:
function
(
callback
)
{
previousurl
=
undefined
;
currentcallback
=
callback
;
if
(
!
hashchangeinitialized
)
{
if
(
window
.
onhashchange
!==
undefined
)
{
$
(
window
).
bind
(
'
hashchange
'
,
callbackwrapper
);
window
.
setTimeout
(
callbackwrapper
);
}
else
{
timeoutwrapper
();
}
hashchangeinitialized
=
true
;
}
},
};
// Expose to the global object
$
.
url
=
new
UrlHandler
();
}(
window
,
jQuery
));
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