# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)

# ---------- Document And Document Element Information -------------------------------------------------------------
#
# Dependencies	: main.kmm ($macroPrefBranch, JS, ExecMacros)
# Resources	: [MacroFolder]\docinfo\docinfo.css
# Preferences	: kmeleon.plugins.macros.docinfo.forceTab.images
#		  kmeleon.plugins.macros.docinfo.forceTab.links
#		  kmeleon.plugins.macros.docinfo.forceTab.linkedImages
#
# ------------------------------------------------------------------------------------------------------------------

DocInfo_Image{
macroinfo=_("View image properties");
$JS_doitImage="a=false;var s='"._("Image Properties:")."\\n\\n"._("URL:\\t%s")."\\n'.replace(/%s/,unescape(src));s+=(naturalWidth!=width||naturalHeight!=height?'"._("Size:\\t%w x %h Pixels (scaled to %W x %H)")."'.replace(/%w/,naturalWidth).replace(/%h/,naturalHeight):'"._("Size:\\t%W x %H Pixels")."').replace(/%W/,width).replace(/%H/,height);if(alt)s+='\\n"._("Alt. Text:\\t%s")."'.replace(/%s/,alt);if(longDesc){s+='\\n\\n"._("A description is available for this image. Do you want to view it now?")."';if(confirm(s)){if(top.location==self.location)open(longDesc);top.location.href=longDesc}}else alert(s)";
$JS_doitInput="a=false;var s='"._("Image Properties:")."\\n\\n"._("URL:\\t%s")."'.replace(/%s/,unescape(src));if(alt)s+='\\n"._("Alt. Text:\\t%s")."'.replace(/%s/,alt);alert(s);a=false"; &JS_hndlImage;
}
DocInfo_Link{
macroinfo=_("View link properties");
$JS_doitLink="j=a.length;var l=getAttribute('hreflang'),p=getAttribute('ping'),t=getAttribute('type'),s='"._("Link Properties:")."\\n\\n"._("URL:\\t%s")."'.replace(/%s/,unescape(href));if(p)s+='\\n"._("Ping:\\t%s")."'.replace(/%s/,unescape(p));if(l||t){s+='\\n\\n"._("Properties of Linked Resource:")."\\n';if(t)s+='\\n"._("MIME Type:\\t%s")."'.replace(/%s/,t);if(l)s+='\\n"._("Language:\\t%s")."'.replace(/%s/,l)}s+='\\n\\n"._("Do you want to view the linked resource now?")."';if(confirm(s)){if(top.location==self.location)open(href);top.location.href=href}"; &JS_hndlLink;
}

DocInfo_Page_Links{
macroinfo=_("View all links in the current page");
&_DocInfo_lstLinks; $ExecMacros="JS_hndlDocs"; $ForceTab=$_DocInfo_ForceTab; &ExecMacros_Popups;
}
DocInfo_Frame_Links{
macroinfo=_("View all links in the current frame");
&_DocInfo_lstLinks; $ExecMacros="JS_hndlDoc";  $ForceTab=$_DocInfo_ForceTab; &ExecMacros_Popups;
}

DocInfo_Page_LinkedImages{
macroinfo=_("View all images linked by the current page");
&_DocInfo_lstLinkedImages; $ExecMacros="JS_hndlDocs"; $ForceTab=$_DocInfo_ForceTab; &ExecMacros_Popups;
}
DocInfo_Frame_LinkedImages{
macroinfo=_("View all images linked by the current frame");
&_DocInfo_lstLinkedImages; $ExecMacros="JS_hndlDoc";  $ForceTab=$_DocInfo_ForceTab; &ExecMacros_Popups;
}

DocInfo_Page_Images{
macroinfo=_("View all images in the current page");
&_DocInfo_lstImages; $ExecMacros="JS_hndlDocs"; $ForceTab=$_DocInfo_ForceTab; &ExecMacros_Popups;
}
DocInfo_Frame_Images{
macroinfo=_("View all images in the current frame");
&_DocInfo_lstImages; $ExecMacros="JS_hndlDoc";  $ForceTab=$_DocInfo_ForceTab; &ExecMacros_Popups;
}

# ----- PRIVATE

$_DocInfo_ForceTab=false;
$_DocInfo_FrameError="txt+='<fieldset><legend>"._("(unknown)")."</legend><p>"._("A script error occured accessing this frame. Probably this frame belongs to another domain and access was denied for security reasons.")."</p></fieldset>'";
$_DocInfo_PopupStyle="left=0,top=0,width=600,height=300,minimizable=yes,resizable=yes,status=yes,scrollbars=yes";
$_DocInfo_StyleSheet=getfolder(MacroFolder)."\\docinfo\\docinfo.css";

_DocInfo_lstLinks{
$_DocInfo_ForceTab=getpref(BOOL,$macroPrefBranch."docinfo.forceTab.links");
$JS_func="with(document)var h='kmHOST',l='kmLINK',w=window.name,n=(w&&!getElementsByTagName('body')[0])?w.replace(h,''):Math.floor(Math.random()*1000),hstWinName=window.name=h+n,lnkWinName=l+n,cnt=0,nlf='"._("No links found.")."',tit='"._("Links: %s")."'.replace(/%s/,(title)?title:unescape(URL)),txt='';";
$JS_doit="if(getElementsByTagName('body')[0]){txt+='\\n<fieldset><legend>'+((title)?title:unescape(URL)).link(URL)+'</legend><ol>';cnt+=links.length;if(links.length)for(var j=0;j<links.length;j++)txt+='\\n<li>'+((links[j].text)?links[j].text.link(links[j]):unescape(links[j]).link(links[j]))+'&nbsp;</li>';else txt+='\\n<p>'+nlf+'</p>';txt+='</ol>\\n</fieldset>'}";
$JS_last="if(cnt){var html='<html><head><title>'+tit+'</title><style type=\"text/css\">\\n".gsub("\n","\\n",readfile($_DocInfo_StyleSheet))."\\n</style><base target=\"'+hstWinName+'\"></head>\\n<body class=\"km_DocInfo_lstLinks\">'+txt+'\\n</body></html>';var lnkWin=open('data:text/html,'+encodeURIComponent(html),lnkWinName,'".$_DocInfo_PopupStyle."');lnkWin.focus()}else alert(nlf)";
$JS_fail=$_DocInfo_FrameError;
}
_DocInfo_lstLinkedImages{
$_DocInfo_ForceTab=getpref(BOOL,$macroPrefBranch."docinfo.forceTab.linkedImages");
$JS_func="with(document)var ext=new Array('bmp','gif','giff','jpg','jpeg','png','ico'),cnt=0,nlf='"._("No linked images found.")."',tit='"._("Linked Images: %s")."'.replace(/%s/,(title)?title:unescape(URL)),txt='';";
$JS_doit="if(getElementsByTagName('body')[0]){var url=new Array();function add(s){for(var j=0;j<url.length;j++)if(s==url[j])return;for(var j=0,x=s.split('.');j<ext.length;j++)if(x[x.length-1].toLowerCase()==ext[j])url[url.length]=s}for(var j=0,l=links;j<l.length;j++)add(l[j].href);txt+='\\n<fieldset><legend>'+((title)?title:unescape(URL)).link(URL)+'</legend><ol>';cnt+=url.length;if(url.length)for(var j=0;j<url.length;j++)txt+='\\n<li><img src=\"'+url[j]+'\"></li>';else txt+='\\n<p>'+nlf+'</p>';txt+='</ol>\\n</fieldset>'}";
$JS_last="if(cnt){var html='<html><head><title>'+tit+'</title><style type=\"text/css\">\\n".gsub("\n","\\n",readfile($_DocInfo_StyleSheet))."\\n</style></head>\\n<body class=\"km_DocInfo_lstLinkedImages\">'+txt+'\\n</body></html>';var imgWin=open('data:text/html,'+encodeURIComponent(html),'kmLINKIMG'+Math.floor(Math.random()*1000),'".$_DocInfo_PopupStyle."');}else alert(nlf)";
$JS_fail=$_DocInfo_FrameError;
}
_DocInfo_lstImages{
$_DocInfo_ForceTab=getpref(BOOL,$macroPrefBranch."docinfo.forceTab.images");
$JS_func="with(document)var cnt=0,nif='"._("No images found.")."',tit='"._("Images: %s")."'.replace(/%s/,(title)?title:unescape(URL)),txt='';";
$JS_doit="if(getElementsByTagName('body')[0]){var url=new Array();function add(s){for(var j=0;j<url.length;j++)if(s==url[j])return;url[url.length]=s}for(var j=0,i=images;j<i.length;j++)add(i[j].src);for(var j=0,i=getElementsByTagName('input');j<i.length;j++)if((i[j].getAttribute('type')=='image')&&(i[j].getAttribute('src')))add(i[j].src);txt+='\\n<fieldset><legend>'+((title)?title:unescape(URL)).link(URL)+'</legend><ol>';cnt+=url.length;if(url.length)for(var j=0;j<url.length;j++)txt+='\\n<li><img src=\"'+url[j]+'\"></li>';else txt+='\\n<p>'+nif+'</p>';txt+='</ol>\\n</fieldset>'}";
$JS_last="if(cnt){var html='<html><head><title>'+tit+'</title><style type=\"text/css\">\\n".gsub("\n","\\n",readfile($_DocInfo_StyleSheet))."\\n</style></head>\\n<body class=\"km_DocInfo_lstImages\">'+txt+'\\n</body></html>';var imgWin=open('data:text/html,'+encodeURIComponent(html),'kmIMG'+Math.floor(Math.random()*1000),'".$_DocInfo_PopupStyle."');}else alert(nif)";
$JS_fail=$_DocInfo_FrameError;
}

_DocInfo_BuildMenu{
# context menus
setmenu(ImageProperties,macro,"Image &Properties",DocInfo_Image,0);
setmenu(LinkProperties,macro,"Link &Properties",DocInfo_Link,0);
$__m="Page Pro&perties";
setmenu($__m,macro,"Li&nks",DocInfo_Page_Links,ID_VIEW_SOURCE);
setmenu($__m,macro,"Link&ed Images",DocInfo_Page_LinkedImages,ID_VIEW_SOURCE);
setmenu($__m,macro,"Im&ages",DocInfo_Page_Images,ID_VIEW_SOURCE);
$__m="Page &Properties";
setmenu($__m,macro,"Li&nks",DocInfo_Page_Links,ID_VIEW_IMAGE);
setmenu($__m,macro,"Link&ed Images",DocInfo_Page_LinkedImages,ID_VIEW_IMAGE);
setmenu($__m,macro,"Im&ages",DocInfo_Page_Images,ID_VIEW_IMAGE);
$__m="Frame &Properties";
setmenu($__m,macro,"Li&nks",DocInfo_Frame_Links,ID_VIEW_IMAGE);
setmenu($__m,macro,"Link&ed Images",DocInfo_Frame_LinkedImages,ID_VIEW_IMAGE);
setmenu($__m,macro,"Im&ages",DocInfo_Frame_Images,ID_VIEW_IMAGE);
}
$OnInit=$OnInit."_DocInfo_BuildMenu;";

# ------------------------------------------------------------------------------------------------------------------
$macroModules=$macroModules."DocInfo;";