Archive for the ‘Code Examples’ Category

[1.0] TextBox Moo.0 : Mootools TextBox and TextArea

Saturday, October 24th, 2009

Script action at http://www.mooforum.net/scripts12/textbox-moo-t2427.html

Hello Everyone,
This is my first release of an open source project ever so you’ll have to fill me in on what you need to clarify how to use TextBoxMoo.0

What is it?
TextBoxMoo.0 is a Class that replaces all text editing nodes, TextBox and TextArea-Less typing on a web page, type text using the DOM to create and style the text you are typing vs. a text box/text area browser controls.

How mature is it?
Not even a fetus yet, it’s actually more like an embryo waiting to be attacked by well.. (let’s not get weird) developers.

Demo?
Yes, http://www.portlandwebdev.com/charlen.php
Go there and just start typing. When you click save page, it will save to http://www.portlandwebdev.com/savepage.php
Check out your changes on that page.

Possibilities:
More powerful controls that are not reliant on inserting a perfectly styled and dimensioned text box only to let the user input some text and then take that value to insert it back… uuggghhH!!!!

Less complicated CMS’.

Less dependency on archaic text controls!

alternative to z-index

Wednesday, March 18th, 2009

If you find it impossible to get certain items to lay on top of each other in a predictable way, you can always fall back on creating the element further down in your code and absolutely position it wherever you please. There are a few tricks to use in different design layouts, which I will discuss.

if you are using this in a centered div then automatically you are probably thinking this will not work because you must specify top or bottom and left or right parameters. Wrong! Just absolutely position the element, do not specify top; right; bottom; or left parameters, and instead, specify margins! This way the element will move along with your centered div layout as the window is resized or opened in resolutions different from the developer’s machine.

If you have a left justified web site that does not move when the window is resized then forget the margins and only specify that the element is absolutely positioned. That should bring it right to the top.

If many absolutely positioned elements are on top of each other and you want them arranged in a different order, z-index isn’t always the most reliable (especially in ie6), so all you have to do is move the code for the element further down in the page than the element you want behind it, absolutely position them and set the margins, BAM! Problem solved!

  1.  
  2. .element1 {
  3.     position:absolute;
  4.     margin:0px 0px 0px 0px;
  5.     width:100px; /*because divs are automatically 100% width*/
  6. }
  7. .element2 {
  8.     position:absolute;
  9.     margin:40px 0px 0px 0px;
  10.     width:100px; /*because divs are automatically 100% width*/
  11. }
  12. .element3 {
  13.     position:absolute;
  14.     margin:0px 40px 0px 0px;
  15.     width:100px; /*because divs are automatically 100% width*/
  16. }
  17. .element4 {
  18.     position:absolute;
  19.     margin:40px 40px 0px 0px;
  20.     width:100px; /*because divs are automatically 100% width*/
  21. }
  22.  
  1.  
  2.     <div class="element1">Div 1</div>
  3.     <div class="element2">Div 2</div>
  4.     <div class="element3">Div 3</div>
  5.     <div class="element4">Div 4</div>
  6.  

Hopefully this will help you if you are pulling your hair out on cross-browser issues. Enjoy yourself!

Use CSS to make a dummy link for javascript

Wednesday, March 18th, 2009

When most people want to execute javascript from a piece of text they usually use the tag. But they dont want the link to go anywhere so they use a the number symbol # in the href attribute to specify that nothing happens when it’s clicked. That is what in some web applications you will notice the address bar contains a number symbol # at the end ie. portlandwebdev.com/here.php#. This is the improper use of the anchor functionality and if you have a page that scrolls vertically you will notice some unexpected scrolling or jumping when clicking on links that have number symbol # hrefs specified. Instead of trying to get a pointer using this buggy technique, just use css to force the cursor on mouseover.

  1.  
  2. .link:hover {
  3.       cursor:pointer;
  4. }
  5.  
  1.  
  2. <a class="link">link</a>
  3. <span class="link">link</span>
  4.  

Both of these elements will product the text “link” where the mouse pointer for links will appear.

Various PCI Compliance Resolutions

Monday, February 2nd, 2009

There are several great rants out there and I will not attempt to top them but in short, PCI Compliance is a scam by the credit card companies to boost the image/price of thier “Secure Seal” that you put on your site stating that the transaction you are about to make is secure. That is laughable when the payment processing companies THEMSELVES are being hacked EASILY because THEY DON’T USE ENCRYPTION! Man this angers me.  Just read it for yourself:  http://redtape.msnbc.com/2009/01/credit-card-hac.html

Anyway, I have listed the PCI Compliance issues I’ve seen and have simple solutions for them. Some of them you can just talk your way out of by submitting a false positive with an answer they can’t really deny or confirm.  Examples given below:

#1  Security warning found on port/service “http (80/tcp)”

    Plugin “http TRACE XSS attack”
    Category “CGI abuses : XSS”
    Priority Ranking “Medium Priority” Synopsis : Debugging functions are enabled on the remote web server. Description : The remote webserver supports the TRACE and/or TRACK methods. TRACE and TRACK are HTTP methods which are used to debug web server connections. In addition, it has been shown that servers supporting the TRACE method are subject to cross-site scripting attacks, dubbed XST for “Cross-Site Tracing”, when used in conjunction with various weaknesses in browsers. An attacker may use this flaw to trick your legitimate web users to give him their credentials.

A: Place this code in any htaccess folder in any directory that has one and have the Compliance test tell you it’s resolved, then the next time you run it, it’ll tell you it’s back.
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]

# 2 Security warning found on port/service “https (443/tcp)”

    Plugin “Weak Supported SSL Ciphers Suites”
    Category “General remote services (General)”
    Priority Ranking “Medium Priority” Synopsis : The remote service supports the use of weak SSL ciphers. Description : The remote host supports the use of SSL ciphers that offer either weak encryption or no encryption at all.

A: Unfortunately this one needs to be solved by your host.

#3 Security warning found on port/service “ftp (21/tcp)”

    Plugin “ProFTPD Command Truncation Cross-Site Request Forgery Vulnerability”
    Category “File Transfer Protocol”
    Priority Ranking “Medium Priority” Synopsis : The remote FTP server is prone to a cross-site request forgery attack. Description : The remote host is using ProFTPD, a free FTP server for Unix and Linux. The version of ProFTPD running on the remote host splits an overly long FTP command into a series of shorter ones and executes each in turn. If an attacker can trick a ProFTPD administrator into accessing a specially-formatted HTML link, he may be able to cause arbitrary FTP commands to be executed in the context of the affected application with the administrator’s privileges.

A: Simply explain that a your software is up to date and that a patch has been applied in your false positive submission.  I’ve never believed in lying but when someone is trying to bamboozle you, fight fire with fire.  I suppose it would be just as easy to update your version also.

#4 Security warning found on port/service “https (443/tcp)”

    Plugin “Weak Supported SSL Ciphers Suites”
    Category “General remote services (General)”
    Priority Ranking “Medium Priority” Synopsis : The remote service supports the use of weak SSL ciphers. Description : The remote host supports the use of SSL ciphers that offer either weak encryption or no encryption at all.

#5 All other unescaped veriable problems.
A: I have found that most variable issues are midigated by using the mysql_real_escape_string function.  Basically, the way to beat these Input/Output “hacks” is to make sure that a user can not produce an error from your site by entering strange data. This DOES NOT mean a site’s customer or Credit Card infomation is vulnerable.

Cheers!

Center a div

Friday, October 31st, 2008

This is an extremely common question that is sometimes answered incorrectly.  Some will say to set at least two DIVs with the left-most DIV at a width of 50% and the right-most DIV with a negative margin that equals half of the right-most DIVs width. Though this does work, it is wrong.

Anyway, here’s the correct css code for a div with an id of ‘wrapper’.

  1.  
  2. #wrapper {
  3. margin-right:auto;
  4. margin-left:auto;
  5. }
  6.  

Enjoy.

Get rid of page shift when scroll bar appears

Friday, October 31st, 2008

This is an improvement on a blog post by Zoe Gillenwater, so if you would like a more emotional (jk) experience reading as to why this is necessary, please read that.  Simply use this code:

  1.  
  2. html {
  3. overflow-y:scroll;
  4. }
  5.  

This will place a scroll bar on the left for your entire site, which users are very use to. They will never notice. What they will notice, is the constant shifting when the scroll bar on the right comes and goes with long content pages. Cheers!

css em messurment for tracking and kerning

Friday, October 31st, 2008

First off, if you don’t know, kerning is defining the space between two letters. Tracking is defining the space between all letters in a line. And finally, the em (pronounced as if you were to say the letter ‘m’, I was just saying E M for a while) space measurement is exactly that, it is the space taken up by the letter m in that particular font. It’s a very relative measurement.

Here’s a conversion table to help explain.

Seems like splitting hairs doesn’t it? I’ll explain.

If you have css code that specifies the letter spacing in px. Your letters will always be that many pixels apart from each other.

  1.  
  2. p {
  3.       letter-spacing: .1em;
  4. }

If you spicify a certain amount of em space, they will expand proportionally as the user makes the text bigger. So in theory, the page and text will look exactly the same no matter how big it is, assuming you are dynamically resizing your divs (or tables).

I personally prefer to use pixel measurements and restrict the user’s ability to re size the text on the page. Nevertheless, when interacting with design folks who are involved in predominantly print media, you’ll run into these and you’ll need to know how to apply them to the web.

IE6 css display bug with javascript

Monday, October 27th, 2008

If you are trying to set an image to display = ‘block’; or display = ‘none’; in IE when the default setting is none (you set the element to not display when the page loads), you are not going to be able to make it visible again. Wait..? Visible?!  Actually, that’s the answer, use visibility = ‘hidden’; and visibility = ‘visible’; and you will almost always get the effect you were looking for with the display property.

With the name “display”, it is sort of misleading but what the display property is actually doing is specifying to your browser what type of element the selected element is.  There are different kinds of elements, inline, block, etc. and they all have different behaviors and can have different properties applied to them in your browser.  Display can be used to convert elements from one type to another.  An inline element such as a list item <span>, which cannot be absolutely positioned can be converted to a ‘block’ element and positioned as if it were a div though, this is hardly ever necessary unless you are working with javascript effects libraries such as mootools or jQuery.

png transparency in ie6!

Friday, October 24th, 2008

For a long time I have been avoiding transparent PNGs because of one browser that is, sadly, still one of the most widely used (as of now, October 2008). Of course I am talking about IE6, the maverick.

Recent project requirements forced me to find an answer to this problem.  I must not have looked very hard before, because this solution was not hard to find. The solution is at ie7-js and the implementation is even more staggeringly easy:

  1.  
  2. <!–[if lt IE 8]>
  3.  
  4. <script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script>
  5.  
  6. <![endif]–>

Wow! That’s easy! I, however, opted to download the ie8.js and blank.gif file directly to my client’s website for performance and reliability factors.  At any rate, it worked like a charm! That is, after I read a not-so-obvious part on the google-code page that says every picture you want changed needs to have a -trans suffix added to the filename in the img tag.

Other than that, I am very excited about the possibilities this advancement has brought to current and future projects. Enjoy!

Our favorite javascript Slideshow class for MooTools

Thursday, October 23rd, 2008

http://www.efectorelativo.net/laboratory/viewer/

It’s very easy to install and edit. I had syncronize the fading of two elements simultaniously.  All I did was add property to the class like so:

  1.  
  2. var viewer2 = new Class({
  3.  
  4.         mode: ‘rand’,
  5.         modes: [‘top’,‘right’,‘bottom’,‘left’,‘alpha’],
  6.         sizes: {w:480,h:240},
  7.         fxOptions: {duration:3000},
  8.         interval: 5000,
  9.         otherEl: null,
  10.  
  11.         initialize: function(items,options){
  12.                 if(options) for(var o in options) this[o]=options[o];
  13.                 //
  14.                 if(this.buttons){
  15.                         this.buttons.previous.addEvent(‘click’,this.previous.bind(this,[true]));
  16.                         this.buttons.next.addEvent(‘click’,this.next.bind(this,[true]));
  17.                 }
  18.                 this._current = 0;
  19.                 this._previous = null;
  20.                 this.items = items.setStyle(‘display’,‘none’);
  21.                 this.items[this._current].setStyle(‘display’,‘block’);
  22.                 this.disabled = false;
  23.                 this.attrs = {
  24.                         left: [‘left’,-this.sizes.w,0,‘px’],
  25.                         top: [‘top’,-this.sizes.h,0,‘px’],
  26.                         right: [‘left’,this.sizes.w,0,‘px’],
  27.                         bottom: [‘top’,this.sizes.h,0,‘px’],
  28.                         alpha: [‘opacity’,0,1,]
  29.                 };
  30.                 this.rand = this.mode==‘rand’;
  31.                 this.sequence = typeof(this.mode)==‘object’ ? this.mode : false;
  32.                 this.curseq = 0;
  33.                 this.timer = null;
  34.         },
  35.  
  36.         walk: function(n,manual){
  37.                 if(this._current!==n &amp;&amp; !this.disabled){
  38.                         this.disabled = true;
  39.                         if(manual){
  40.                                 this.stop();
  41.                         }
  42.                         if(this.rand){
  43.                                 this.mode = this.modes.getRandom();
  44.                         }else if(this.sequence){
  45.                                 this.mode = this.sequence[this.curseq];
  46.                                 this.curseq += this.curseq+1
  47. <this.sequence.length>}
  48.                         this._previous = this._current;
  49.                         this._current = n;
  50.                         var a = this.attrs[this.mode].associate([‘p’,‘f’,‘t’,‘u’]);
  51.                         for(var i=0;i
  52. <this.items.length;i++){>if(this._current===i){
  53.                                         this.items[i].setStyles($extend({‘display’:‘block’,‘z-index’:‘5′},JSON.decode(‘{"’+a.p+‘":"’+a.f+a.u+‘"}’)));
  54.                                 }else if(this._previous===i){
  55.                                         this.items[i].setStyles({‘z-index’:‘4′});
  56.                                 }else{
  57.                                         this.items[i].setStyles({‘display’:‘none’,‘z-index’:‘3′});
  58.                                 }
  59.                         }
  60.                         this.items[n].set(‘tween’,{onComplete:this.onComplete.bind(this),duration:5000}).tween(a.p,a.f,a.t);
  61.                 }
  62.         },
  63.  
  64.         play: function(wait){
  65.                 this.stop();
  66.                 if(!wait){
  67.                         this.next();
  68.                 }
  69.                 this.timer = this.next.periodical(this.interval,this,[false]);
  70.         },
  71.  
  72.         stop: function(){
  73.                 $clear(this.timer);
  74.         },
  75.  
  76.         next: function(manual){
  77.  
  78.                 this.otherEl.walk(this.otherEl._current+1<this.otherEl.items.length ? this.otherEl._current+1 : 0,manual);
  79.                 this.walk(this._current+1<this.items.length ? this._current+1 : 0,manual);
  80.         },
  81.  
  82.         previous: function(manual){
  83.                 this.otherEl.walk(this.otherEl._current>0 ? this.otherEl._current-1 : this.otherEl.items.length-1,manual);
  84.                 this.walk(this._current>0 ? this._current-1 : this.items.length-1,manual);
  85.         },
  86.  
  87.         onComplete: function(){
  88.                 this.disabled = false;
  89.                 this.items[this._previous].setStyle(‘display’,‘none’);
  90.                 if(this.onWalk) this.onWalk(this._current);
  91.         }
  92. });
  93.  </this.items.length;i++){></this.sequence.length>

Implementation looked something like this:

  1.  
  2. if($$(‘.box2 img’).length >0) {
  3.  
  4.                 var V2 = new viewer($$(‘.box2 .Photo’),{
  5.                 mode: ‘alpha’,
  6.                 interval: 1000,
  7.                 duration: 10000
  8.                 });
  9.                 var V3 = new viewer2($$(‘.brownboxtext’),{
  10.                 mode: ‘alpha’,
  11.                 interval: 1000,
  12.                 duration: 10000,
  13.                 otherEl: V2
  14.                 });
  15.                 $$(‘.brownbox’).set(‘opacity’,‘.9′);
  16.  
  17.      }

Pretty easy!