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
f55aeaf7
Commit
f55aeaf7
authored
Jun 04, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fwd postMessage to preview gadget, digest and display
parent
ad7d15e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
40 deletions
+98
-40
gadget/filebrowser_and_preview.js
gadget/filebrowser_and_preview.js
+29
-3
gadget/preview.js
gadget/preview.js
+69
-37
No files found.
gadget/filebrowser_and_preview.js
View file @
f55aeaf7
...
@@ -3,6 +3,23 @@
...
@@ -3,6 +3,23 @@
"
use strict
"
;
"
use strict
"
;
(
function
(
document
,
$
)
{
(
function
(
document
,
$
)
{
var
myIndexOf
=
function
(
path
,
contains
)
{
var
len
=
path
.
length
;
var
wordLen
=
contains
.
length
;
for
(
var
i
=
0
;
i
<
len
;
i
++
)
{
var
j
=
0
;
for
(
j
=
0
;
j
<
wordLen
;
j
++
)
{
if
(
path
[
i
+
j
]
!=
contains
[
j
])
{
break
;
}
}
if
(
j
==
wordLen
)
{
return
i
;
}
}
return
-
1
;
};
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
...
@@ -15,10 +32,19 @@
...
@@ -15,10 +32,19 @@
return
null
;
return
null
;
};
};
// this is our "interactor", it only knows one other iFrame
// so we post to this one!
var
handler
=
function
(
event
)
{
var
handler
=
function
(
event
)
{
console
.
log
(
event
.
data
);
var
frames
=
document
.
getElementsByTagName
(
"
iframe
"
),
frame
,
i
;
console
.
log
(
"
hello inside handler
"
);
for
(
i
=
0
;
i
<
frames
.
length
;
i
+=
1
)
{
console
.
log
(
event
);
frame
=
frames
[
i
];
if
(
myIndexOf
(
event
.
source
.
location
.
pathname
,
frame
.
getAttribute
(
"
src
"
).
split
(
"
?
"
)[
0
]
)
<
0
)
{
frame
.
contentWindow
.
postMessage
(
event
.
data
,
window
.
location
.
href
);
}
}
};
};
var
mapUrl
=
function
(
url
)
{
var
mapUrl
=
function
(
url
)
{
...
...
gadget/preview.js
View file @
f55aeaf7
...
@@ -8,49 +8,81 @@
...
@@ -8,49 +8,81 @@
/*global document, jQuery */
/*global document, jQuery */
"
use strict
"
;
"
use strict
"
;
(
function
(
document
,
$
)
{
(
function
(
document
,
$
)
{
$
(
document
).
ready
(
function
()
{
var
ajaxGet
=
function
(
src
,
cb
)
{
var
mapUrl
=
function
(
url
)
{
$
.
ajax
({
var
searchString
=
url
.
href
.
split
(
"
?
"
)[
1
],
method
:
'
GET
'
,
fileToDisplay
;
url
:
src
,
context
:
$
(
'
body
'
),
if
(
searchString
)
{
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
fileToDisplay
=
getParameter
(
searchString
,
"
file
"
);
$
(
this
).
text
(
errorThrown
);
if
(
fileToDisplay
)
{
},
$
.
ajax
({
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
method
:
'
GET
'
,
cb
(
value
,
textStatus
,
jqXHR
);
url
:
fileToDisplay
,
}
context
:
$
(
'
body
'
),
});
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
};
$
(
this
).
text
(
errorThrown
);
},
var
handler
=
function
(
event
)
{
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
ajaxGet
(
event
.
data
,
function
(
value
,
status
,
jqXHR
)
{
if
(
value
===
""
)
{
ajaxGet
(
value
.
_links
.
enclosure
.
href
,
function
(
value
,
status
,
jqXHR
)
{
$
(
this
).
text
(
"
file not found
"
);
if
(
value
===
""
)
{
}
else
{
window
.
document
.
body
.
innerHTML
=
"
file not found
"
;
$
(
this
).
text
(
value
);
}
else
{
}
window
.
document
.
body
.
innerHTML
=
value
;
},
});
}
}
}
else
{
});
$
(
this
).
text
(
"
no file to display
"
);
});
}
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
);
}
},
});
}
}
};
}
else
{
$
(
this
).
text
(
"
no file to display
"
);
}
};
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
for
(
i
=
0
;
i
<
params
.
length
;
i
++
)
{
for
(
i
=
0
;
i
<
params
.
length
;
i
++
)
{
val
=
params
[
i
].
split
(
"
=
"
);
val
=
params
[
i
].
split
(
"
=
"
);
if
(
val
[
0
]
==
paramName
)
{
if
(
val
[
0
]
==
paramName
)
{
return
decodeURIComponent
(
val
[
1
]);
return
decodeURIComponent
(
val
[
1
]);
}
}
}
return
null
;
}
};
return
null
;
};
$
(
document
).
ready
(
function
()
{
// mapUrl(window.location);
mapUrl
(
window
.
location
);
if
(
window
.
addEventListener
){
window
.
addEventListener
(
"
message
"
,
handler
,
false
)
}
else
{
window
.
attachEvent
(
"
onmessage
"
,
handler
)
}
});
});
}(
document
,
jQuery
));
}(
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