Notepad Web Development

Feed icon

Code Snippets

Netvibes UWA Widget Template

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html 	xmlns="http://www.w3.org/1999/xhtml"
		xmlns:widget="http://www.netvibes.com/ns/"  >
  <head>

    <meta name="author"      content="Stephen Griffin" />
    <meta name="website"     content="http://notepadwebdevelopment.com" />
    <meta name="description" content="Template for developing Netvibes UWA widgets" />
    <meta name="apiVersion"  content="1.0" />
    <meta name="autoRefresh" content="20" />
    <meta name="debugMode"   content="true" />

    <link rel="stylesheet" type="text/css" href="http://www.netvibes.com/themes/uwa/style.css" />
    <script type="text/javascript" src="http://www.netvibes.com/js/UWA/load.js.php?env=Standalone"></script>

    <title>UWA Template</title>
    <link rel="icon" type="image/png" href="http://www.notepadwebdevelopment.com/favicon.ico" />

	<widget:preferences>
		<!--preference type="text" name="testPref" label="Test Pref" defaultValue="Test prefernce value here" /-->
	</widget:preferences>

	<style type="text/css">
	  h1 		{ color: #333; }
	</style>

	<script type="text/javascript">
		// Create a pseudo-namespace
		var MyWidget = {};

		// Properties
		MyWidget.foo = 'http://www.google.com/';

		// Methods
		MyWidget.test = function(message) {
		  alert(message);
		}

		// Entry point
		widget.onLoad = function() {

		  widget.setBody('<h1>Loaded!</h1><p><a href="'+MyWidget.foo+'">'+MyWidget.foo+'</a></p>');
		}
	</script>
  </head>

  <body>

	<h1>Loading...</h1>

  </body>
</html>

Adapted from http://dev.netvibes.com/doc/uwa/documentation/uwa_monopage

AS3 Singleton workaround example

package
{
	public class YourSingletonClass
	{
		private static var _instance : YourSingletonClass;

		public function YourSingletonClass(pvt:PrivateClass) { }

		public static function getInstance():YourSingletonClass
		{
			if (YourSingletonClass._instance == null) {
				YourSingletonClass._instance = new YourSingletonClass(new PrivateClass());
			} else {
				trace("No can do - already gots me an instance of this class");
			}
			return YourSingletonClass._instance;
		}
	}
}
// Workaround to enable Singleton pattern, because private
// class declarations are unsupported within AS3
class PrivateClass
{
	public function PrivateClass() { }
}

A basic AS3 custom event template

package  {
	import flash.events.Event;
	import YourClass;

	public class YourClassEvent extends Event
	{
		public static const SOMETHING:String = "something";
		private var _object:YourClass;

		public function YourClassEvent (type:String, object:YourClass)
		{
			super(type);
			_object	= object;
		}

		public function get object():YourClass
		{
           return _object;
		}

		override public function clone():Event
		{
           return new YourClassEvent(type, _object);
		}
	}
}

Dynamic resizing full bleed background image

This was a quick mock-up done in Flash CS3 for a pitch for a new site for Harrogate Ladies college. The background images rotate thorugh a slideshow and will dynamically resize as you change the size of your browser window. In order to see this working you will need to view the swf in it’s own window… here’s the link

The code for the resizing the image on resize is pretty straight forward, just don’t forget to add smoothing to your source images.

resizeHandler(null);

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align 	= StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeHandler);

function resizeHandler(e:Event):void {

	// get largest dimension scaling
	var w	= stage.stageWidth / 1022;
	var h	= stage.stageHeight / 687;

	var newWidth, newHeight;

	if ( w > h ) {
		newWidth	= stage.stageWidth;
		newHeight	= 687 * w;
	} else {
		newHeight	= stage.stageHeight;
		newWidth	= 1022 * h;
	}

	backgrounds.width 	= newWidth;
	backgrounds.height 	= newHeight;
}

Writing jQuery for Wordpress

( function($) {
$(document).ready( function() {
//-------------------------------

  // Your jQuery code here

//--------------------
} ); } ) ( jQuery );

Or alternatively, you can use no conflict mode, and use $j throughout your script instead of $

var $j = jQuery.noConflict();
$j(function(){

});

(more…)