TinyPortal

Development => Block Codes => Topic started by: brianjw on January 15, 2007, 05:38:48 PM

Title: [BLOCK] All in 1 User Preference
Post by: brianjw on January 15, 2007, 05:38:48 PM
I built this just in case some people wanted all these options put together.

What Comes With It
- Add to favorites link
- Set homepage link

Instructions to build
none.

Code for this snippet (mainly made for a left or right block but you can change it around)

<a href="#" onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://SITEURL.com');">Set As Your Homepage</a>
<u>
<span STYLE="color:blue;cursor:hand;" onclick = "window.external.AddFavorite(location.href, document.title);"> Add Page To Favorites
</span>
</u>


Code Editing (personalized for your site)
1. Change http://SITEURL.com to your website domain that you want to be set as homepage when user clicks on it. You can also modify the link text you want shown to your visitors.
2. To change the color of the link shown you need to modify this code: color:blue. You can also modify the link text you want shown to your visitors.

This script is nothing much... I just wanted it to be easier for myself and other people to find this script the easy way! ;)

This script has to be put into a scriptbox and is better viewed set as:
O Use frame, but not title
O Do not allow block to collapse

Demo: It is html+javascript and there isn't really any demo for now :)
Title: Re: [BLOCK] All in 1 User Preference
Post by: RoarinRow on January 15, 2007, 06:50:16 PM
Very cool, thanks brian!   :up:
Title: Re: [BLOCK] All in 1 User Preference
Post by: carver on January 15, 2007, 08:23:33 PM
After trying Brian's script which does work. just not for non-Internet Explore Borwsers I set off to find one that would work. and found several that will work with either IE or FF but none of the other browsers. I know a few people are using other browsers still like opera..

I found this rather lengthly bit of code that claims it works with all current browsers ( should with the amount of code here)

I am just not sure how to make it behave in a block...

Any ideas on this?

/*
*  Copyright 2006 Dynamic Site Solutions.
*  Free use of this script is permitted for non-commercial applications,
*  subject to the requirement that this comment block be kept and not be
*  altered.  The data and executable parts of the script may be changed
*  as needed.  Dynamic Site Solutions makes no warranty regarding fitness
*  of use or correct function of the script.  Terms for use of this script
*  in commercial applications may be negotiated; for this, or for other
*  questions, contact "license-info@dynamicsitesolutions.com".
*
*  Script by: Dynamic Site Solutions -- http://www.dynamicsitesolutions.com/
*  Last Updated: 2006-09-29
*/

//IE5+/Win, Firefox, Netscape 6+, Opera 7+, Safari, Konqueror 3, IE5/Mac, iCab 3

var addBookmarkObj = {
  init:function() {
    if(!document.getElementById || !document.createTextNode) return;
    var cont=document.getElementById('addBookmarkContainer');
    if(!cont) return;
    var a=document.createElement('a');
    a.href=location.href;
    if(window.opera) {
      a.rel='sidebar'; // this makes it work in Opera 7+
    } else {
      // this doesn't work in Opera 7+ if the link has an onclick handler,
      // so we only add it if the browser isn't Opera.
      a.onclick=function() {
        addBookmarkObj.exec(this.href,this.title);
        return false;
      }
    }
    a.title=document.title;
    a=cont.appendChild(a);
    a.appendChild(document.createTextNode('Bookmark This Page'));
  },
  exec:function(url, title) {
    var isKonq=(isLikelyKonqueror3 && isLikelyKonqueror3());
    var isMac=(navigator.userAgent.toLowerCase().indexOf('mac')!=-1);
    var buttonStr = isMac?'Command/Cmd':'CTRL';

    if(window.external && (!document.createTextNode ||
      (typeof(window.external.AddFavorite)=='unknown'))) {
        // IE4/Win generates an error when you
        // execute "typeof(window.external.AddFavorite)"
        // In IE7 the page must be from web server, not directly from a local
        // file system, otherwise, you get a permission denied error.
        window.external.AddFavorite(url, title); // IE/Win
    } else if(isKonq) {
      alert('You need to press CTRL + B to bookmark our site.');
    } else if((window.opera &&
        opera.buildNumber && !isNaN(opera.buildNumber()))) {
          void(0); // do nothing here (Opera 7+)
    } else if(window.opera) { // older Opera
      alert('You need to press '+buttonStr+' + T to bookmark our site.');
    } else if(window.home) { // Netscape, iCab
      alert('You need to press '+buttonStr+' + D to bookmark our site.');
    } else if(!window.print || isMac) { // IE5/Mac and Safari 1.0
      alert('You need to press Command/Cmd + D to bookmark our site.');   
    } else {
      alert('In order to bookmark this site you need to do so manually '+
        'through your browser.');
    }
  }
}

function isLikelyKonqueror3() {
  if(!document.getElementById) return false;
  if(document.defaultCharset || window.opera || !window.print) return false;
  if(window.home) return false; // Konqueror doesn't support this but Firefox,
    // which has silent support for document.all when in Quirks Mode does
  if(document.all) return true; // Konqueror versions before 3.4
  var likely = 1;
  // testing for silent document.all support; try-catch used to keep it from
  // generating errors in other browsers.
  // try-catch causes errors in IE4 and NS4.x so we use the eval() to hide it.
  // try {
  //   var str=document.all[0].tagName;
  // } catch(err) { likely=0; }
  eval("try{var str=document.all[0].tagName;}catch(err){likely=0;}");
  return likely;
}

function dss_addEvent(el,etype,fn) {
  if(el.addEventListener && (!window.opera || opera.version) &&
  (etype!='load')) {
    el.addEventListener(etype,fn,false);
  } else if(el.attachEvent) {
    el.attachEvent('on'+etype,fn);
  } else {
    if(typeof(fn) != "function") return;
    if(typeof(window.earlyNS4)=='undefined') {
      // to prevent this function from crashing Netscape versions before 4.02
      window.earlyNS4=((navigator.appName.toLowerCase()=='netscape')&&
      (parseFloat(navigator.appVersion)<4.02)&&document.layers);
    }
    if((typeof(el['on'+etype])=="function")&&!window.earlyNS4) {
      var tempFunc = el['on'+etype];
      el['on'+etype]=function(e){
        var a=tempFunc(e),b=fn(e);
        a=(typeof(a)=='undefined')?true:a;
        b=(typeof(b)=='undefined')?true:b;
        return (a&&b);
      }
    } else {
      el['on'+etype]=fn;
    }
  }
}

dss_addEvent(window,'load',addBookmarkObj.init);
Title: Re: [BLOCK] All in 1 User Preference
Post by: brianjw on January 17, 2007, 03:15:29 AM
Ok... sorry about that :(

some of you know how my coding skills are ;)

I will post an update to this tomorrow cuz im tired now, I will edit it to make it work. Sorry about that. I am not farmiliar with the code you are posting here so I cannot help you with that. And like you said it is lengthy. Why do it lengthy when it can be done with a few lines :D

So tomorrow I will make a re-post to this and post an updated version. If someone can reply to this after I log off (in a few min.) so when I log on this pops up and I remember to post a new code. lol :2funny:

Brianjw
Title: Re: [BLOCK] All in 1 User Preference
Post by: carver on January 17, 2007, 11:31:34 AM
No need to apologize Brian, if it were not for guys like you guys like me would be up a creek.
I looked around a lot for a better ( smaller more efficient code) that would work with a broader range of browsers and just did not see one.
Thanks for your help.
:up:
Title: Re: [BLOCK] All in 1 User Preference
Post by: brianjw on January 18, 2007, 03:05:00 AM
I am sorry. I can't create the code tonight for the links seeing that I just got home and now I am so tired and it is late ;)
so... it will be the day that i am home on time to be able to do this the updated code will be here :D
Title: Re: [BLOCK] All in 1 User Preference
Post by: G6Cad on January 18, 2007, 08:24:03 AM
Tell the truth, you need help to get the code to work as you dont know coding your self Brian ;)

Aku will be back from artica in 3 month and 24 days  :coolsmiley:
Title: Re: [BLOCK] All in 1 User Preference
Post by: carver on January 18, 2007, 11:32:59 AM
OUCH... Man did she take a shot at you...  ;D

Hope yall are friends... though it sounds more like 2 siblings.. ::)
Title: Re: [BLOCK] All in 1 User Preference
Post by: G6Cad on January 18, 2007, 11:49:35 AM
I think Brian knows im just joking with him....or are I  :coolsmiley:    :D
Title: Re: [BLOCK] All in 1 User Preference
Post by: bigb on January 18, 2007, 04:45:37 PM
A lot of times it's not what you know,  it's who you know to get the job done right.
Title: Re: [BLOCK] All in 1 User Preference
Post by: brianjw on January 19, 2007, 02:26:28 AM
Yes, everyone knows my CODING SKILLS suck! But thats alright because im learning. lol. So I figured I would work with some people who arent learning and know nothing and see if I can do something. But Obviously my coding skills striked me again and people are claiming it doesnt work, lol :2funny:
Title: Re: [BLOCK] All in 1 User Preference
Post by: brianjw on January 19, 2007, 03:10:31 AM
Updated Code

1. (ADD TO FAVORITES ONLY)

<script type="text/javascript"><!--
// Favorites only!
// Use in left or right block
// Change the urls and titles as you wish.
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
var url="http://YOURURL.com";
var title="YOURSITE";
document.write('<A HREF="javascript:window.external.AddFavorite(url,title)');
document.write('"><font face= color=#3300FF size=none>Add this site to your favorites!</font></a>');
}
else {
var alt = "<font color=#3300FF face= size=none>Add this site to your favorites!</font><BR>";
if(navigator.appName == "Netscape") alt += "Press (Ctrl-D) on your keyboard.</font>";
document.write(alt);
}
// End of favorites code --></SCRIPT>


2. (SET HOMEPAGE ONLY)

<!-- Homepage Code ONLY-->
<!--[if IE]><a HREF onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://YOURURL.com');" style="cursor:hand">
<font color="#3300FF" face="" size="none">Make YOURSITE Your Homepage!</font></a><![endif]-->
<!-- end of homepage code -->


3. (ALL)

<script type="text/javascript"><!--
// Favorites only!
// Use in left or right block
// Change the urls and titles as you wish.
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
var url="http://YOURURL.com";
var title="YOURSITE";
document.write('<A HREF="javascript:window.external.AddFavorite(url,title)');
document.write('"><font face= color=#3300FF size=none>Add this site to your favorites!</font></a>');
}
else {
var alt = "<font color=#3300FF face= size=none>Add this site to your favorites!</font><BR>";
if(navigator.appName == "Netscape") alt += "Press (Ctrl-D) on your keyboard.</font>";
document.write(alt);
}
// End of favorites code --></SCRIPT>
<!-- Homepage Code ONLY-->
<!--[if IE]><a HREF onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://YOURURL.com');" style="cursor:hand">
<font color="#3300FF" face="" size="none">Make YOURSITE Your Homepage!</font></a><![endif]-->
<!-- end of homepage code -->


MODIFY: Remember to change #3300FF to the color you wish the links to be (this applies for both of the links). Modify the http://YOURURL.com to your website and add your site title in where it says YOURSITE.

These codes work 100% well. Just be sure to modify the above and it will absolutely work :D

Brianjw