1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| /**
* Created by Trebly on 27/08/2015.
*/
var OpenOrReusePageOrFrag = function (url, pWname, rfrag,libel,idSrc) {/* version b50826 */
/**
* url : full url
* pwname : name previously given to the window (tab) or new unique name
* rfrag : the fragment to focus
* libel : title of the window
* idSrc : the identifier to manages the extended window object for data and cookie management into the others parts of script
*/
/**
* Principle :
* if pWname the one of the current page (window) then focus the fragment
* if not : verify if it is set
* - if yes : focus the fragment into the window object and show (focus) the window
* - if not : open new with
* -> if yes : focus the frag into the windows and then the widow (which show it)
* -> if not : open it
* The url must be split or not used if window exist : the window.open considers that if url is not exactly (including frag) the same it must be updated. Then use first window.open("",wmane) and after check window.open(url,wname) to populate it
* So we get the window, we get the hash and the new full url (with hash) and open it on right element
*/
if (window.name === pWname) { /* B50828 - The function can be called from the current window then we just target the frag */
var t= document.getElementById(rfrag);
if (t===null) {
alert('The fragment (element link) doesn\'t exist) : ['+libel+']');
return false;
}
set_header_top_position(t);
t.focus();
return true;
}
var w = window.open("", pWname); /* Try to find if pWanme window exists : this opens an empty tab if not known */
if (w.document.body.innerHTML === "") { /* Check if the reference contains data : if so it is not new */
alert("The window (tab) [" + pWname +"] doesn't exist a new tab is opened");
window.open(url, pWname); /* if not open new */
set_new_TOC_tab(url,pWname,libel,idSrc); // set_new_TOC_tab : crée ou met à jour le cookie
w.focus();
return true;
}
else { /* it exists then reopen will update url with frag */
var frag = w.document.getElementById(rfrag); /* Get the rfrag id element */
if (frag !== null) { /* If found we focus */
alert("The window (tab) [" + pWname +"] exist and found and the element [rfrag] exist too the tab at the frag element is focused");
frag.focus(); /* in w but not show it */
w.focus(); /* show w in navigator */
/* note : w = window.open(url, pWname); cannot be used it updates the window if the rfrag is not the current hash */
return true; /* Will allow to end the onclck sequence */
}
else { /* frag don't exist it should not be targetted */
alert("System error : the fragment [" + rfrag + "] \nhas not been found into the display section\n[" + pWname +
"]\nEven you have an obvious explanation (broken link) for example, if not\n" +
"please report this error to the plugin author\nThe new tab is going to be opened on current focused element by default");
/* Just focus the window after the alert */
w.focus();
return true; /* Will allow to end the onclck sequence */
/* w = window.open(url, pWname); */
}
/* the structure of soft should make that reach this point is not normal */
alert ("System error :OpenOrReusePageOrFrag b51007 - this point should not ever be reached");
return false;
}
} |
Partager