File tree 3 files changed +35
-9
lines changed
3 files changed +35
-9
lines changed Original file line number Diff line number Diff line change 922
922
* @returns {object } EpicEditor will be returned
923
923
*/
924
924
EpicEditor . prototype . preview = function ( theme ) {
925
- var self = this ;
926
-
925
+ var self = this
926
+ , x
927
+ , anchors ;
928
+
927
929
theme = theme || self . settings . basePath + self . settings . theme . preview ;
928
930
929
931
_replaceClass ( self . getElement ( 'wrapper' ) , 'epiceditor-edit-mode' , 'epiceditor-preview-mode' ) ;
935
937
else if ( self . previewerIframeDocument . getElementById ( 'theme' ) . name !== theme ) {
936
938
self . previewerIframeDocument . getElementById ( 'theme' ) . href = theme ;
937
939
}
938
-
940
+
939
941
// Add the generated HTML into the previewer
940
942
self . previewer . innerHTML = self . exportFile ( null , 'html' ) ;
941
-
943
+
944
+ // Because we have a <base> tag so all links open in a new window we
945
+ // need to prevent hash links from opening in a new window
946
+ anchors = self . previewer . getElementsByTagName ( 'a' ) ;
947
+ for ( x in anchors ) {
948
+ // If the link is a hash AND the links hostname is the same as the
949
+ // current window's hostname (same page) then set the target to self
950
+ if ( anchors [ x ] . hash && anchors [ x ] . hostname == window . location . hostname ) {
951
+ anchors [ x ] . target = '_self' ;
952
+ }
953
+ }
954
+
942
955
// Hide the editor and display the previewer
943
956
if ( ! self . is ( 'fullscreen' ) ) {
944
957
self . editorIframe . style . display = 'none' ;
You can’t perform that action at this time.
0 commit comments