Visual Basic is a third generation event-driven programming language. The Microsoft Corporation released Visual Basic in 1987. It was indeed the first visual development tool from Microsoft. Visual Basic was derived from BASIC and enables rapid application development of graphical user interface applications, access to databases using DAO, RDO, or ADO, and creation of ActiveX controls and objects. The language not only allows Visual Basic programmers to create simple GUI applications, but also helps them develop quite complex applications. Visual Basic allows developers to target Windows, Web, and mobile devices.
Programming in Visual Basic
is a combination of visually arranging components on a form, specifying
attributes and actions of those components. Since the default
attributes and actions ought to be defined for the components, it is
very simple to write a program without the help of a Visual Basic programmer. Forms can be created using drag and drop techniques. Visual Basic
provides many interesting sets of tools to help you in building
exciting and entertaining applications. It provides these tools to make
your life easier, since the entire coding is already written for you.
Moreover, it is a user friendly language which is very effective and
efficient. A tool is used to place controls such as text boxes, buttons,
etc on the form window. Default values will be provided when a control
is created, but it can be changed by the Visual Basic programmer.
Visual Basic is not only a programming language, but it also has a complete graphical development environment. Visual Basic has the ability to develop programs that can be used as a front end application to a database system, and serving as the user interface which collects input from the user and displays formatted output in an attractive format. As the Visual Basic programmer works in the graphical environment, much of the program code is automatically generated by the Visual Basic program. The main object in Visual Basic
is called a form. Once you create forms, you can change the properties
using properties window. Finally, you can add events to your controls.
Events are responses to actions performed on controls.
Using
Visual Basic's tools, you can quickly translate an abstract idea into a
program design which you can actually see on the screen. VB encourages
you to experiment, revise, correct, and network your design until the
project meets your requirements. Visual Basic Programmer use the language in different areas such as Education, Business, Accounting, Marketing and Sales. Visual Basic
supports a number of common programming constructs and language
elements. Once you understand the basics of the language, you can create
powerful applications using Visual Basic.
Visual Basic can
create executables i.e. EXE files, ActiveX controls, but it is primarily
used to develop Windows applications. It is also used to interface web database systems. This generation of Visual Basic continues the tradition of giving you a faster and easier way to create .NET framework-based applications. Visual Basic
also fully integrates the .NET framework and the common language
runtime, which provide language interoperability, garbage collection,
enhanced security, and versioning support.
Sunday, April 29, 2012
Crop Image File Size, Width & Height Using Php Script
Crop Images Contextually
Crop images contextually for faster downloads and higher impact. By cropping maximally and resizing you can convey meaning without slowing down your web pages.
However, we've seen many sites that either use HTML's width and height attributes to resize larger images, or minimally crop and resize images to lose vital information. A better way to create images optimized for the Web is to crop them contextually.
Contextually Cropping
What is cropping contextually? Many times digital images shot for Web use have a border of useless space around the object(s) of interest. Rather than crop to just the film or chip's border, crop contextually down to the minimum dimensions that still convey the meaning or context of your image.
Note how the author is now more recognizable in the cropped version (behind the sunscreen) and the lettering is larger and more legible. Most importantly, the image has more impact, with the subject taking up more of the frame. This cropped image could be shown with a smaller dimension, saving file size.
Resize to a Smaller Thumbnail
Once you've got your image maximally cropped, resize and sharpen it to create a smaller thumbnail image. To give the reader more detail, you can provide a larger version (cropped or uncropped) of the image linked to that thumbnail.
This two-step process of cropping maximally and resizing is what Jakob Nielsen calls "relevance-enhanced image reduction." Nielsen writes that by combining cropping and scaling you can "preserve both content and detail, even at very small sizes." (Nielsen 2000)
Extreme Closeup for a Sneak Preview
Some high fashion sites actually use only the important part of an image as a thumbnail. For example, just the shoulder or neckline of a style - click and you get the full shots with details. This "image tease" technique can add an artistic feel to a site. Let's get up close and personal with our intrepid traveler.
Extreme Cropping through Rearrangement
In extreme cases you could rearrange the target objects and reshoot, or move them closer together in your favorite image editing program. The idea is to use the smallest possible image that still conveys the information you want to display. You may need to bump up font sizes to withstand more extreme image reductions.
JPEG Cropping Caution
Be careful when resaving JPEG images. Reoptimizing an existing JPEG can compound compression artifacts. It is possible to transform JPEGs losslessly, however. Lossless transformations (like 90-degree rotations and flips) require the dimensions of the JPEG to be a multiple of the block size (16x16, 16x8, or 8x8 pixels for color JPEGs). Lossless crops are also possible by cropping to block boundaries with specialized software, like JPEG Wizard.
Crop images contextually for faster downloads and higher impact. By cropping maximally and resizing you can convey meaning without slowing down your web pages.
However, we've seen many sites that either use HTML's width and height attributes to resize larger images, or minimally crop and resize images to lose vital information. A better way to create images optimized for the Web is to crop them contextually.
Contextually Cropping
What is cropping contextually? Many times digital images shot for Web use have a border of useless space around the object(s) of interest. Rather than crop to just the film or chip's border, crop contextually down to the minimum dimensions that still convey the meaning or context of your image.
Note how the author is now more recognizable in the cropped version (behind the sunscreen) and the lettering is larger and more legible. Most importantly, the image has more impact, with the subject taking up more of the frame. This cropped image could be shown with a smaller dimension, saving file size.
Resize to a Smaller Thumbnail
Once you've got your image maximally cropped, resize and sharpen it to create a smaller thumbnail image. To give the reader more detail, you can provide a larger version (cropped or uncropped) of the image linked to that thumbnail.
This two-step process of cropping maximally and resizing is what Jakob Nielsen calls "relevance-enhanced image reduction." Nielsen writes that by combining cropping and scaling you can "preserve both content and detail, even at very small sizes." (Nielsen 2000)
Extreme Closeup for a Sneak Preview
Some high fashion sites actually use only the important part of an image as a thumbnail. For example, just the shoulder or neckline of a style - click and you get the full shots with details. This "image tease" technique can add an artistic feel to a site. Let's get up close and personal with our intrepid traveler.
Extreme Cropping through Rearrangement
In extreme cases you could rearrange the target objects and reshoot, or move them closer together in your favorite image editing program. The idea is to use the smallest possible image that still conveys the information you want to display. You may need to bump up font sizes to withstand more extreme image reductions.
JPEG Cropping Caution
Be careful when resaving JPEG images. Reoptimizing an existing JPEG can compound compression artifacts. It is possible to transform JPEGs losslessly, however. Lossless transformations (like 90-degree rotations and flips) require the dimensions of the JPEG to be a multiple of the block size (16x16, 16x8, or 8x8 pixels for color JPEGs). Lossless crops are also possible by cropping to block boundaries with specialized software, like JPEG Wizard.
New Ajax Star Rating System in Tag Cloud Style using JQuery and PHP
New tutorial in Rating System series is here for you. It is a stylish and animated rating system I created many Ajax based Rating and Voting systems over 99Points.info. You can get
Youtube Style Ratings and Ajax Rating In this rating system i used tag cloud technique, where top times rated star will be show bigger than others. So when you want to give a rate to any image or post, Click on your desired star number from 1-5 and then this star will go to bigger and bigger on each click. This is an awesome and unique rating system. Hope you like. You can get facebook style comment script, facebook style extracting url data, youtube style share button, facebook style profile edit, Ajax search tutorial, Dynamic dropdown using jQuery and Ajax and many others.
New tutorial in Rating System series is here for you. It is a stylish and animated rating system I created many Ajax based Rating and Voting systems over 99Points.info. You can get
Youtube Style Ratings and Ajax Rating In this rating system i used tag cloud technique, where top times rated star will be show bigger than others. So when you want to give a rate to any image or post, Click on your desired star number from 1-5 and then this star will go to bigger and bigger on each click. This is an awesome and unique rating system. Hope you like. You can get facebook style comment script, facebook style extracting url data, youtube style share button, facebook style profile edit, Ajax search tutorial, Dynamic dropdown using jQuery and Ajax and many others.
Youtube Style Ratings and Ajax Rating In this rating system i used tag cloud technique, where top times rated star will be show bigger than others. So when you want to give a rate to any image or post, Click on your desired star number from 1-5 and then this star will go to bigger and bigger on each click. This is an awesome and unique rating system. Hope you like. You can get facebook style comment script, facebook style extracting url data, youtube style share button, facebook style profile edit, Ajax search tutorial, Dynamic dropdown using jQuery and Ajax and many others.
New tutorial in Rating System series is here for you. It is a stylish and animated rating system I created many Ajax based Rating and Voting systems over 99Points.info. You can get
Youtube Style Ratings and Ajax Rating In this rating system i used tag cloud technique, where top times rated star will be show bigger than others. So when you want to give a rate to any image or post, Click on your desired star number from 1-5 and then this star will go to bigger and bigger on each click. This is an awesome and unique rating system. Hope you like. You can get facebook style comment script, facebook style extracting url data, youtube style share button, facebook style profile edit, Ajax search tutorial, Dynamic dropdown using jQuery and Ajax and many others.
How Do I Become a Computer Programmer?
Programming a computer has
always fascinated me. To be able to type a few lines of english into a
machine, and then it does all sorts of things for me, was really
exciting. It still is. If I need to do some task, I just write a
programme to do it for me and I can take the rest of the week off!
If you are a creative or lateral thinking person, computer programming can be very satisfying; especially if you are doing it for yourself or freelance. I've been programming in various languages since about 1987, and I still enjoy doing it.
So how do you become a programmer? Where do you start?
First off, you need to be able to work a computer. How to use the mouse, keyboard, move files, get around explorer and so on. You also need to have a reasonable ability in math. (You can learn it as you go along as well.)
Then you need to decide what type of programmes you would like to write - financial, games, operating systems, machine controllers, etc - because each type of programming has a particular type of programming language that is particularly suited to it. For instance, Delphi is fine tuned for Databases, C++ is good for operating systems, Visual Basic works well in web applications.
Then you need to select the programming language that you would like to use. eg. Delphi, C++, Visual Basic, etc, etc.
You will have to buy yourself a Compiler, the software package that you use to write your programs. (Or use one at your school or library, or borrow a friends computer if he's got it installed. But eventually you will have to buy your own.)
Then you need to either go on a course that offers tuition in this language, or start teaching yourself; in which case you will need books to refer to. Courses are available via correspondence, at technikons or at universities.
Then you need a couple of years (part time) to do all this studying. Maybe after a month or two you will be able to turn out programmes that are kinda useful.
Programming is a bunch of
commands written in a "language" that is normal english words, but a small finite set of them, together with symbols and punctuation that all has a particular function. For example:
Procedure WriteSomething ;
begin
form1.edit1.text := 'Hi there guys" ;
form1.edit1.visible := true ;
Application.Processmessages ;
end ;
This little bit of programming would put the text "Hi there guys" into a little box on the screen; but note: This is only part of a larger programme, and won't work by itself. If you leave out one of the semi-colons or a full stop, the program won't work!
So you have to write this "english" in a particular
format, so that the compiler can "interpret" it, and convert it into machine code so that the computer can "understand" it and execute it.
A
compiler is the software that takes your programme, written in this pseudo english, and converts it into a computer readable and executable form.
If you are a creative or lateral thinking person, computer programming can be very satisfying; especially if you are doing it for yourself or freelance. I've been programming in various languages since about 1987, and I still enjoy doing it.
So how do you become a programmer? Where do you start?
First off, you need to be able to work a computer. How to use the mouse, keyboard, move files, get around explorer and so on. You also need to have a reasonable ability in math. (You can learn it as you go along as well.)
Then you need to decide what type of programmes you would like to write - financial, games, operating systems, machine controllers, etc - because each type of programming has a particular type of programming language that is particularly suited to it. For instance, Delphi is fine tuned for Databases, C++ is good for operating systems, Visual Basic works well in web applications.
Then you need to select the programming language that you would like to use. eg. Delphi, C++, Visual Basic, etc, etc.
You will have to buy yourself a Compiler, the software package that you use to write your programs. (Or use one at your school or library, or borrow a friends computer if he's got it installed. But eventually you will have to buy your own.)
Then you need to either go on a course that offers tuition in this language, or start teaching yourself; in which case you will need books to refer to. Courses are available via correspondence, at technikons or at universities.
Then you need a couple of years (part time) to do all this studying. Maybe after a month or two you will be able to turn out programmes that are kinda useful.
Programming is a bunch of
commands written in a "language" that is normal english words, but a small finite set of them, together with symbols and punctuation that all has a particular function. For example:
Procedure WriteSomething ;
begin
form1.edit1.text := 'Hi there guys" ;
form1.edit1.visible := true ;
Application.Processmessages ;
end ;
This little bit of programming would put the text "Hi there guys" into a little box on the screen; but note: This is only part of a larger programme, and won't work by itself. If you leave out one of the semi-colons or a full stop, the program won't work!
So you have to write this "english" in a particular
format, so that the compiler can "interpret" it, and convert it into machine code so that the computer can "understand" it and execute it.
A
compiler is the software that takes your programme, written in this pseudo english, and converts it into a computer readable and executable form.
What is Flex and Its Advantages
Title:
What is Flex?
Flex is very prominent and familiar with professional developers. Flex is a set of products designed in an effective way based on efficient delivery of high performance.
Flex is a standard-based programming model for high performance rich internet applications. Flex application will take advantage of adobe flash player 9 and this will enable developer to extend the capabilities enables the client with richer applications in real time.
Flex framework represents the presentation tire in multitier architecture applications and will be easy integrated with server-side functionality. If you want to create flex application then, you will start this application on Flex builder, which is IDE with visual layout, debugging, skinning, coder hinting and styling for developing rich Internet applications.
What are various features that make to adopt Flex?
I have started coding with flash since the flash version 4 and get them started coding with flash 4 by the way the only available functions in this version. Later version of flash like Flash 5 until Flash MX 2004, the coding in flash was improved too much with action script 2.0. Therefore, using advanced technology like advanced games advanced application with communication interacting with server, reading data configuration from Xml files.
However, as if now flex changes my way of working with coding writing. I want to get this technology due to it functionalities so I have stated discovering Flex and their programming classes and functions.
I have kept a function in flash to real XML file and parse it to next or previous record and I was passing this function once needed. Now and with Flex, we have predefined http classes that will work after passing URL.
With Flex has predefined functions and classes that enable us to read or synchronize data perfectly. These predefined functions and classes will work for us automatically so that I should focus on animation and interactivity. First, try to use it and see the difference. Personally, I am using Adobe Flex as tool to create RIA (Rich Internet applications).
RIAs developed into adobe Flex is the cross browser and platform compatibility. Rich internet application developed in Flash player.
Implementation of Flex player made the adobe flash player to more and more user's machine.
What is Flex?
Flex is very prominent and familiar with professional developers. Flex is a set of products designed in an effective way based on efficient delivery of high performance.
Flex is a standard-based programming model for high performance rich internet applications. Flex application will take advantage of adobe flash player 9 and this will enable developer to extend the capabilities enables the client with richer applications in real time.
Flex framework represents the presentation tire in multitier architecture applications and will be easy integrated with server-side functionality. If you want to create flex application then, you will start this application on Flex builder, which is IDE with visual layout, debugging, skinning, coder hinting and styling for developing rich Internet applications.
What are various features that make to adopt Flex?
I have started coding with flash since the flash version 4 and get them started coding with flash 4 by the way the only available functions in this version. Later version of flash like Flash 5 until Flash MX 2004, the coding in flash was improved too much with action script 2.0. Therefore, using advanced technology like advanced games advanced application with communication interacting with server, reading data configuration from Xml files.
However, as if now flex changes my way of working with coding writing. I want to get this technology due to it functionalities so I have stated discovering Flex and their programming classes and functions.
I have kept a function in flash to real XML file and parse it to next or previous record and I was passing this function once needed. Now and with Flex, we have predefined http classes that will work after passing URL.
With Flex has predefined functions and classes that enable us to read or synchronize data perfectly. These predefined functions and classes will work for us automatically so that I should focus on animation and interactivity. First, try to use it and see the difference. Personally, I am using Adobe Flex as tool to create RIA (Rich Internet applications).
RIAs developed into adobe Flex is the cross browser and platform compatibility. Rich internet application developed in Flash player.
Implementation of Flex player made the adobe flash player to more and more user's machine.
Facebook Style Wall Posting and Comments System using jQuery PHP and Ajax
Facebook style wall posting and commenting system. Try a new reloaded version of demo which is almost similar to facebook style.
My previous facebook style posting system was not so much like original facebook posting style and also there is no commenting system So I created this tutorial again to complete the commenting system and I tried my best to give my dear users a complete posting script with comments system. Facebook is now a days top social networking site. So I have created some tutorialssimilar to facebook. Youtube style rating is also very popular tutorial on this blog. Hope you like it.
I have used ip check to make user restricted to there posts or comments. They can only there postings.
Two new function missed in source files. One for making links clickable and other for removing tags etc.
My previous facebook style posting system was not so much like original facebook posting style and also there is no commenting system So I created this tutorial again to complete the commenting system and I tried my best to give my dear users a complete posting script with comments system. Facebook is now a days top social networking site. So I have created some tutorials similar to facebook. Youtube style rating is also very popular tutorial on this blog. Hope you like it.
I have used ip check to make user restricted to there posts or comments. They can only there postings.
Two new function missed in source files. One for making links clickable and other for removing tags etc.
There are many awesome tutorials on 99points.info
My previous facebook style posting system was not so much like original facebook posting style and also there is no commenting system So I created this tutorial again to complete the commenting system and I tried my best to give my dear users a complete posting script with comments system. Facebook is now a days top social networking site. So I have created some tutorialssimilar to facebook. Youtube style rating is also very popular tutorial on this blog. Hope you like it.
I have used ip check to make user restricted to there posts or comments. They can only there postings.
Two new function missed in source files. One for making links clickable and other for removing tags etc.
My previous facebook style posting system was not so much like original facebook posting style and also there is no commenting system So I created this tutorial again to complete the commenting system and I tried my best to give my dear users a complete posting script with comments system. Facebook is now a days top social networking site. So I have created some tutorials similar to facebook. Youtube style rating is also very popular tutorial on this blog. Hope you like it.
I have used ip check to make user restricted to there posts or comments. They can only there postings.
Two new function missed in source files. One for making links clickable and other for removing tags etc.
There are many awesome tutorials on 99points.info
Ajax Rating Script - Php & Mysql
Introduction
Frequent visitors of ajax enabled websites, like ajaxian, have all witnessed them already: ajax rating widgets. They are flashy, animated, you can use them to rate the content (usually without refreshing the page) and if you could, you'd present them to your parents and marry them. Compared to the classic rating system, as on IMDb, they incite people to click them, reducing the effective rating process to only one click.
In this tutorial, I want to show you how to create the JavaScript framework to display the animated rating widget and how to connect it to your server backend by using some of the most common Ajax frameworks out there. I clearly separate the page creation from the JavaScript functions and the rating backend, to allow the script to be as flexible as possible and to be easy integrable into your existing website.
This tutorial is not meant to present you with a finished script (even though you could simply copy&paste the end result into your website and make it work without any problems), but rather to explain the design and implementation process that would enable you to create your own widgets if you'd need to. Getting started with the HTML markup
What It Is
This is a rating bar script done with PHP and mySQL that allows users to rate things like can be done all web 2.0-like with no page refresh. It is a major improvement on the previous version because it is now unobtrusive, meaning that if Javascript is off it will still work (although the page will refresh). You can also set the number of rating units you want to use (i.e. 4 stars, 5 stars, or 10 stars) on a rater to rater basis (see samples below or read the docs). A few other changes were made as well see the docs for details. Note that this script isn t tied to any specific system (such as WordPress), so you should be able to adapt it to your situation without too much trouble. What are you waiting for? Check the Ajax Rating demos.
It is most important that there are no line breaks in this code, as this will complicate the DOM tree unnecessarily. If you are uncertain about what I just said, please read the W3Schools HTML DOM Tutorial for further reference, since we are going to access the DOM directly from within our JavaScript.
As you can see, the div container is pretty easy to generate in the server-side scripting language, requiring most of the time only one line:
printf("%s", ratingId, rating);
The "continue" keyword in our JavaScript code, just like in most other programming languages, continues with the next iteration of the loop and prevents the execution of the rest of the code during that iteration. Read the rating value
Now that we have all the rating containers, we can start by reading the rating value written as text inside the div container. To read that value, we access the first child node of the div container, which is a TextNode, and access its nodeValue, which returns the text CDATA in case of text nodes. This is done by the following line:
var rating = ratings[i].firstChild.nodeValue;
There is no graceful way to recover from that error, so I simply decided to continue with the next rating container and prevent that error from happening within the server backend.
Now, we need to loop over the number of stars that are displayed and check what the image graphic will be that is displayed on the star. Using the HTML DOM function createElement(), we initialize a new image and progressively add the respective values to that element. Of course, the first thing we are interested in is the displayed image: we could either test the rating against the current iteration value or we could decrement the rating value during each iteration and test against 1, 0.5 and 0. I decided to decrement the rating during each iteration, which presents me with three simple cases to test: if the rating is greater than or equal than 1, the star is "on", if the rating is exactly 0.5, the star is "half" otherwise, the star is "off". This results in the following code:
for (var j = 0; j < NUMBER_OF_STARS; j++)
{
var star = document.createElement('img');
if (rating >= 1)
{
star.setAttribute('src', './images/stars/rating_on.gif');
rating--;
}
else if(rating == 0.5)
{
star.setAttribute('src', './images/stars/rating_half.gif');
rating = 0;
}
else
{
star.setAttribute('src', './images/stars/rating_off.gif');
}
ratings[i].appendChild(star);
}
Conclusion
Our current JavaScript allows us to transform specially marked div containers into animated rating widgets that we can use in specialized Ajax frameworks to link to our server backend. The HTML markup is completely separated from the JavaScript code, which will leave the user with a not very stylish but still visual display of the current rating in case JavaScript is disabled. I've put together a ZIP file with the current result, containing an HTML file, a CSS file, the JavaScript file and the images. Connect the widget to the server with different frameworks
Please make sure to delete the "window.onload=init_rating;" line in the "script.js" file if you downloaded the .zip file, since we're using the specialized framework onload event.
The examples below are only an illustration of how this given task is achievable with a variety of different JavaScript frameworks. It should not be used as a reference about what framework is superior since not every framework follows the same route and has the same objectives. Before jumping to conclusion, you should read more sources and also hear every site. There are good reasons for dojo not having the $ operator and some interesting points can be found here (in the comments). When you need to decide which framework to chose, base your decision on your specific task and the framework you're most comfortable with. The PHP backend
Frequent visitors of ajax enabled websites, like ajaxian, have all witnessed them already: ajax rating widgets. They are flashy, animated, you can use them to rate the content (usually without refreshing the page) and if you could, you'd present them to your parents and marry them. Compared to the classic rating system, as on IMDb, they incite people to click them, reducing the effective rating process to only one click.
In this tutorial, I want to show you how to create the JavaScript framework to display the animated rating widget and how to connect it to your server backend by using some of the most common Ajax frameworks out there. I clearly separate the page creation from the JavaScript functions and the rating backend, to allow the script to be as flexible as possible and to be easy integrable into your existing website.
This tutorial is not meant to present you with a finished script (even though you could simply copy&paste the end result into your website and make it work without any problems), but rather to explain the design and implementation process that would enable you to create your own widgets if you'd need to. Getting started with the HTML markup
What It Is
This is a rating bar script done with PHP and mySQL that allows users to rate things like can be done all web 2.0-like with no page refresh. It is a major improvement on the previous version because it is now unobtrusive, meaning that if Javascript is off it will still work (although the page will refresh). You can also set the number of rating units you want to use (i.e. 4 stars, 5 stars, or 10 stars) on a rater to rater basis (see samples below or read the docs). A few other changes were made as well see the docs for details. Note that this script isn t tied to any specific system (such as WordPress), so you should be able to adapt it to your situation without too much trouble. What are you waiting for? Check the Ajax Rating demos.
It is most important that there are no line breaks in this code, as this will complicate the DOM tree unnecessarily. If you are uncertain about what I just said, please read the W3Schools HTML DOM Tutorial for further reference, since we are going to access the DOM directly from within our JavaScript.
As you can see, the div container is pretty easy to generate in the server-side scripting language, requiring most of the time only one line:
printf("%s", ratingId, rating);
The "continue" keyword in our JavaScript code, just like in most other programming languages, continues with the next iteration of the loop and prevents the execution of the rest of the code during that iteration. Read the rating value
Now that we have all the rating containers, we can start by reading the rating value written as text inside the div container. To read that value, we access the first child node of the div container, which is a TextNode, and access its nodeValue, which returns the text CDATA in case of text nodes. This is done by the following line:
var rating = ratings[i].firstChild.nodeValue;
There is no graceful way to recover from that error, so I simply decided to continue with the next rating container and prevent that error from happening within the server backend.
Now, we need to loop over the number of stars that are displayed and check what the image graphic will be that is displayed on the star. Using the HTML DOM function createElement(), we initialize a new image and progressively add the respective values to that element. Of course, the first thing we are interested in is the displayed image: we could either test the rating against the current iteration value or we could decrement the rating value during each iteration and test against 1, 0.5 and 0. I decided to decrement the rating during each iteration, which presents me with three simple cases to test: if the rating is greater than or equal than 1, the star is "on", if the rating is exactly 0.5, the star is "half" otherwise, the star is "off". This results in the following code:
for (var j = 0; j < NUMBER_OF_STARS; j++)
{
var star = document.createElement('img');
if (rating >= 1)
{
star.setAttribute('src', './images/stars/rating_on.gif');
rating--;
}
else if(rating == 0.5)
{
star.setAttribute('src', './images/stars/rating_half.gif');
rating = 0;
}
else
{
star.setAttribute('src', './images/stars/rating_off.gif');
}
ratings[i].appendChild(star);
}
Conclusion
Our current JavaScript allows us to transform specially marked div containers into animated rating widgets that we can use in specialized Ajax frameworks to link to our server backend. The HTML markup is completely separated from the JavaScript code, which will leave the user with a not very stylish but still visual display of the current rating in case JavaScript is disabled. I've put together a ZIP file with the current result, containing an HTML file, a CSS file, the JavaScript file and the images. Connect the widget to the server with different frameworks
Please make sure to delete the "window.onload=init_rating;" line in the "script.js" file if you downloaded the .zip file, since we're using the specialized framework onload event.
The examples below are only an illustration of how this given task is achievable with a variety of different JavaScript frameworks. It should not be used as a reference about what framework is superior since not every framework follows the same route and has the same objectives. Before jumping to conclusion, you should read more sources and also hear every site. There are good reasons for dojo not having the $ operator and some interesting points can be found here (in the comments). When you need to decide which framework to chose, base your decision on your specific task and the framework you're most comfortable with. The PHP backend
Subscribe to:
Posts (Atom)