DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets

  • submit to reddit

Recent Snippets

                    
import mx.events.EventDispatcher;
import mx.utils.Delegate;

class Emailer {
	
	// required for EventDispatcher:
	public var addEventListener:Function;
	public var removeEventListener:Function;
	private var dispatchEvent:Function;
	
	// use to communicate with php script
	private var _lv:LoadVars;
	// holds address of sender
	private var _sentFrom:String;
	
	// constructor
	public function Emailer() {    
		EventDispatcher.initialize(this);
		_lv = new LoadVars();
	}

	// 
	private function dataReceived(dataxfer_ok:Boolean):Void {
		// if some problem with loadVars transfer, pass back error=2
		if (!dataxfer_ok) dispatchEvent({target:this, type:'mailSent', errorFlag:2});
		// otherwise pass back error code returned from script
		else dispatchEvent({target:this, type:'mailSent', errorFlag:Number(_lv["faultCode"])});
	}
	
	 // Use loadvars object to send data (set to call dataReceived when script returns data)
	public function sendEmail(sub:String, fn:String, fe:String, msg:String, rep:String):Void {
		// if user already sent from this address, show error msg
		if (_sentFrom == fe) dataReceived(false);
		// otherwise set up and send
		else {
			_sentFrom = fe;
			// specify function to handle results, make scope = Emailer
			_lv.onLoad = Delegate.create(this, dataReceived);
			// set up properties of lv to items to be POSTed
			_lv.subject = sub;
			_lv.name = fn;
			_lv.email = fe;
			_lv.message = msg;
			_lv.reply = rep;
			// call script
			_lv.sendAndLoad("sendemail.php", _lv, "POST");
		}
	}
} 
                
                    If installed under Mambo, edit:
mambots/editors/tinymce_exp.php
Lines 157-158:
  relative_urls : true,
  remove_script_host : true,
                
                    When installed in Mambo, edit 
mambos/editors/tinymce_exp/jscripts/tiny_mce/plugins/advlink/link.php
 lines 253-258:
<select name="target" id="target">
          <option value="_self" selected>_self (<?php echo _insert_link_target_same ?>)</option>
          <option value="_blank">_blank (<?php echo _insert_link_target_blank ?>)</option>
          <!--<option value="_parent">_parent (<?php echo _insert_link_target_parent ?>)</option>
          <option value="_top">_top (<?php echo _insert_link_target_top ?>)</option>-->
</select>
                
                    
/********************************************************
   Function: getChildNodeName

     note:
       Cycle through the child nodes and find the first instance of the name.

*********************************************************/
XMLNode.prototype.getChildNodeName = function(nName) {
   for (var i=0; i<this.childNodes.length; i++) {
      var tChild = this.childNodes[i];
      if (tChild.nodeName === nName) {
         return tChild;
      }  
   }
   return null;
};
                
                    Serve XHTML as application/xhtml+xml to browsers which accept it (and to W3C Validator).

<?php 
header("Vary: Accept");
if (stristr($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml') || stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator"))
{
  header('Content-type: application/xhtml+xml');
  echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
}
else
{
  header('Content-type: text/html');
}
?>
                
                    A request for this came up on the CF-Talk list recently. Here's what I came up with.
<!--- The list with want to clean up --->
<cfset lst = "a,list,with,a,few,duplicates">
<!--- Use a struct to build a set of the list elements --->
<cfset set = StructNew()>
<cfloop index="elem" list="#lst#">
    <cfset set[elem] = "">
</cfloop>
<!--- Convert the set back to a list --->
<cfset lst = StructKeyList(set)>
This sort of this should be familiar to all you perlmongers out there.                
                    
<%
    response.setContentType("text/xml");
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("pragma","no-cache");
%>
                
                    
function loadXMLDoc(url) {
		
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
    
        req = new XMLHttpRequest();
        //function_name is the function to process request
        req.onreadystatechange = function_name;
        req.open("GET", url, true);
        req.send(null);
        
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
    
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {

            //function_name is the function to process request        
            req.onreadystatechange = actualizarLista;
            req.open("GET", url, true);
            req.send();
        }
    }
}
                
                    
if (req.readyState == 4) {

	if (req.status == 200) {
		
            // ...processing statements go here...

            response = req.responseXML;
            
            results = response.getElementsByTagName(name);

	}
}
                
                    in Firefox

user_pref("javascript.options.strict", true);
console display 'warning'