Tag Archive for basic

jsCookies – my simple easy pure js javascript cookies function

//  create my jsCookies function
var jsCookies = {

	// this gets a cookie and returns the cookies value, if no cookies it returns blank ""
	get: function(c_name) {
		if (document.cookie.length > 0) {
			var c_start = document.cookie.indexOf(c_name + "=");
			if (c_start != -1) {
				c_start = c_start + c_name.length + 1;
				var c_end = document.cookie.indexOf(";", c_start);
				if (c_end == -1) {
					c_end = document.cookie.length;
				}
				return unescape(document.cookie.substring(c_start, c_end));
			}
		}
		return "";
	},

	// this sets a cookie with your given ("cookie name", "cookie value", "good for x days")
	set: function(c_name, value, expiredays) {
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + expiredays);
		document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + exdate.toUTCString());
	},

	// this checks to see if a cookie exists, then returns true or false
	check: function(c_name) {
		c_name = jsCookies.get(c_name);
		if (c_name != null && c_name != "") {
			return true;
		} else {
			return false;
		}
	}

};
// end my jsCookies function

// USAGE - get    ::   jsCookies.get("cookie_name_here");  [returns the value of the cookie]
// USAGE - set    ::   jsCookies.set("cookie_name", "cookie_value", 5 );  [give name, val and # of days til expiration]
// USAGE - check  ::   jsCookies.check("cookie_name_here");  [returns only true or false if the cookie exists or not]

source

Basic JavaScript Image Fading

function fade(step) {
    var imgs = document.getElementsByTagName("img");
    step = step || 0;
    imgs[1].style.opacity = step/100;
    imgs[1].style.filter = "alpha(opacity=" + step + ")";
    step += 2;
    if (step <= 100) {
        setTimeout(function() {
            fade(step);
        }, 1);
    }
}

source

Basic JavaScript Progressbar Animation

<div id="progress" style="background: green; width: 0;">&nbsp;</div>
<p><a href="#" onclick="progress(); return false;">start</a></p>

function progress() {
    var loadingbar = document.getElementById("progress");
    var width = parseInt(loadingbar.style.width);
    width++;
    loadingbar.style.width = width + "px";
    if (width < 300) {
        setTimeout(progress, 10);
    }
}

source

Remove Dotted Outline

a, a:active { outline: none; }

source

Cross Browser Transparency

.transparent {
    
    /* Modern Browsers */ opacity: 0.7;
  
    /* IE 8 */ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";

    /* IE 5-7 */ filter: alpha(opacity=70);

    /* Netscape */ -moz-opacity: 0.7;

    /* Safari 1 */ -khtml-opacity: 0.7;
    
  }

source

Law of Tobac

Public Function createDCNRevision(ByVal strID As String) As Boolean
        Dim dt As New DataTable
	
	-- this is an arraylist that will hold each of your parameters
        Dim arlParameters As New ArrayList                     
        -- this is how you add parameters to the arlParameters variable.
	-- In this case the database function we are trying to call accepts two
	-- parameters.  One is called vDCNId and the other is vUserId.
	-- The next two lines show how to add these parameters.
	-- This line adds the parameter vDCNId and gives it the value
	-- that is stored in the strID variable
	arlParameters.Add(New clsODP.SP_Parameter("vDCNId", strID)) 
	-- This line adds the parameter vUserId and gives it the value
	-- that is stored in the _userId variable
        arlParameters.Add(New clsODP.SP_Parameter("vUserId", _userId))
	-- This line calls a function named ODP.storedProcedure_getData
	-- This function accepts two parameters.  The first is the name of the package and procedure in string format.
	-- The second parameter is the arlParameters variable.  Remember, this variable is an Arraylist that holds all of the
	-- parameters that need to be passed into this function.  The ODP.storedProcedure_getData calls the database function 
	-- and the database function queries the database and returns the results.  The ODP.storedProcedure_getData function
	-- then returns these results and puts them into the variable of type datatable named dt.
	-- You can access the data using the dt variable.  To get the first item in the first row of results
	-- you would do the following. dt.rows(0).item(0).
        dt = ODP.storedProcedure_getData("PKG_DCN.P_BL_createDCNRevision", arlParameters)
        If dt.Rows(0).Item(0) = -1 Then
            Return "False"
        Else
            _DCN_ID = dt.Rows(0).Item("DCN_ID")
            Return "True"
        End If
    End Function

source

Declare Variables for Table In Visual Basic

Private Function getInformation() As DataTable
        Try
            Dim dt As DataTable
            Dim arlParameters As New ArrayList

            arlParameters.Add(New clsODP.SP_Parameter("vManufacturer", manufacturer))
            dt = ODP.storedProcedure_getData("PK_MANUMODEL.getInformation", arlParameters)

            Return dt

        Catch ex As Exception
            Throw
        End Try
    End Function

source

Create Table In Visual Basic

Private Function createContactTable() As String
        Try
            Dim dt As DataTable = getInformation()
            Dim i As Integer = 0
            Dim html As New System.Text.StringBuilder
            If dt.Rows.Count = 0 Then
                html.Append("<h4> No contact information avaialble at this time.</h4>")
            Else
                For i = 0 To dt.Rows.Count - 1
                    With html
                        .Append("<table class = ""contactTable"">")
                        .Append("   <tr>")
                        .Append("       <td><b>Company:</b></td>")
                        .Append("       <td>")
                        .Append(dt.Rows(i).Item("COMPANY"))
                        .Append("       </td>")
                        .Append("   </tr>")
                        .Append("   <tr>")
                        .Append("       <td><b>Name:</b></td>")
                        .Append("       <td>")
                        .Append(dt.Rows(i).Item("NAME"))
                        .Append("       </td>")
                        .Append("   </tr>")
                        .Append("   <tr>")
                        .Append("       <td><b>Position:</b></td>")
                        .Append("       <td>")
                        .Append(dt.Rows(i).Item("POSITION"))
                        .Append("       </td>")
                        .Append("   </tr>")
                        .Append("   <tr>")
                        .Append("       <td><b>Phone Number:</b></td>")
                        .Append("       <td>")
                        .Append(dt.Rows(i).Item("PHONE"))
                        .Append("       </td>")
                        .Append("   </tr>")
                        .Append("   <tr>")
                        .Append("       <td><b>E-mail:</b></td>")
                        .Append("       <td>")
                        .Append(dt.Rows(i).Item("EMAIL"))
                        .Append("       </td>")
                        .Append("   </tr>")
                        .Append("</table>")
                        .Append("<HR>")
                    End With
                Next
            End If

            Return html.ToString

        Catch ex As Exception
            Throw
        End Try
    End Function

source

Basic Switch

switch (example_string)
			{
				case "a":
					trace ("a was selected");
					break;
				
				case "b":
					trace ("b was selected");
					break;
				
				default:
					trace ("Neither a or b was selected")
			}

source

Basic Document Class Template, as Created by FlashDevelop

package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	/**
	 * ...
	 * @author <YourNameHere>
	 */
	public class Main extends Sprite 
	{
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
		}
		
	}
	
}

source