Ajax Updates

Ajax Updates


prettyPhoto using jQuery Plugin

Posted: 05 Sep 2009 10:17 AM PDT

prettyPhoto is a jQuery based lightbox clone. Not only does it support images, it also add support for videos, flash, YouTube, iFrames. It’s a full blown media lightbox.

It comes with useful APIs so prettyPhoto can be launched from nearly anywhere (yes, that includes Flash)!

Usage:
First include the jQuery library, prettyPhoto javascript and the prettyPhoto CSS in the head of the page(s) where you want to use prettyPhoto.

 Javascript |  copy code |? 
1
<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script> 
2
 
3
	<link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" media="screen" charset="utf-8" /> 
4
	<script src="js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>


Then, initialize prettyPhoto. Put the following code before the closing tag of your body ()

 Javascript |  copy code |? 
1
<script type="text/javascript" charset="utf-8"> 
2
		$(document).ready(function(){ 
3
			$("a[rel^='prettyPhoto']").prettyPhoto(); 
4
		}); 
5
	</script>


And...you're set!

To customize prettyPhoto, you can pass the following parameters

 Javascript |  copy code |? 
01
<script type="text/javascript" charset="utf-8"> 
02
		$(document).ready(function(){ 
03
			$("a[rel^='prettyPhoto']").prettyPhoto({ 
04
				animationSpeed: 'normal', /* fast/slow/normal */ 
05
				padding: 40, /* padding for each side of the picture */ 
06
				opacity: 0.35, /* Value betwee 0 and 1 */ 
07
				showTitle: true, /* true/false */ 
08
				allowresize: true, /* true/false */ 
09
				counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */ 
10
				theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */ 
11
				callback: function(){} 
12
			}); 
13
		}); 
14
	</script>


Version 2.5 introduced an easy to use API. You can now open prettyPhoto from anywere.

The public API functions are the following
 Javascript |  copy code |? 
1
	$.prettyPhoto.open('images/fullscreen/image.jpg','Title','Description'); 
2
	$.prettyPhoto.changePage('next'); 
3
	$.prettyPhoto.changePage('previous'); 
4
	$.prettyPhoto.close();


You can also open galleries using the API, just pass arrays to the open function.

 Javascript |  copy code |? 
1
images = ['images/fullscreen/image1.jpg','images/fullscreen/image2.jpg','images/fullscreen/image3.jpg']; 
2
	titles = ['Title 1','Title 2','Title 3']; 
3
	descriptions = ['Description 1','Description 2','Description 3'] 
4
	$.prettyPhoto.open(images,titles,descriptions); 
5
								

You can now open prettyPhoto from Flash or launch is from anywhere, anytime!
PcbtalkRapidxHTML - You Design We CodeAre My Sites Up?

Demo:
Download:
Source:
tafbutton blue16 prettyPhoto using jQuery Plugin

Related Listings:

  1. PrettyPhoto Script How to use Nothing is easier to use. First include...
  2. Pretty Photo Script with jQuery Plugin Here’s my jQuery lightbox clone, I did it because those...
  3. Jquery-Bounce plugin This project allows the user to extend the elements on...

NyroModal : jQuery Plugin

Posted: 05 Sep 2009 09:59 AM PDT

Designers seem to like using modal windows more and more, as they provide a quick way to show data without reloading the entire page. It’s easy to use and easy to design.
The big problem I experienced with every plugin I tried either using Prototype/Scriptaculous or jQuery is the customization. They say you can do whatever you want simply but that’s not fully true. The default CSS works fine, but most of time it’s a mix between required elements and optional. That mean you have to be very careful when editing it.
The other problem is the animation. That’s the worst point. I never found one plugin allowing to redefine easily the animations.

I tried to solve these problems with my plugin. I documented everything possible. The default CSS contains only optional rules. Without it, the plugin will works perfectly —but will also looks very sad. Regarding the animations, you can simply redefine them from A to Z. Thanks to the useful jQuery function like animate, fadeTo or the future enchant, it’s pretty simple.
Moreover, I added the ability to define many callbacks at different time in the process to allow you to edit the settings, the data or do whatever you need.

Features

* Ajax Call
* Ajax Call with targeting content
* Ajax call can change the modal size
* Single Image
* Images Gallery with arrow navigating
* Gallery with any kind of content
* Form
* Form in iframe
* Form with targeting content
* Form with file upload
* Form with file upload with targeting content
* Dom Element
* Manual Call
* Iframe
* Error handling
* Modal will never goes outside the view port
* Esc key to close the window
* Customizable animation
* Customizable look
* Modal title
* Ability to block only one element
* W3C valid HTML (Transitionnal)

Usage

The plugin provide some function to work with it:

* nyroModal(); is the basic function to set the click or submit function. To add the nyroModal functionnality to all links containing in #container, you’ll do:

 Javascript |  copy code |? 
1
  $('#container a').nyroModal();

Pretty long, right? As all jQuery plugin, the chain is not broken. That mean you can use it like all other jQuery functions. You can also set the settings as an object paramter to overwrite the default parameter.
* nyroModalManual(); will execute the same action like a click in a real link. You can simulate an user click or create your modal content. See demos to better understand.
* $.nyroModalSettings(settings); could be used to change the default settings if no modal are started or the current settings if a modal is currently shown. For example, it will be pretty useful to change the modal size or background color from an Ajax request. If you call this function with the width, height, and/or bgColor parameters while the modal is already shown, the related animation function will be called.
* $.nyroModalRemove(); will simply remove the modal. Could be useful if you need to close after a time or something else.

When using the gallery modal, you can also use these functions:

* $.nyroModalNext(); Go to the next image. Return the link which opened the image if successful or false if nothing was done
* $.nyroModalPrev(); Go to the previous image. Return the link which opened the image if successful or false if nothing was done

When you open a modal using an Ajax request, the scripts included in the loaded page are executed folowing these rules:

* If the modal is a targeting content, only the scripts inside this element are executed
* If the modal isn't targeting:
o All the inline script are executed
o The scripts with a src attribute to load a javascript file are loaded only if they are the attribute rel="forceLoad". This avoid the reload of jQuery for example

If you need to investigate what's going on with your modal, you could enable the debug. But sometimes, it's not enough and you want more. You could overwrite the function nyroModalDebug(msg, elts, settings); to do what ever you want!

Settings

You have 3 different ways to modify the settings:

1. Directly modify $.fn.nyroModal.settings. These settings will be used by default for every modal which will be open
2. Set at first parameter to the nyroModal(); function. Example:

$('a.nyroModal').nyroModal({bgColor: '#ffffff'});

3. Use the $.nyroModalSettings(settings); function

Here is the complete usable settings list, with their default values.

 Javascript |  copy code |? 
01
$.fn.nyroModal.settings = { 
02
  debug: false, // Show the debug in the background 
03
  blocker: false, // Element which will be blocked by the modal 
04
  modal: false, // Esc key or click backgrdound enabling or not 
05
  type: '', // nyroModal type (form, formData, iframe, image, etc...) 
06
  forceType: null, // Used to force the type 
07
  from: '', // Dom object where the call come from 
08
  hash: '', // Eventual hash in the url 
09
  processHandler: null, // Handler just before the real process 
10
  selIndicator: 'nyroModalSel', // Value added when a form or Ajax is sent with a filter content 
11
  formIndicator: 'nyroModal', // Value added when a form is sent 
12
  content: null, // Raw content if type content is used 
13
  bgColor: '#000000', // Background color 
14
  ajax: {}, // Ajax option (url, data, type, success will be overwritten for a form, url and success only for an ajax call) 
15
  swf: { // Swf player options if swf type is used. 
16
    wmode: 'transparent' 
17
  }, 
18
  width: null, // default Width If null, will be calculate automatically 
19
  height: null, // default Height If null, will be calculate automatically 
20
  minWidth: 400, // Minimum width 
21
  minHeight: 300, // Minimum height 
22
  resizable: true, // Indicate if the content is resizable. Will be set to false for swf 
23
  autoSizable: true, // Indicate if the content is auto sizable. If not, the min size will be used 
24
  padding: 20, // padding for the max modal size 
25
  regexImg: '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$', // Regex to find images 
26
  addImageDivTitle: false, // Indicate if the div title should be inserted 
27
  defaultImgAlt: 'Image', // Default alt attribute for the images 
28
  setWidthImgTitle: true, // Set the width to the image title 
29
  ltr: true, // Right to left by default. Put to false for Hebrew or Left to Right language 
30
  gallery: null, // Gallery name if provided 
31
  galleryLinks: '<a href="#" class="nyroModalPrev">Prev</a><a href="#"  class="nyroModalNext">Next</a>', // Use .nyroModalPrev and .nyroModalNext to set the navigation link 
32
  galleryCounts: galleryCounts, // Callback to show the gallery count 
33
  zIndexStart: 100, 
34
  css: { // Default CSS option for the nyroModal Div. Some will be overwritten or updated when using IE6 
35
    bg: { 
36
      position: 'absolute', 
37
      overflow: 'hidden', 
38
      top: 0, 
39
      left: 0, 
40
      height: '100%', 
41
      width: '100%' 
42
    }, 
43
    wrapper: { 
44
      position: 'absolute', 
45
      top: '50%', 
46
      left: '50%' 
47
    }, 
48
    wrapper2: { 
49
    }, 
50
    content: { 
51
      overflow: 'auto' 
52
    }, 
53
    loading: { 
54
      position: 'absolute', 
55
      top: '50%', 
56
      left: '50%', 
57
      marginTop: '-50px', 
58
      marginLeft: '-50px' 
59
    } 
60
  }, 
61
  wrap: { // Wrapper div used to style the modal regarding the content type 
62
    div: '<div class="wrapper"></div>', 
63
    ajax: '<div class="wrapper"></div>', 
64
    form: '<div class="wrapper"></div>', 
65
    formData: '<div class="wrapper"></div>', 
66
    image: '<div class="wrapperImg"></div>', 
67
    swf: '<div class="wrapperSwf"></div>', 
68
    iframe: '<div class="wrapperIframe"></div>', 
69
	iframeForm: '<div class="wrapperIframe"></div>', 
70
    manual: '<div class="wrapper"></div>' 
71
  }, 
72
  closeButton: '<a href="#" class="nyroModalClose" id="closeBut" title="close">Close</a>', // Adding automaticly as the first child of #nyroModalWrapper  
73
  title: null, // Modal title 
74
  titleFromIframe: true, // When using iframe in the same domain, try to get the title from it 
75
  openSelector: '.nyroModal', // selector for open a new modal. will be used to parse automaticly at page loading 
76
  closeSelector: '.nyroModalClose', // selector to close the modal 
77
  contentLoading: '<a href="#" class="nyroModalClose">Cancel</a>', // Loading div content 
78
  errorClass: 'error', // CSS Error class added to the loading div in case of error 
79
  contentError: 'The requested content cannot be loaded.<br />Please try again later.<br /><a href="#" class="nyroModalClose">Close</a>', // Content placed in the loading div in case of error 
80
  handleError: null, // Callback in case of error 
81
  showBackground: showBackground, // Show background animation function 
82
  hideBackground: hideBackground, // Hide background animation function 
83
  endFillContent: null, // Will be called after filling and wraping the content, before parsing closeSelector and openSelector and showing the content 
84
  showContent: showContent, // Show content animation function 
85
  endShowContent: null, // Will be called once the content is shown 
86
  beforeHideContent: null, // Will be called just before the modal closing 
87
  hideContent: hideContent, // Hide content animation function 
88
  showTransition: showTransition, // Show the transition animation (a modal is already shown and a new one is requested) 
89
  hideTransition: hideTransition, // Hide the transition animation to show the content 
90
  showLoading: showLoading, // show loading animation function 
91
  hideLoading: hideLoading, // hide loading animation function 
92
  resize: resize, // Resize animation function 
93
  endResize: null, // Will be called one the content is resized 
94
  updateBgColor: updateBgColor, // Change background color animation function 
95
  endRemove: null // Will be called once the modal is totally gone 
96
}; 
97

Demo: http://nyromodal.nyrodev.com/
Download: http://nyromodal.googlecode.com/files/nyroModal-1.5.2.zip
Source: http://nyromodal.nyrodev.com/
tafbutton blue16 NyroModal : jQuery Plugin

Related Listings:

  1. NyroModal – jQuery Script Designers seem to like using modal windows more and more,...
  2. jQuery Lightbox Plugin jQuery lightBox plugin is simple, elegant, unobtrusive, no need extra...
  3. Impromptu – prompt jQuery plugin for Forms jQuery Impromptu is an extention to help provide a more...

jQuery Flot, Plots, Canvas, Charts

Posted: 05 Sep 2009 09:32 AM PDT

Fetch and format the data to be processed by Flot to generate the bar chart.
jQuery + Flot=Plots, Canvas, Charts

Here is the Javascript using jQuery that fetch and format the data to be processed by Flot.

 Javascript |  copy code |? 
01
$(document).ready(function() {  
02
 
03
    $.getJSON('w3s_getdata.php', function(json) {  
04
 
05
        var plot_data = new Array();  
06
        var plot_ticks = new Array();  
07
 
08
        for (var i in json) {  
09
            i = parseInt(i);  
10
            plot_data.push([i, json[i].visitors]);  
11
            plot_ticks.push([i+0.5, json[i].dates]);  
12
        }  
13
 
14
        $.plot($("#placeholder"),   
15
             [  
16
                {"data": [[0, 0]]},   
17
                {"data": [[0, 0]]},   
18
                {"data": [[0, 0]]},   
19
                {"data": [[0, 0]]},   
20
                {"data": [[0, 0]]},   
21
                 {  
22
                     label: "Last 20 days visits",  
23
                     bars: {"show": "true"},  
24
                     data: plot_data  
25
                 }  
26
             ],  
27
            {  
28
                 xaxis: {  
29
                   ticks: plot_ticks  
30
                }  
31
             }  
32
         );  
33
    });  
34
});  
35


Sample JSON data

 Javascript |  copy code |? 
01
[  
02
    {"dates":"24 feb","visitors":"5"},  
03
    {"dates":"25 feb","visitors":"21"},  
04
    {"dates":"26 feb","visitors":"14"},  
05
    {"dates":"27 feb","visitors":"45"},  
06
    {"dates":"28 feb","visitors":"20"},  
07
    {"dates":"29 feb","visitors":"18"},  
08
    {"dates":"01 mar","visitors":"9"},  
09
    {"dates":"02 mar","visitors":"7"},  
10
    {"dates":"03 mar","visitors":"42"},  
11
    {"dates":"04 mar","visitors":"17"},  
12
    {"dates":"05 mar","visitors":"15"},  
13
    {"dates":"06 mar","visitors":"9"},  
14
    {"dates":"07 mar","visitors":"15"},  
15
    {"dates":"08 mar","visitors":"3"},  
16
    {"dates":"09 mar","visitors":"3"},  
17
    {"dates":"10 mar","visitors":"19"},  
18
    {"dates":"11 mar","visitors":"15"},  
19
    {"dates":"12 mar","visitors":"11"}  
20
]  
21


PHP source code

Here is the little script I use to grab informations from my old fashioned eXTReMe tracking stats.

 Javascript |  copy code |? 
01
$a = strtolower(file_get_contents("http://extremetracking.com/open;unique?login=ncrovatt"));  
02
 
03
$pattern = '|.*  (\d+\s[a-z]{3},\s[a-z]{3})  .*|im';  
04
preg_match_all($pattern, $a, $matches);  
05
 
06
$pattern = '|.*  (\d+\s[a-z]{3}),\s[a-z]{3}  .*  
07
        <font face=arial size=2><b>  (\d+)  |im';  
08
 
09
foreach($matches[0] as $k => $v) {  
10
    preg_match_all($pattern, $v, $res);  
11
    $data[] = array('dates' => $res[1][0], 'visitors'=> $res[2][0]);  
12
}  
13
 
14
print_z(array2json($data));  
15
</b></font>

Demo: http://blog.shinylittlething.com/workshop/flot_intro/
Source: http://blog.shinylittlething.com/workshop/flot_intro/
tafbutton blue16 jQuery Flot, Plots, Canvas, Charts

Related Listings:

  1. jQuery + Flot = Plots, Canvas, Charts Flot is a pure Javascript plotting library for jQuery. It...
  2. Accessible Charts with Canvas and jQuery Script Data visualization in HTML has long been tricky to achieve....
  3. Flot – Plotting for jQuery Flot is a pure Javascript plotting library for jQuery. It...

DamnIT – JS error notification

Posted: 04 Sep 2009 08:19 AM PDT

DamnIT is a free service that emails you when a user encounters a JavaScript error in your webpages.

Setting up DamnIT with JavaScriptMVC

DamnIT is available as JavaScriptMVC’s error plugin. Using JavaScriptMVC’s error plugin lets you easily compress your application with the DamnIT library. To load DamnIT with JavaScriptMVC, all you have to do is include the error plugin.

Setup steps:

1. Obtain an application key
2. Include the error plugin

Obtaining an application key:

1. Sign up at damnit.jupiterit.com.
2. Click the link in the confirmation email.
3. Get your Application Key on the setup instructions page.

Including the error plugin:

Assuming you’ve correctly set up your JavaScriptMVC application, the following code includes the error plugin and defines your application key. Make sure you replace _APPLICATION_KEY_ with your application key.

APPLICATION_KEY=’_APPLICATION_KEY_’;
include.plugins(’error’);

Setting up the error plugin

The error plugin only reports errors in JavaScriptMVC’s production mode.
Setting up DamnIT as a standalone script

Setup steps:

1. Obtain an application key
2. Load the DamnIT script

Obtaining an application key:

1. Sign up at damnit.jupiterit.com.
2. Click the link in the confirmation email.
3. Get your Application Key on the setup instructions page.

Loading the DamnIT script:

Insert the following code into your html pages right before the ending body tag (). Replace _APPLICATION_KEY_ with your application key.

 Javascript |  copy code |? 
1
<script type='text/javascript'  
2
   src='https://damnit.jupiterit.com/damnit.js?_APPLICATION_KEY_'> 
3
</script>


Demo: http://javascriptmvc.googlecode.com/files/damnit_demo.html
Download: http://javascriptmvc.googlecode.com/files/damnit_demo.html
Source: https://damnit.jupiterit.com/home/documentation
tafbutton blue16 DamnIT   JS error notification

Related Listings:

  1. JavaScriptMVC – Include Include makes it simple to include and compress JavaScript files...
  2. jQuery Tabs Address – Deep linking plugin The jQuery Address plugin provides powerful deep linking capabilities and...
  3. Confirm inplace Script using jQuery This plugin displays a confirmation message in place before doing...

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.