Monday, February 2, 2015

Javascript slide show

<SCRIPT>var myPix = new Array("images/pathfinder.gif", "images/surveyor.gif", "images/surveyor98.gif");
var thisPic = 0;
function processPrevious() {
     if (document.images && thisPic > 0) {
          thisPic--;
          document.myPicture.src = myPix[thisPic];
     }
}
function processNext() {
     if (document.images && thisPic < 2) {
          thisPic++;
          document.myPicture.src = myPix[thisPic];
     }
}
</SCRIPT>
<IMG SRC="images/pathfinder.gif" NAME="myPicture">
<HREF="javascript:processPrevious()">Previous</A>
<
HREF="javascript:processNext()">Next</A>

Javascript function determines whether a Credit Card number is "valid"

// The function determines whether a Credit Card number is "valid"
// Please note that a "valid" Credit Card number is not essentially a Credit Card in "Good Standing"
function isValidCreditCard(number) {
     if (number.indexOf("-")) {
          cc = number.split("-");
          number = "";
          for (var i = 0; i < cc.length; i++) number += cc[i];
     }
     // Another Version of what was performed above using String & Array Methods
     if (number.
indexOf(" ")) {
          cc = number.
split(" ");
          number = cc.
join("");
     }
     // OR using RegExp we can combine the above two
     
//  number = number.replace(/-|\s/g, "");
     /**********************************************/
     if (number.length > 19) return (false);
     sum = 0; mul = 1; l = number.length;
     for (i = 0; i < l; i++) {
          digit = number.substring(l - i - 1, l - i);
          tproduct = parseInt(digit, 10) * mul;
          if (tproduct >= 10) sum += (tproduct % 10) + 1;
          else sum += tproduct;
          if (mul == 1) mul++;
          else mul--;
     }

     if ((sum % 10) == 0) return (true);
     else return (false);
}

Javascript Jump list Choose A Page and Jump:


<FORM>selectedIndex is the "Index number" that the user "chose"
notice that the <SELECT> tag has a bunch of options -- hence an Array of Options
the Options all have a value & that value is a URL
location.href = URL is where we will end up going to
<SELECT onChange="location.href=options[selectedIndex].value">
     <OPTION VALUE="index.htm">Select a Page</OPTION>
     <OPTION VALUE="crossword.htm">Crossword Puzzle</OPTION>
     <OPTION VALUE="email.htm">E-mail Address Check</OPTION>
     <OPTION VALUE="banner1.htm">Random Banner</OPTION>
     <OPTION VALUE="quotes.htm">Random Quotes</OPTION>
     <OPTION VALUE="rollover.htm">Rollover Example</OPTION>
</SELECT>
</FORM>

Javascript Clock Military or Civilian Time?

<SCRIPT>

var now;

function showMilitaryTime() {
     if (document.theForm.showMilitary[0].checked) {
          return true;
     }
     return false;
}

function showTheHours(theHour) {
     if (showMilitaryTime() || (theHour > 0 && theHour < 13)) {
          return (theHour);
     }
     if (theHour == 0) {
          return (12);
     }
     return (theHour - 12);
}

function showZeroFilled(inValue) {
     if (inValue > 9) {
          return ":" + inValue;
     }
     return ":0" + inValue;
}

function showAmPm() {
     if (showMilitaryTime()) {
          return ("");
     }
     if (now.getHours() < 12) {
          return (" am");
     }
     return (" pm");
}

function showTheTime() {
     now = new Date();
     document.theForm.showTime.value =
     showTheHours(now.getHours()) +
     
showZeroFilled(now.getMinutes()) +
     
showZeroFilled(now.getSeconds()) +
     
showAmPm();
     setTimeout("showTheTime()", 1000);
}
</SCRIPT>
<BODY onLoad="showTheTime();">

<FORM NAME="theForm">
     <INPUT TYPE="TEXT" NAME="showTime">
     Display Military Time?
     <INPUT TYPE="RADIO" NAME="showMilitaryCHECKED>Yes
     <INPUT TYPE="RADIO" NAME="showMilitary">No
</FORM>

Javascript Calculating the sum of the digits

<SCRIPT>
function sumDigits(num) {
     var i, sum = 0;                  // can declare two variables at once
     for (i = 1; i <= num; i++) {
             sum += i;              // add each number to sum (ie, 1 + 2 + ...+ num)
     }
     // Display result
     alert("The sum of the digits from 1 to "+ num + " is:\n\n\t " + sum);
}
</SCRIPT>
<BODY>
Looping Functions - Calculate the sum of the digits.
<FORM NAME="SumNums">
     The sum of the digits from 1 to:
     <INPUT TYPE="text" NAME="charNum">
     <INPUT TYPE="button" VALUE="Calculate"
       onClick="sumDigits(SumNums.charNum.value)">
</FORM>

Javascript Bouncing Ball Example

Link - http://www.sislands.com/coin70/week3/bball.htm


This script uses a the setTimeout() Method to perform a sequence of Image Swaps that create the animation.
The setTimeout() Method accepts two arguments, the name of a Function that you want to call and the number of milliseconds you want to wait before calling the Function. The name of the Function needs to be in "quotes", so it looks like this:
setTimeout("someFunction()", 100);
This example waits 100 milliseconds (one tenth of a second) and then calls "someFunction()".
So, this animation is composed of 5 different images of the ball dropping. Each image is about 300 pixels tall, which is the length that the ball drops. In other words, the image never changes position or size, the ball just changes location in each successive image.
As is the standard when doing an image swap, all five of the ball images are Pre-loaded into Image Objects. In this case, each of the image Objects is also loaded into an Array, which makes it easy to refer to them in the script. This process of Pre-loading the image works like this:
var imageArray = new Array();
imageArray[0] = new Image();
imageArray[0].src = "images/ball0.gif";
imageArray[1] = new Image();
imageArray[1].src = "images/ball1.gif";
etc.
To make the ball drop, there is a Function called bounce() which contains a series of setTimeout() Methods that call each of the five images as the ball drops and then calls each of the five images in reverse order as the ball bounces back up. The setTimeout() Methods have longer and longer time intervals specified. The whole series looks like this:
function bounce() {
     setTimeout("document.images['ball'].src = imageArray[0].src", 100);
     setTimeout("document.images['ball'].src = imageArray[1].src", 200);
     setTimeout("document.images['ball'].src = imageArray[2].src", 300);
     setTimeout("document.images['ball'].src = imageArray[3].src", 400);
     setTimeout("document.images['ball'].src = imageArray[4].src", 500);
     setTimeout("document.images['ball'].src = imageArray[5].src", 600);
     setTimeout("document.images['ball'].src = imageArray[4].src", 700);
     setTimeout("document.images['ball'].src = imageArray[3].src", 800);
     setTimeout("document.images['ball'].src = imageArray[2].src", 900);
     setTimeout("document.images['ball'].src = imageArray[1].src", 1000);
     setTimeout("document.images['ball'].src = imageArray[0].src", 1100);
}
This Function takes almost no time to finish, all of the setTimeout() Methods themselves are executed in less than 15 milliseconds. But the commands that they call, which are all image swaps, occur over a 1.1 second time interval because the setTimeout() Methods have specified it that way.
As we'll see in a later class, it's not good to call more than 20 setTimeout Methods at once. It swamps JavaScript and you'll get an error message.

Tuesday, January 27, 2015

Sharepoint 2013 deploy app through wsp and activate feature


1) site settings - solutions - upload wsp by clicking upload solution - Activate App

2) site settings - site actions - manage site features - Activate app