Showing posts with label jquery. Show all posts
Showing posts with label jquery. Show all posts

Thursday, July 29, 2010

jQuery plugins July 2010

InputNotes


A jQuery plugin to add notes below textareas and input fields based on regex patterns. Great for validating forms and showing additional info.

Equal Column Heights


This jQuery plugin sets the height of selected elements equal to the height of the highest element with the ability to animate the change.

Full Calendar


FullCalendar is a jQuery plugin that provides a full-sized, drag & drop calendar like the one below. It uses AJAX to fetch events on-the-fly for each month and is easily configured to use your own feed format.

Button Tutorials


A nice compilation of some of the helpful tutorials that can teach you on how to use jQuery in improve and creating special effects for the buttons of your website.

Poshy Tip


A new promising tool tip with a lot of options for configuration and easy to use. It also works very well with forms.

Thumbnails Navigation Gallery


Extraordinary navigation using images, a great tutorial by codrops, definetely worth checking out.

jQuery.Spritely


A plugin for creating dynamic character and background animation in pure HTML and JavaScript. It's a simple, light-weight plugin with a few simple methods for creating animated sprites and dynamic scrolling backgrounds.

and for the iPhone and iPad experts: jQuery Swipe

Tuesday, December 15, 2009

Merging items with same title in gantt view in Sharepoint

Today, got a challenge with Sharepoint where a user wanted to see multiple entries in a gannt view in Sharepoint. Below is the jquery magic you can use in a CEWP.

function docready() {

var row = [];
var ix=0;



$('tr.ms-ganttTaskRow th').each(
  function() {
    row[ix] = $(this).parent();
    ix++;
  }
);


ix=0;
for(ix=1; ix< row.length; ix++){
   var $prevrow = row[ix].prev();
   var prevtxt = $prevrow.find('th').text();
   var curtxt  = row[ix].find('th').text();
   if (prevtxt == curtxt) {
     var colix =0;
     row[ix].find('td').each(
       function() {
         var ht = $(this).html();
         if (ht.length > 0){
           $prevrow.find('td:eq('+colix+')').html(ht);
         }
         colix++;
       }
     );
     row[ix].remove();
   }
}

}

_spBodyOnLoadFunctionNames.push("docready");


Explanation of the code:

  1. Trigger the docready on load
  2. Store all the rows in an jquery array for easy processing
  3. Walk through the rows array starting from second item and match the row header with previous row, if so, copy the contents of the columns to the row above and remove after processed.
There is only one catch, the gantt view needs to be sorted on the row header column.

Friday, September 4, 2009

Enlarge input width size in edit/new pages

When editing list items in SharePoint, one of the most irritating issues I find is the width of the input fields, in particular the rich-text editor. So I have decided to fix this.




First of all we need to go to the page and set it in edit mode, which can be done by using the ToolPaneView=2 querystring. (See SharePoint Kings for more info), eg:

.....your-sharepoint-list-url..../EditForm.aspx?ToolPaneView=2

Then add a Content Editor WebPart. Make sure it is hidden in the appearance.
Finally add the following code:

<script type="text/javascript" src="{url-to-jquery}/jquery.js" language="javascript"></script> 


<script type="text/javascript">
function docready() {
  $('.ms-formbody').css('width', '100%');
  $('.ms-long').css('width', '100%');
  $('.ms-rtelong').css('width', '100%'); 
  $('.ms-rtelonger').css('width', '100%'); 
  $('#onetIDListForm').css('width', '100%');
}

_spBodyOnLoadFunctionNames.push("docready");

</script> 

Your forms will now use the complete width of your window.

Update: 25 september - Added the rte-longer class for also resizing the rich-text boxes

Sunday, January 18, 2009

jQuery 1.3 issue - part 2

I have to apologize to the jQuery team, as it seems that jQuery does work. It seems there was a very strange issue with the Finjan software we are using at the office. When I downloaded jQuery at home, all seemed to be working.. after doing a file compare between what I got at the office and what I had downloaded at home, there was 1 line (the line I mentioned in previous post), different.

Anyway, this has been a lesson for me to double check the firewall and proxies..

Thursday, January 15, 2009

jQuery 1.3 issue/bug

First of all congrats to the jQuery team with the new 1.3 release, however maybe it is me only.. but it doesn't work. I have downloaded it used it on my test sites and none of them work: there is an issue in the jQuery code.

So I checked http://api.jquery.com and the same issue..(in IE7 and FF3)



Now I was interested what went wrong, downloaded dev version, checked the error message:



Line 2097 seemed the issue:

div.appendChild( document.createElement('Comment').data = "" );

I guess appendChild assumes an Element object, however:

document.createElement('Comment').data = ""

returns an empty string. Removing the .data="" fixes the issue for now, but I have no idea how it will effect the rest of the code.
I can't imagine that jQuery team released a non working version! Am i doing something wrong or do more people have this issue?

I still have some other pages which gives errors on events, but first a smoke :)

Sunday, December 21, 2008

Tables: The Next Evolution in CSS Layout is Now

After reading an excellent article at Vitamin about using CSS tables and how it will be next evolution for design once IE 8 is released. But I think we already should start using it, because with the help of jQuery, we can easily modify the DOM to emulate the CSS tables in IE 7 and below.

The trick is to replace the CSS table elements to real table elements for IE, which can be very easily done and the results are amazing. See my example.

Actually the code convert the elements to tables is the following:

$(document).ready(
function() {
// check for ie (it would be better to check for IE version too in the future)
if( jQuery.browser.msie){
// update the cells....
$('#container > div > div').each(
function(){
$(this).replaceWith('<td class="'+$(this).attr('class')+'">'+$(this).html()+'</td>')
}
);
// update the rows
$('#container > div').each(
function(){
$(this).replaceWith('<tr>'+$(this).html()+'</tr>')
}
);
$('#container').replaceWith('<table id="container_table">'+$('#container').html()+'</table>');
}
}
);



What the code actually does is converting the div elements containing the display: table-cell to td elements and the same for row (to tr elements) and finally the container div to a table.

To be honest, I am amazed with the results myself and for now on I will start using this technique for all my projects.

See below for the screenshots (as you notice, they all look the same)

Firefox:


Safari:


IE 7:


Of course what I have done here is a quick test whether it was possible. The code I have presented is just an idea and it can be optimized and generalized for common use.

Good luck on using the CSS tables!

Friday, July 25, 2008

Using mapstraction and Yahoo maps to determine lat/lon of a location

(View demo).

During this week, I started experimenting with maps in my web applications. As a good developer, you should always google and see what is out there. Why invent the wheel again. One the first things I encountered was a javascript framework called mapstraction. It really does a nice job on working with maps (independent of the maps provider).

Having a look at the demos provided by mapstraction it was quite easy and fast to create mapping functionality. My biggest problem was the choice of the mapping provider. Having a look at the various api's and providers, there are actually 2 mapping api's which look good: Yahoo and Google. Being stubborn and not being a sheep in a flock, I have chosen for yahoo. I think yahoo is doing a very good job with their services.

Creating the map


The first thing we need to do is to get an app key from Yahoo. After we have this we can start coding. We start off by including the javascript files to our page. Then we create a div element which will hold our map. (Keep in mind that thesize of the div element needs to be specified, either directly or in the css).

Basically we are now set for coding.


<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid={yourappkey}"></script>
<script type="text/javascript" src="js/mapstraction.js"></script>
<!-- the size must be specified here, or in the CSS -->
<div id="mapcontainer" style="width:300px;height:200px;"></div>

As always for javascript coding, I use jQuery. When the dom is ready, we will start
creating the mapstraction object and then initialize it.



$(document).ready(
function() {
var bw = $('body').width();
// we want the map to be as width as the browser window
$('#mapcontainer').css( 'width', bw);
// initialise the map with yahoo API
mapstraction = new Mapstraction('mapstraction','yahoo');
// add some controls for it (for zooming and panning)
mapstraction.addControls({
pan: true,
zoom: 'large',
map_type: true
});
// this function we will use to put some markers on the map,
// eg coming from a database
fillmap(true);
}
);

Almost done... Just need to fill the map with markers. In my example I will have 1 marker which is predefined, but you can easily get this from your database (eg, by using an ajax call)

Markers on the map

In order to be able to add markers on the map, we need to define a point based on latitude and longitude. Once we have this point, we can add the marker to the given position.

function fillmap() {
// check if we have a mapstraction defined
if (mapstraction) {
// set the lat/lon value of the location we would like to mark
// in this example, it is Rotterdam (centrum of the world :))
var lat=51.92434043666618;
var lon=4.47817325592041;
// get rid of existing markers (if they are)
mapstraction.removeAllMarkers();
// create a point with lat/lon coordinates defined
var myPoint = new LatLonPoint(lat,lon);
// create a marker positioned at a lat/lon
var my_marker = new Marker(myPoint);
// add the marker to the map
mapstraction.addMarker(my_marker);
// center map on the location and zoom (level 9)
mapstraction.setCenterAndZoom(myPoint, 9);
}
}
It is possible to add text to a marker, however this is not my goal. If you want to do that, you can use the my_marker.setInfoBubble() method.

The goal is to get the latitude and longitude values of a location the user selects on the map. In order to do this we need to add and onclick event to the map. This can easily be done by using the addEventListener of the mapstraction object.



// capture the mouse click event
mapstraction.addEventListener( 'click', onClickMap);

// on each mouse click this function will be called with the point
// object of mapstraction
function onClickMap( point) {
// the yahoo map returns 0 for lat and 180 for lon when user
// clicks on a control on the map (for example on the pan-left arrow)
if (point.lat != 0) {
// we will remove existing markers on the map (resetting the map)
mapstraction.removeAllMarkers();
// we add a marker at the clicked location
mapstraction.addMarker( new Marker( new LatLonPoint(point.lat,point.lon)));
}
}

Now we are finished. To conclude: it is very quick and easy to geo-enable your application by using mapstraction.

Demo

For a demonstration of the code, have a look at my lat/lon finder. Please look at the source to see the full implementation.

In order to accomplish the search functionality and removing of markers in the demo, I have modified/extended the mapstration.js with 2 functions (for Yahoo):

Mapstraction.findCenterAndZoom(findtxt, zoom)

Marker.setClick(onMarkerClick)

The first function allows to search on a text and then centers the found location with a zoom. The second function allows a callback function when the marker is clicked. This was a function I really missed in mapstraction.

While I was busy working on the demo, I also found it interesting to be able to retrieve the location name of clicked/entered location. This is done by using the geonames.org JSON webservices.

Finally, I also implemented the parsin of the URL with lat and lon parameters, allowing a permalink. All in all, I think it is a usefull demo ;)

Feedback/Comments

If you have any questions or remarks about this code, as always you can always contact me.

Saturday, May 19, 2007

Using CSS to clip image with the help of jQuery

Last week I was reading a nice article by Seifi explaining how to clip an image in a web page by using available CSS techniques. I did like the idea of clipping images. Sometime there is no need to show the whole image on a page, especially if you want to save space.

Although the idea of clipping images interested me, the wholeprocess of getting an image chopped scared me, especially if you need to have different clippings on different sizes. Why calculate offsets and sizes manually if there is a computer which can do this for you. To accomplish this, I took the method in the article as a base and with the help of my favorite javascript framework jQuery, I got it all automated.

How?

In order to get the process of clipping images automated, some parameters are necessary to get the job done. These parameters are: size of original image, clipping offset and clipped size. I have chosen to use attributes on the img tag, allowing setting these values during design of the page.

Example

<img src="castle.jpg" id="clipit" alt="Clipped castle image" width="300" height="225" clipwidth="136" clipheight="105" clipleft="82" cliptop="50" />


As you can see, I have used some custom properties to the img tag, which will be used by javascript during the clipping process. In order to get the image clipped I have written a javascript function which can be called.

clipImage( 'id-of-image', 1);


This function will take care of it all and it will render the clipped image with the given parameters. I didnt spend much time on the code and it is quick and dirty. Maybe it would be an idea create a jQuery plugin for it.

Demo

The demo page showing the image clipping can be found here.
Please look at the source to see the implementation.


Feedback/Comments

If you have any questions or remarks about this code, you can always contact me.


Tuesday, May 15, 2007

How to make sexy buttons with CSS - jQuery version

A quick update on the previous post on improving sexy buttons. I have a jQuery version which fixes some small issues. See the demo page for detailed information.