Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
renderjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
renderjs
Commits
2c2efaf7
Commit
2c2efaf7
authored
Jun 10, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
convert mapUrl from pages to API function renderJs.mapUrl()
parent
5baa2b91
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
107 deletions
+58
-107
renderjs.js
renderjs.js
+58
-107
No files found.
renderjs.js
View file @
2c2efaf7
...
@@ -489,13 +489,17 @@
...
@@ -489,13 +489,17 @@
};
};
// => interaction gadget and listener
// => interaction gadget and listener
// if initializing config is provided in the URL, we may have an src=[]
// TODO: how to extend to include external HTML pages/external methods
// of links to additional functional libraries (?), which should be
// available here. So we should load them.
priv
.
createServiceMap
=
function
(
spec
)
{
priv
.
createServiceMap
=
function
(
spec
)
{
var
rootSrc
=
(
spec
===
undefined
||
spec
.
_links
.
self
.
href
===
""
)
?
window
.
location
.
href
:
spec
.
_links
.
self
.
href
// create service object
that
.
gadgetService
=
{
that
.
gadgetService
=
{
"
root
"
:
spec
.
root
||
window
.
location
.
href
,
"
root
"
:
rootSrc
,
"
directories
"
:
spec
.
src
||
[],
// directories should be links to external HTML pages containing
// <links> with callable methods?
"
directories
"
:
[],
"
map
"
:
[]
"
map
"
:
[]
};
};
...
@@ -983,89 +987,69 @@
...
@@ -983,89 +987,69 @@
// => initialize
// => initialize
priv
.
initialize
=
function
()
{
priv
.
initialize
=
function
()
{
// both root and iFrame try to map location.search, either for initial
// check if root gadget URL has ?-configuration attached
// configuration or to retrieve the root when inside an iFrame
that
.
mapUrl
(
window
.
location
.
search
,
function
(
spec
)
{
var
spec
=
that
.
mapUrl
(
window
.
location
.
search
);
// all renderJs instances have a serviceMap = directory of available methods
priv
.
createServiceMap
(
spec
);
// create index
// trigger => find HTML gadgets in root document
priv
.
createGadgetIndex
(
);
priv
.
findGadgetinHTML
(
spec
);
// create tree
// trigger => find HTML coded interactions in root document
priv
.
createGadgetTree
(
);
priv
.
findServiceInHTML
(
spec
);
// all instances of renderJs should have an serviceMap
// create index
priv
.
createServiceMap
(
spec
);
priv
.
createGadgetIndex
(
);
// trigger => find HTML gadgets in root document
// create tree
priv
.
findGadgetinHTML
(
spec
);
priv
.
createGadgetTree
(
);
// trigger => find HTML coded interactions in root document
},
true
);
priv
.
findServiceInHTML
(
spec
);
// expose API
// expose API
window
.
renderJs
=
that
;
window
.
renderJs
=
that
;
};
};
// => map data-URL internally
priv
.
mapUrlInternal
=
function
(
queryString
)
{
var
dataUrl
=
queryString
.
slice
(
1
).
split
(
"
=
"
)[
1
];
return
$
.
ajax
({
method
:
'
GET
'
,
url
:
dataUrl
,
context
:
$
(
'
body
'
)
})
.
fail
(
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
return
jqXHR
,
textStatus
,
errorThrown
;
})
.
then
(
function
(
value
,
textStatus
,
jqXHR
)
{
// preprocessing, if needed
return
value
,
textStatus
,
jqXHR
;
});
};
// => "global" errorHandler
priv
.
errorHandler
=
function
(
message
,
internal
)
{
return
(
internal
===
true
)
?
undefined
:
message
+
"
specified
"
,
"
405
"
,
{};
};
// ================ public API (call on renderJs and $(elem) ===========
// ================ public API (call on renderJs and $(elem) ===========
// => mapURL searchstring
that
.
mapUrl
=
function
(
spec
,
internal
)
{
// => public API to map a URL via Ajax and run the result through a callback
var
key
,
that
.
mapUrl
=
function
(
url
,
callback
,
internal
)
{
obj
,
var
queryString
=
typeof
url
===
"
string
"
?
url
:
url
.
search
;
parsedJSON
,
if
(
queryString
)
{
configuration
=
{};
priv
.
mapUrlInternal
(
queryString
).
done
(
callback
?
callback
:
priv
.
errorHandler
(
"
no callback
"
,
internal
)
if
(
spec
!==
undefined
&&
spec
!==
""
)
{
);
obj
=
spec
.
slice
(
1
).
split
(
"
=
"
);
key
=
obj
[
0
];
switch
(
key
)
{
case
"
string
"
:
case
"
url
"
:
configuration
.
root
=
priv
.
decodeURI
(
obj
[
1
]);
break
;
case
"
json
"
:
parsedJSON
=
JSON
.
parse
(
priv
.
decodeURI
(
obj
[
1
]));
configuration
.
root
=
parsedJSON
.
root
||
window
.
location
.
pathname
;
configuration
.
src
=
priv
.
decodeURIArray
(
parsedJSON
.
src
)
||
[];
break
;
case
"
hal
"
:
parsedJSON
=
JSON
.
parse
(
priv
.
decodeURI
(
obj
[
1
]));
configuration
.
root
=
parsedJSON
.
_links
.
self
||
window
.
location
.
pathname
;
configuration
.
src
=
priv
.
decodeURIArray
(
parsedJSON
.
src
)
||
[];
break
;
case
"
file
"
:
$
.
ajax
({
method
:
'
GET
'
,
url
:
obj
[
1
],
context
:
$
(
'
body
'
),
fail
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
configuration
=
{
"
errorThrown
"
:
errorThrown
,
"
textStatus
"
:
textStatus
,
"
jqXHR
"
:
jqXHR
}
},
done
:
function
(
value
,
textStatus
,
jqXHR
)
{
configuration
=
{
"
value
"
:
value
,
"
textStatus
"
:
textStatus
,
"
jqXHR
"
:
jqXHR
}
}
});
break
;
default
:
// no allowable-type - ignore configuration-parameter!
configuration
.
root
=
window
.
location
.
href
;
configuration
.
src
=
[];
break
;
}
}
else
{
}
else
{
configuration
=
{
"
root
"
:
window
.
location
.
href
};
// we still need to run a callback, if only internally?
internal
?
(
callback
?
callback
()
:
priv
.
errorHandler
(
"
no callback
"
))
:
priv
.
errorHandler
(
"
no query parameter
"
)
}
}
return
configuration
;
};
};
// => publish a service to this instance (and root instance)
// => publish a service to this instance (and root instance)
that
.
addService
=
$
.
fn
.
addService
=
function
(
options
)
{
that
.
addService
=
$
.
fn
.
addService
=
function
(
options
)
{
var
addressArray
=
window
.
location
.
href
.
split
(
"
?
"
),
targetUrl
;
var
addressArray
=
window
.
location
.
href
.
split
(
"
?
"
),
targetUrl
;
...
@@ -1247,28 +1231,6 @@
...
@@ -1247,28 +1231,6 @@
// {command}/{method}/{scope}/{interaction}/
// {command}/{method}/{scope}/{interaction}/
var
internalRequest
=
priv
.
mapBrowserURL
(
this
.
url
);
var
internalRequest
=
priv
.
mapBrowserURL
(
this
.
url
);
if
(
internalRequest
.
command
===
"
call
"
)
{
// if (this.method === "POST") {
//
// } else {
// this.respond(405, {}, "");
// }
}
else
if
(
internalRequest
.
command
===
"
delegate
"
)
{
// if (this.method === "POST") {
//
// } else {
// this.respond(405, {}, "");
// }
}
else
if
(
internalRequest
.
command
===
"
request
"
)
{
// if (this.method === "POST") {
//
// } else {
// this.respond(405, {}, "");
// }
}
else
{
// this.respond(404, {}, "");
}
// =================== previous ====================
// =================== previous ====================
// localStorage handler
// localStorage handler
...
@@ -1389,17 +1351,6 @@
...
@@ -1389,17 +1351,6 @@
// still inside child frame
// still inside child frame
// add to tree, so lookup is possible when service is requested
// add to tree, so lookup is possible when service is requested
config
=
JSON
.
parse
(
this
.
requestBody
);
config
=
JSON
.
parse
(
this
.
requestBody
);
// // we don't need this here!
// // but first get the internal router to work, so we only
// // handle data-uris
// window.parent.postMessage({
// "type": "tree/update",
// "options": {
// "id": config.self,
// "src": config.src,
// "children": []
// }
// }, "*");
// generate a url to be called once the service is requested
// generate a url to be called once the service is requested
// this is a parent > child URL, so we delegate
// this is a parent > child URL, so we delegate
...
...
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