Krisco Designs produces Cambrian Mobile for Cambrian Credit Union

January 9, 2012 Leave a comment

Together with Cambrian Credit Union, Krisco Designs has created an iPhone app to better serve Cambrian’s clients by allowing users to have important info about their bank at their fingertips.

With the new app, Cambrian clients can locate branches, receive directions to branches, and call to speak with a representative at each branch.  The clean, easy-to-use interface also provides info on wheelchair accessibility, location info for ATM’s, as well as business hours for each branch.   

The app also comes equipped with a mortgage calculator, to provide users with estimates regarding mortgages with their bank, and a currency calculator.  Both features were designed to include the bank’s interest rates.  Furthermore, the app includes a QR scanner that allows users to look up further details on additional services.  Cambrian’s decision to place a QR code on marketing & promotional materials encourages clients to download the app.  

All banking info is kept current by Cambrian House via their in-house designed back-end system.  Krisco Designs integrated this previously established back-end with the user-friendly mobile app and provided Cambrian with a choice of several professionally designed iPhone app icons.  

After the release of this app, Krisco Designs continues to uphold its 100% Apple Approval Rate.  Krisco Designs is proud to have been a part of the creation of a useful app like this one.  It was a pleasure to work with Cambrian.

Categories: Uncategorized

Using MailChimp and background images in your table cells

May 19, 2011 5 comments

So we designed a fantastic looking Email newsletter template which had very nice background images, and show up very nice on the web, and not at all in outlook 2007+ woops. We are all pretty familiar with the Microsoft blunder that replaced the rendering engine in Outlook from IE to … Word?! Thanks Microsoft, that was awesome. Of course we all use Word to view HTML…

Anyhoo MailChimp and many others simply outright deny that this is possible or simply state that “We don’t support or recommend this because it doesnt really work in Outlook”

Guess what?  Some smarty pants figured out a really elegant way to make background images show up in Outlook. While this is technically a hack its the best I have seen and it will probably not get any better then this until Microsoft figures out that HTML should be rendered by HTML software not Word Processors.

Credit goes to this forum post I stumbled upon from Brian Thies.

Ok so while that example works great getting this working with MailChimp takes a few more steps.

Step 1. Export your beautifully created template that doesnt work in outlook from MailChimp to your Desktop

Step 2. Modify this template using your favorite HTML Code editor (notepad)

Step 3. Change the head tag and doctype

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:v="urn:schemas-microsoft-com:vml">

Step 4. Comment out the following tag. Settign a background color or image on the table or cell breaks the vml background and your image will not show unless this is commented out.

@tab Body
@section body style
@tip Set the background color for your email’s body area.
*//*
#templateContainer,.bodyContent{
/*@editable*//*background-color:#FFFFFF;
}
/*

Step 5. Insert your background code using this amazing cool method, this an example cell

<td colspan="3" style="background-image:url(http://gallery.mailchimp.com
/1xxxx3wfwf3c/images/1.jpg);width:643px;height:172px;" valign
="top">
<!--[if gte mso 9]>
    <v:image xmlns:v="urn:schemas-microsoft-com:vml" style='behavior: 
url(#default#VML); display:inline-block;width:643px;height:172px;
position:absolute;top:0;left:0;border:0;z-index:-1;' src="
http://gallery.mailchimp.com/1xxxx3wfwf3c/images/1.jpg" />
<![endif]-->
</td>

Step 6. Import your template back into MailChimp from Dashboard > My Templates

Step 7. Go back to your campaign and change your template to your newly fixed imported Template of Master D00m awesome.

Categories: Programming

NETDataset project now on github!

November 17, 2010 Leave a comment

To make things a bit easier for updating I have added NETDataset to github so I can easily post updates. you can find the project here

https://github.com/KriscoDesigns/NETDataset-for-iPhone

Using .NET Web Services And Datasets with iPhone Revision 2!

May 28, 2010 112 comments

***Updated to work with iPhone iOS4.0.1 There seems to be a problem with the old code on version 4.0+ where the last record crashes the app in the XMLDataSetParser.m class Thanks to Douwe Querty for submitting a fix!

Well I must apologize for the amount of time it has taken me to post this, I have been finished this version for quite a while however our company has been extremely busy and I have not had time to post this! But fret no more for here it is! the second version of the iPhone Dataset Parser! I will now call this project the NETDataset Project.

Let me re-iterate before we begin that I am a self taught developer coming from .NET to iphone development, and while I am pretty well versed in objective C now, I am by no means an expert. If you see something that needs to be fixed such as memory leaks proper usage of functions etc, please contact me and tell me how to fix those problems instead of just spamming in the comments about how its full of memory leaks or how I am not coding this properly.

(by the way I discovered analyzer and its tantalizingness since the last version so this version is now memory leak free!)

Whats New in this version?

  • A Sample project has been provided to make things easier to understand and implement
  • Using Asynchronous calls now shown in sample project
  • Connecting Data to your UITableView in sample project
  • Better table structure, can now reference data by using column names as the key.
  • Sorting Data Alphabetically
  • Performance increases
  • Memory Leak fixes

If you are updating from the old code you will find that almost everything relating to the querying/dataset functions no longer work the same so be aware if this is an upgrade you will need to make some changes to the way you handle the data. (Which is far far easier now by the way)

The biggest difference is the way the data is now returned from the parser. We now have a structure that looks like this

Dataset

NSDictionary(Tables) key=tablename value=arrayofTables
----------NSDictionary (Table) key=rowid value=arrayofrows
------------------------------------NSDictionary(Rows)key=columnName value=columnvalue

this allows us to ask for a column value using the column name!!! so much nicer!
for example to get a column value all we do is call
[row objectForKey:@"Column1"]

Lets start again with the essential files

Download the new version and sample project from github here

add these files to your project including the example cacheDBCommands files

Simply drag the NETDataset folder from the sample project to your own project the folder should contain the same 6 files

To follow along this example you should ALSO copy the CacheDBCommands.h and .m files you should now have all these files in your project

DataSet.h
DataSet.m
XMLDataSetParser.h
XMLDataSetParser.m
WebServiceHelper.h
WebServiceHelper.m
CacheDBCommands.h
CacheDBCommands.m

1. First go to your view controller and include the CacheDBCommands.h file to your viewController.h file

#import "CacheDBCommands.h"

2. Add the CacheDBDelegate to your view controllers header file

@interface DatasetParserViewController : UITableViewController <CacheDBDelegate> {

3. Create a property/Variable in your view controller for the cachedb class

CacheDBCommands *cacheDB;
@property(nonatomic, retain)CacheDBCommands *cacheDB;

4.Initialize cachedb and set delegate in your view controllers viewDidLoad event

cacheDB = [[CacheDBCommands alloc] init];
cacheDB.delegate = self;

5.Call your download function from the view controller

[cacheDB initDownloadMyDataset:@"param1Value" Param2:@"pram2Value"];

6. Modify the CacheDBCommands class to  suit your needs

The initDownloadMyDataset function is simply a handler method that creates a new Asynchronous operation for your actual method call. This way your app doesnt hang waiting for a response. It creates an NSInvocationOperation which contains your actual working method and adds it to the NSOperationQueue.  We pass any parameters along with the operation, since the NSOperation only accepts a single object for parameters, we need to create an array of parameters and pass the single array object along if we have more than one parameter for our worker method.

In the example the working operation method is called getMyDataset and it accepts the single array parameter that we passed to the NSInvocationOperation.

This method is where the actual connection to the server is made and the data passed to the web service.
Lets break it down! o/< o|< o\<
ok all dancing aside…
first we get our parameters out of the array

NSString *param1 = [params objectAtIndex:0];
NSString *param2 = [params objectAtIndex:1];

Next we create a WebServiceHelper to make our connection to the server

// Create an object to the class above which is the connection to the WCF Service
WebServiceHelper *DataCon = [[WebServiceHelper alloc] init];

Now we set the connection info which includes the XMLNamespace (which must match EXACTLY to what you have set in your web service)

//set up service method and urls
DataCon.XMLNameSpace = self.XMLNamespace;
DataCon.XMLURLAddress = self.ServerURL;

Next we need to specify which method in the web service we want to invoke. Now the most important thing to remember is the method name and its parameters must
also match EXACTLY to what you have in your web service.

//set up method and parameters
DataCon.MethodName = @"getMyDataset";

DataCon.MethodParameters = [[NSMutableDictionary alloc] init];
[DataCon.MethodParameters setObject:param1 forKey:@"param1"];
[DataCon.MethodParameters setObject:param2 forKey:@"param2"];

This next part simply initiates the call and downloads the response as raw data into the NSMutableData object

NSMutableData *retData;
retData = [DataCon initiateConnection];

Now that we have our data we want to make it into something useful, like a dataset! This is where the Dataset and XMLDatasetParser classes do their magic!
If you wanted to instead retrieve something else like a string or a boolean or an integer from your service method, you would need to write your own NSXMLParser class to handle those. I have not had a need for this yet as I am fine with just passing back datasets. If you do end up writing one email it to me and I will add it to the NETDataset project :)
If you uncomment the doDebug line you will get the XML returned from the soap service NSLogged to the console. This becomes very useful when debugging.
once parseXMLWithData is called the dataset object will now contain the tables and rows from your dataset.

//self.myDataset.doDebug = YES; //uncomment to print all data to NSLog
[self.myDataset parseXMLWithData:retData];

[DataCon release];

The last step in the cacheDbCommands class is to call our delegate function which lets the View Controller know we are done downloading the dataset and we have our data!

//call delegate to let view know we have finished downloading this
[delegate performSelectorOnMainThread:@selector(didFinishDownloading:)
withObject:self
waitUntilDone:NO];

7.Handle the delegate callback events

#pragma mark -
#pragma mark CacheDBCommands Delegate

- (void)willStartDownloading:(CacheDBCommands *)cacheDB
{
//NSLog(@"Delegate called start downloading", nil);
[self.act startAnimating];
self.act.hidden = NO;
}
-(void)didFinishDownloading:(CacheDBCommands *)acacheDB
{
//NSLog(@"Delegate called finish downloading", nil);

NSMutableDictionary *rows = [[NSMutableDictionary alloc] initWithDictionary:[cacheDB.myDataset getRowsForTable:@"Table1"]];
//each object in the rows dictionary contains a Key which is the rowid number and the value is a corresponding array of columns and values
NSArray *rowValues = [[NSMutableArray alloc] initWithArray:[rows allValues]];
//each object in the rowValues array is a dictionary object containing all of the columns and values
NSMutableArray *data = [[NSMutableArray alloc] initWithArray:rowValues];

[rows release];
[self.tableView reloadData];
[self.act stopAnimating];
}

8. Do what you want! Your Done!
You can also query the dataset for a value using the function getRowsForTableWhereColumnEquals I often use this to join two tables together or use the first table as a section header in the tableview and the second table as the data

This accepts 3 parameters TableName ColumnName and Searchstring

NSMutableArray *filteredData= [[NSMutableArray alloc] initWithArray:[cacheDB.myDataset getRowsForTableWhereColumnEquals:@"Table1" Column:@"Column1" Where:@"happyfish"]]];

Sorting Your Data

The NSXMLParser runs Asynchronously as it parses through the document, this is why even though a dataset is ordered sometimes your data is still not in the right order when you add the cells to your UITableview. Here is a utility function that I use to resort the order of an array of rows by column name.

*** updated now supports numerical ordering and duplicate entries since caseInsensitiveSearch does not order numbers properly in a string.

-(void)sortArrayContainingDictionaryItemsByKey:(NSString *)keyName ArrayToSort:(id)arrayToSort Ascending:(BOOL)asc isNumeric:(BOOL)isNumeric
{
NSMutableArray *unsortedValues = [[NSMutableArray alloc] init];
NSMutableArray *sortedArray = [[NSMutableArray alloc] init];
NSUInteger i,e;
for (i=0; i<[arrayToSort count]; i++) {
[unsortedValues addObject:[[arrayToSort objectAtIndex:i] objectForKey:keyName]];
}
//NSArray *sortedValues = [unsortedValues sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSSortDescriptor *sortDesc;
if(isNumeric == YES){
sortDesc = [[NSSortDescriptor alloc] initWithKey:nil ascending:asc selector:@selector(numericCompare:)];
}
else {
sortDesc = [[NSSortDescriptor alloc] initWithKey:nil ascending:asc selector:@selector(caseInsensitiveCompare:)];
}
NSArray *sortedValues = [unsortedValues sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDesc]];
NSMutableDictionary *dupCount = [[NSMutableDictionary alloc] init];
for (i=0; i<[sortedValues count]; i++) {
//loop through each sorted item
NSInteger newcnt = 0;//reset newcnt for duplicates
for (e=0; e<[arrayToSort count]; e++) {
//set duplicate counter
//find the matching StyleName
NSString *avalue = [[NSString alloc] initWithString:[[arrayToSort objectAtIndex:e] objectForKey:keyName]];
if ([avalue isEqualToString:(NSString *)[sortedValues objectAtIndex:i]])
{
NSInteger cnt = (NSInteger)[dupCount objectForKey:avalue];
//this has been found previously we need to skip this index if we are not at the matchign duplciate position
if (newcnt == cnt || cnt == 0) {
//this is the right record to add
cnt++;
[dupCount setObject:[NSString stringWithFormat:@"%d", cnt, nil] forKey:avalue];
[sortedArray addObject:[arrayToSort objectAtIndex:e]];
[avalue release];
break;//break out in case there are duplicate matches
}else {
//this is the wrong record skip over this one
newcnt++;
}
}
[avalue release];
}
}
[dupCount release];
for (i=0; i<[sortedArray count]; i++) {
[arrayToSort replaceObjectAtIndex:i withObject:[sortedArray objectAtIndex:i]];
}
[sortDesc release];
[unsortedValues release];
[sortedArray release];
}


Now lets say I have a dataset containing multiple vehicles but I only want the cars and I want them sorted alphabetically.

NSMutableArray *myData= [[NSMutableArray alloc] initWithArray:[acacheDB.myDataset getRowsForTableWhereColumnEquals:@"Table1" Column:@"VehicleType" Where:@"Car"]];

[self sortArrayContainingDictionaryItemsByKey:@"VehicleType" ArrayToSort:myData isNumeric:NO];

Thats it! mydata should now be an array of rows sorted by the column!

*****EDIT Please note If you are using [rows allValues] and you want to sort on that Array you will not be able to since the array is Immutable, you will get a selector does not recognize instance error. You must convert to a mutable array with myMutableArray = [NSMutableArray arrayWithArray:[rows allValues]];
then to get the first row you just call

NSDictionary *firstRow = [myData objectAtIndex:0];

to get say the vehicle model I would add on

NSString *model = [firstRow objectForKey:@"VehicleModel"];

I hope this framework helps you along your way to creating some amazing apps! Please send me the links to your apps on the app store! I will post them here! As always if you have questions please ask in the comments I do my best to answer everyone!

Categories: iPhone, Programming

Using .NET web services and dataset objects in your iphone app

October 19, 2009 114 comments

iPhone XML SOAP or .NET Web Services

can seem overwhelming at first but its actually not too hard to do, you can even download a .NET dataset and query it on the iPhone!

Being a complete n00b to iphone’s cocoa touch api / objective C and then jumping in feet first to iphone programming is like being swallowed by an enormous whale. Its very dark, you can see the blow hole, but you know the only way of reaching it is to be blown out by a mucous-infused geisure of  hot and sticky whale snot. (if you have ever tried to obtain help on irc or various forums you know what I am talking about) not to mention the endless sea of apple docs that may or may not contain any information that you actually need depending on your luck.

That being said after much hair pulling reading docs forums and some examples from everywhere I have put together a simple solution to connect to a .NET web service over https and return a dataset object back to the iphone that can be queried and used accordingly.

Please Note this article is now deprecated you should use the new framework here
I Can not support this version any more if you ask for help with this version you will not be answered.

Download This: iPhone .NET Dataset Framework.zip

In the attached file you will find 6 documents:

DataSet.h
DataSet.m
XMLDataSetParser.h
XMLDataSetParser.m
WebServiceHelper.h
WebServiceHelper.m

These files are pretty much self explanatory. DataSet.h/.m contain code for creating your DataSet Object and contain methods for querying the dataset.

WebServiceHelper contains the code to connect to the appropriate web service with the appropriate methods and parameters

XMLDataSetParser will take the data received from the webservice and pipe it into your DataSet Object.

To use an XML .NET Web service all you need to do is include these files in your project and then call the following procedures.

//First import the relevant files to your viewcontroller class (XMLDataSetParser is
//included by the DataSet class so there is no need to import it here)

#import "WebServiceHelper.h"
#import "DataSet.h"

// Create a connection to the web service
WebServiceHelper *DataCon = [[WebServiceHelper alloc] init];
//set up service method and urls please visit the webservice address in a browser to
//get the exact strings the service expects

DataCon.XMLNameSpace = @"https://myurl.com/WebService";
DataCon.XMLURLAddress = @"https://myurl.com/WebService/service.asmx";
DataCon.MethodName = @"getDataSetFromServer";

//add parameters **PARAMETERS ARE CASE SENSITIVE MAKE SURE THEY ARE TYPED CORRECTLY
//AS THE SERVICE EXPECTS THEM**

DataCon.MethodParameters = [[NSMutableDictionary alloc] init];
[DataCon.MethodParameters setObject:@"Parameter1" forKey:@"P1"];
[DataCon.MethodParameters setObject:@"Parameter2" forKey:@"P2"];

//Connect to the service and retrieve the xml raw data into a NSMutableDataObject
//be sure to include a NSMutableData object called "data" or whatever you wish in
//your viewcontroller

self.data = [DataCon initiateConnection];

//Create a dataset object using the new raw data we received from the service
DataSet *dsMyDataSet = [[DataSet alloc] initWithXMLData:self.data];

//Now we have a dataset filled with data from the initWithXMLData command lets
//query some data from it!
//Set up a dictionary object to hold our query data from the dataset

NSMutableDictionary *mydata= [[NSMutableDictionary alloc] init];

//retrieve all rows from the selected table and column
mydata = [dsMyDataSet getRowsForTableAndColumn:@"Table1" col:@"Username" ];
//mydata should contain all rows from column "Username"

//retrieve all rows from the selected table and column where the CURRENT column
//matches a string

mydata = [dsMyDataSet
getRowsForTableAndColumnWhereEqualsString:@"Table1" col:@"username" where:@"bob"];
//mydata should contain all rows from column username containing the exact match "bob"

//retrieve all rows from the selected table and column where a DIFFERENT column
//matches a string

mydata = [dsMyDataSet
getRowsForTableAndColumnWhereColumnEqualsString:@"Table1"
col:@"username" whereColumn:@"email" whereValue:@"bob@microsoft.com"];
//mydata should contain all rows from column "username" where the column "email"
//contains the exact match "bob@microsoft.com"

//you can do what you want with the data at this point like a simple iteration
NSEnumerator *userIterator= [mydata objectEnumerator];

NSString *username;

while(username =  [userIterator nextObject])
{
NSLog(@"Username: %@", username);
}
[mydata release];

Thats it!!! Hope this helps someone else save as much time as it is now saving me!

Categories: iPhone, Programming

Dynamic Iframe height using javascript

April 16, 2009 1 comment

Welp another challenge another day. My good pal Scott (also  at Imperium.ca) gets the credit for this one. We found while using a dotnetnuke back end it was far easier and far less limited to create our custom applications separately and include them in iframes and simply inherit the permissions from the dotnetnuke namespace in .NET. So while this worked great we had a huge draw back, the iframes were static height and although there was an “auto” setting in dotnetnuke, it did not appear to be functional in any of the browsers we tested.

Enter the dynamic iframe height.

We scoured much code for working examples but were hard pressed to find any that were cross browser compatible. We found some code at dynamicdrive.com while it did work resizing the iframes it was still missing a few things. One problem is we were not writing the “<iframe>” tag manually so we could not follow part two of the instructions, also part 3 instructs to place the resize call in an <a href> tag. Again we needed the script to automatically resize any and all iframes on the page once the child page was loaded. Scott tinkered until… in firefox IE7 and safari browsers we could add iframes and when the page fully loaded it would automatically adjust the iframe height by including one javascript file in the parent page and one javascript file in the child page.

I hope this helps someone else as much as it has helped us.

There are 2 js files that we will use the first js file goes in the parent page head block and loads the script for the parent page.

<!– BEGIN CODE –>

<script type=”text/javascript”>

/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=[];

//Should script hide iframe from browsers that don’t support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide=”yes”

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf(“Firefox”)).split(“/”)[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])

//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide==”no”){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display=”block”
tempobj.style.overflow=”visible”
}
}
}

function resizeIframe(frameid){
var buffer = 10;
var currentfr=document.getElementById(frameid)
currentfr.style.overflow=”hidden”
currentfr.scrolling=”no”

if (currentfr && !window.opera){
currentfr.style.display=”block”
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight + buffer;
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight + buffer;
if (currentfr.addEventListener)
currentfr.addEventListener(“load”, readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent(“onload”, readjustIframe) // Bug fix line
currentfr.attachEvent(“onload”, readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

function stretchAllIframes() {
var objs = document.getElementsByTagName(“iframe”);
for(var i=0; i < objs.length; i++) {
iframeids[iframeids.length] = objs[i].id;
}

resizeCaller();
}

</script>

<!– END CODE –>

The second code is for the page that will be loaded into an iframe

<!– BEGIN CODE –>

<script type=”text/javascript”>

function addOnloadEvent(fnc){
if ( typeof window.addEventListener != “undefined” )
window.addEventListener( “load”, fnc, false );
else if ( typeof window.attachEvent != “undefined” ) {
window.attachEvent( “onload”, fnc );
}
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
window[fnc]();
};
}
else
window.onload = fnc;
}
}

addOnloadEvent(parent.stretchAllIframes);
</script>

<!– END CODE–>

Categories: Programming

Centering the scrollbar horizontally using javascript

April 1, 2009 2 comments

So normally when we develop a website template we make it liquid layout to fit in most browsers however in some cases we want the minimum width to be set with an optional overflow image. Kind of hard to picture… at any rate we wanted the browser to scroll horizontally but be centered on the page in lower resolutions without having to mess with the template.

I did a lot of searching and even found some people saying it was not possible. Well I tell you it is. Here is a script that will work for you. Just copy to your own autoscroll.js file and include it, or you can copy paste this into a script block.

function setScroll()
{
var docWidth;
var docMinWidth = 1182;  //min width in pixels any browser size smaller then this will cause the scrollbar to appear and center

docWidth = getDocWidth();


if( typeof( window.pageYOffset ) == ‘number’ ) {
//Netscape compliant
scrOfY = window.pageYOffset;
scrOfX = window.pageXOffset;
if (docWidth <
docMinWidth ) { window.scroll((docMinWidth - docWidth) / 2, scrOfY);}
} else if( document.body && ( document.body.scrollLeft != ‘undefined’ || document.body.scrollTop != ‘undefined’ ) ) {
//DOM compliant
scrOfY = document.body.scrollTop;
scrOfX = document.body.scrollLeft;
if (docWidth <
docMinWidth ) { window.scroll((docMinWidth - docWidth) / 2, scrOfY);}
} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
//IE6 standards compliant mode
scrOfY = document.documentElement.scrollTop;
scrOfX = document.documentElement.scrollLeft;
if (docWidth <
docMinWidth ) { window.scroll((docMinWidth - docWidth) / 2, scrOfY);}
}

}

function getDocWidth()
{
if (document.body.scrollWidth)
return document.body.scrollWidth;
var w = document.documentElement.offsetWidth;
if (window.scrollMaxX)
w += window.scrollMaxX;
return w;
}

function addOnloadEvent(fnc){
if ( typeof window.addEventListener != “undefined” )
window.addEventListener( “load”, fnc, false );
else if ( typeof window.attachEvent != “undefined” ) {
window.attachEvent( “onload”, fnc );
}
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
window[fnc]();
};
}
else
window.onload = fnc;
}
}

addOnloadEvent(setScroll);

Categories: Programming
Follow

Get every new post delivered to your Inbox.