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
Hide 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,44 +17,21 @@
};
var
handler
=
function
(
event
)
{
ajaxGet
(
event
.
data
,
function
(
value
,
status
,
jqXHR
)
{
ajaxGet
(
value
.
_links
.
enclosure
.
href
,
function
(
value
,
status
,
jqXHR
)
{
if
(
value
===
""
)
{
window
.
document
.
body
.
innerHTML
=
"
file not found
"
;
}
else
{
window
.
document
.
body
.
innerHTML
=
value
;
}
});
});
}
var
mapUrl
=
function
(
url
)
{
var
searchString
=
url
.
href
.
split
(
"
?
"
)[
1
],
fileToDisplay
;
if
(
searchString
)
{
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
);
if
(
fileToDisplay
)
{
$
.
ajax
({
method
:
'
GET
'
,
url
:
fileToDisplay
,
context
:
$
(
'
body
'
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
if
(
value
===
""
)
{
$
(
this
).
text
(
"
file not found
"
);
}
else
{
$
(
this
).
text
(
value
);
}
},
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
===
""
)
{
window
.
document
.
body
.
innerHTML
=
"
file not found
"
;
}
else
{
window
.
document
.
body
.
innerHTML
=
value
;
}
});
}
}
else
{
$
(
this
).
text
(
"
no file to display
"
);
});
}
}
;
}
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
...
...
@@ -75,18 +45,64 @@
return
null
;
};
$
(
document
).
ready
(
function
()
{
// mapUrl(window.location);
var
mapUrl
=
function
(
searchString
)
{
var
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
),
scope
,
register
,
service
;
if
(
fileToDisplay
)
{
$
.
ajax
({
method
:
'
GET
'
,
url
:
fileToDisplay
,
context
:
$
(
'
body
'
),
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
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");
}
});
}
});
}
}
$
(
document
).
ready
(
function
()
{
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