Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
renderjs
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Ivan Tyagov
renderjs
Commits
5e269eda
Commit
5e269eda
authored
Jun 07, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated first example to only using Ajax links
parent
8a1e595d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
49 deletions
+65
-49
gadget/preview_by_hash_change.js
gadget/preview_by_hash_change.js
+65
-49
No files found.
gadget/preview_by_hash_change.js
View file @
5e269eda
// > grab URL with parameters of file to open
// > call addGadget with those parameters?
// > display a file from some storage (local/session)
// > storage type will also be a parameter in the url?
// return "browser://localstorage/foo"
// file=browser%3A%2F%2Flocalstorage%2Ffoo
/*global document, jQuery */
"
use strict
"
;
(
function
(
document
,
$
)
{
...
...
@@ -24,6 +17,10 @@
};
var
handler
=
function
(
event
)
{
var
type
=
event
.
data
.
type
,
method
=
type
?
type
.
split
(
"
/
"
)[
0
]
:
undefined
;
// prevent both renderJs and page events triggering on "run"
if
(
type
===
undefined
||
method
!==
"
run
"
)
{
ajaxGet
(
event
.
data
,
function
(
value
,
status
,
jqXHR
)
{
ajaxGet
(
value
.
_links
.
enclosure
.
href
,
function
(
value
,
status
,
jqXHR
)
{
if
(
value
===
""
)
{
...
...
@@ -34,13 +31,26 @@
});
});
}
}
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
for
(
i
=
0
;
i
<
params
.
length
;
i
++
)
{
val
=
params
[
i
].
split
(
"
=
"
);
if
(
val
[
0
]
==
paramName
)
{
return
decodeURIComponent
(
val
[
1
]);
}
}
return
null
;
};
var
mapUrl
=
function
(
url
)
{
var
searchString
=
url
.
href
.
split
(
"
?
"
)[
1
],
fileToDisplay
;
var
mapUrl
=
function
(
searchString
)
{
var
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
),
scope
,
register
,
service
;
if
(
searchString
)
{
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
);
if
(
fileToDisplay
)
{
$
.
ajax
({
method
:
'
GET
'
,
...
...
@@ -50,43 +60,49 @@
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
if
(
value
===
""
)
{
$
(
this
).
text
(
"
file not found
"
);
}
else
{
$
(
this
).
text
(
value
);
}
scope
=
value
.
_links
.
scope
.
href
.
slice
(
0
,
-
1
).
split
(
/
[/]
+/
).
pop
();
register
=
value
.
_links
.
call
.
href
.
replace
(
"
{method}
"
,
"
register
"
)
.
replace
(
"
{scope}
"
,
scope
)
.
replace
(
"
{interaction}
"
,
""
);
service
=
{
"
type
"
:
"
service/test
"
,
"
src
"
:
encodeURIComponent
(
window
.
location
.
href
),
"
rel
"
:
"
preview
"
,
"
self
"
:
window
.
frameElement
.
id
};
$
.
ajax
({
method
:
'
POST
'
,
url
:
register
,
context
:
$
(
this
),
data
:
JSON
.
stringify
(
service
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
console
.
log
(
"
registration failed:
"
+
errorThrown
);
},
});
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
// console.log("registration successful");
}
}
else
{
$
(
this
).
text
(
"
no file to display
"
);
});
}
};
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
for
(
i
=
0
;
i
<
params
.
length
;
i
++
)
{
val
=
params
[
i
].
split
(
"
=
"
);
if
(
val
[
0
]
==
paramName
)
{
return
decodeURIComponent
(
val
[
1
]);
});
}
}
return
null
;
};
$
(
document
).
ready
(
function
()
{
// mapUrl(window.location);
var
search
=
window
.
location
.
search
;
if
(
search
)
{
mapUrl
(
search
.
slice
(
1
));
}
else
{
$
(
"
body
"
).
text
(
"
No parameter found in url
"
);
}
if
(
window
.
addEventListener
){
window
.
addEventListener
(
"
message
"
,
handler
,
false
)
}
else
{
window
.
attachEvent
(
"
onmessage
"
,
handler
)
}
// $(window).on('hashchange', function() {
// console.log("LE HASH CHANGED");
// });
// $(window).trigger("hashchange");
});
}(
document
,
jQuery
));
\ No newline at end of file
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