Skip to content

Commit

Permalink
update to 0.1.2
Browse files Browse the repository at this point in the history
* includes some whitespace cleanup
  • Loading branch information
tardate committed Jan 7, 2013
1 parent 57f2c6e commit 9bcfd03
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rdoc
@@ -1,3 +1,7 @@
== 0.1.2 released 2013-01-08

* Truncate details to avoid 414 error on Google Calendar site (thanks to woodchuck)

== 0.1.1 released 2011-03-20 == 0.1.1 released 2011-03-20


* Patch for javascript compatibility in older IE (thanks to nfarina) * Patch for javascript compatibility in older IE (thanks to nfarina)
Expand Down
2 changes: 1 addition & 1 deletion README.rdoc
@@ -1,4 +1,4 @@
= jQuery UI AddToCal widget v0.1.0 = jQuery UI AddToCal widget v0.1.2


AddToCal is a jQuery UI widget that provides "Add to Calendar" functionality for any website. AddToCal is a jQuery UI widget that provides "Add to Calendar" functionality for any website.
Given event details, it allows users to add the event to any supported calendar system. Given event details, it allows users to add the event to any supported calendar system.
Expand Down
52 changes: 26 additions & 26 deletions addtocal.htm
Expand Up @@ -7,7 +7,7 @@
<!-- hcalendar is only included for an hCalendar event markup example. It is NOT required for jquery.addtocal --> <!-- hcalendar is only included for an hCalendar event markup example. It is NOT required for jquery.addtocal -->
<link rel="profile" href="http://microformats.org/profile/hcalendar"> <link rel="profile" href="http://microformats.org/profile/hcalendar">
<style type='text/css'> <style type='text/css'>

/* styles here are purely for the purpose of the demo and are not essential for addtocal functionality */ /* styles here are purely for the purpose of the demo and are not essential for addtocal functionality */
body { body {
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif; font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
Expand Down Expand Up @@ -38,7 +38,7 @@
} }
.addtocal .description { .addtocal .description {
} }

</style> </style>


<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script> <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script>
Expand All @@ -49,29 +49,29 @@


<script type='text/javascript'> <script type='text/javascript'>
$(document).ready(function() { $(document).ready(function() {

$('.addtocal').AddToCal({ $('.addtocal').AddToCal({
/* ical and vcal require an ics or vcs file to be served. /* ical and vcal require an ics or vcs file to be served.
* Since we don't have a server for this demo, these features are disabled. * Since we don't have a server for this demo, these features are disabled.
* As a result the 30boxes, iCal and vCalendar menu links will not appear * As a result the 30boxes, iCal and vCalendar menu links will not appear
*/ */
icalEnabled:false, icalEnabled:false,
vcalEnabled:false, vcalEnabled:false,

/* getEventDetails is the most critical function to provide. /* getEventDetails is the most critical function to provide.
* It is called when a user selects a calendar to add an event to. * It is called when a user selects a calendar to add an event to.
* The element parameter is the jQuery object for the event invoked. * The element parameter is the jQuery object for the event invoked.
* You must return an object packed with the relevant event details. * You must return an object packed with the relevant event details.
* How you determine the event attributes will depend on your page. * How you determine the event attributes will depend on your page.
* The example below illustrates how to handle two formats of event markup. * The example below illustrates how to handle two formats of event markup.
*/ */
getEventDetails: function( element ) { getEventDetails: function( element ) {
var var
dtstart_element = element.find('.dtstart'), start, dtstart_element = element.find('.dtstart'), start,
dtend_element = element.find('.dtend'), end, dtend_element = element.find('.dtend'), end,
title_element = element.find('.summary'), title, title_element = element.find('.summary'), title,
details_element = element.find('.description'), details; details_element = element.find('.description'), details;

// in this demo, we attempt to get hCalendar attributes or otherwise just dummy the values // in this demo, we attempt to get hCalendar attributes or otherwise just dummy the values
start = dtstart_element.length ? dtstart_element.attr('title') : new Date(); start = dtstart_element.length ? dtstart_element.attr('title') : new Date();
if(dtend_element.length) { if(dtend_element.length) {
Expand All @@ -82,46 +82,46 @@
} }
title = title_element.length ? title_element.html() : element.attr('id'); title = title_element.length ? title_element.html() : element.attr('id');
details = details_element.length ? details_element.html() : element.html(); details = details_element.length ? details_element.html() : element.html();

// return the required event structure // return the required event structure
return { return {
webcalurl: null, webcalurl: null,
icalurl: null, icalurl: null,
vcalurl: null, vcalurl: null,
start: start, start: start,
end: end, end: end,
title: title, title: title,
details: details, details: details,
location: null, location: null,
url: null url: null
}; };
}, },
}); });

}); });
</script> </script>
</head> </head>
<body> <body>
<h1>jQuery UI AddToCal Widget Demo</h1> <h1>jQuery UI AddToCal Widget Demo</h1>
<p class="description">This demonstrates the basic add-to-calendar function. <p class="description">This demonstrates the basic add-to-calendar function.
For more information and source files, see the project's <a href="http://github.com/tardate/jquery.addtocalendar">github repository</a>.</p> For more information and source files, see the project's <a href="http://github.com/tardate/jquery.addtocalendar">github repository</a>.</p>


<div class="calendar-examples"> <div class="calendar-examples">

<div id='event-1' class='addtocal'>Basic event holder (click me)</div> <div id='event-1' class='addtocal'>Basic event holder (click me)</div>

<div id='event-2' class='addtocal vevent'> <div id='event-2' class='addtocal vevent'>
<div class="summary">hCalendar annotated event</div> <div class="summary">hCalendar annotated event</div>
<span class="dtstart date" title="20100908T070000Z">8th Aug 2010</span> <span class="dtstart date" title="20100908T070000Z">8th Aug 2010</span>
<span class="dtend date" title="20100908T080000Z">7-8am UTC</span> <span class="dtend date" title="20100908T080000Z">7-8am UTC</span>
<div class="description"> <div class="description">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed quam sem, tincidunt sit amet blandit vitae, vehicula sit amet sem. Sed quam sem, tincidunt sit amet blandit vitae, vehicula sit amet sem.
Quisque aliquam commodo lorem vel facilisis. (click me) Quisque aliquam commodo lorem vel facilisis. (click me)
</div> </div>
</div> </div>

</div> </div>

</body> </body>
</html> </html>
56 changes: 28 additions & 28 deletions jquery.addtocal.js
@@ -1,5 +1,5 @@
/* /*
* jQuery.addtocal v0.1.1 * jQuery.addtocal v0.1.2
* http://github.com/tardate/jquery.addtocalendar * http://github.com/tardate/jquery.addtocalendar
* *
* Copyright (c) 2010 Paul GALLAGHER http://tardate.com * Copyright (c) 2010 Paul GALLAGHER http://tardate.com
Expand All @@ -9,11 +9,11 @@
*/ */


(function($) { (function($) {

$.widget("tardate.AddToCal", $.widget("tardate.AddToCal",
{ {
options: { options: {

/* /*
* calendars is a collection of all the supported calendars and the method for formating * calendars is a collection of all the supported calendars and the method for formating
* the calendar link in each case. If you want to use a calendar system not supported here, you can * the calendar link in each case. If you want to use a calendar system not supported here, you can
Expand Down Expand Up @@ -71,12 +71,12 @@
return ( eventDetails.vcalurl ? eventDetails.vcalurl : null ); return ( eventDetails.vcalurl ? eventDetails.vcalurl : null );
} } } }
], ],

/* icalEnabled: set if iCal links are to be supported (requires you to provide an iCal format resource) */ /* icalEnabled: set if iCal links are to be supported (requires you to provide an iCal format resource) */
icalEnabled: true, icalEnabled: true,
/* vcalEnabled: set if vCalendar links are to be supported (requires you to provide an vCalendar format resource) */ /* vcalEnabled: set if vCalendar links are to be supported (requires you to provide an vCalendar format resource) */
vcalEnabled: true, vcalEnabled: true,

/* getEventDetails is the most critical function to provide. /* getEventDetails is the most critical function to provide.
* It is called when a user selects a calendar to add an event to. * It is called when a user selects a calendar to add an event to.
* The element parameter is the jQuery object for the event invoked. * The element parameter is the jQuery object for the event invoked.
Expand All @@ -94,8 +94,8 @@
title: null, details: null, title: null, details: null,
location: null, url: null}; location: null, url: null};
}, },


/* /*
* sanitizeEventDetails cleans up and normalises the event details provided by getEventDetails * sanitizeEventDetails cleans up and normalises the event details provided by getEventDetails
*/ */
Expand All @@ -117,7 +117,7 @@
eventDetails.url = ( eventDetails.url ? encodeURIComponent( eventDetails.url ) : '' ); eventDetails.url = ( eventDetails.url ? encodeURIComponent( eventDetails.url ) : '' );
return eventDetails; return eventDetails;
}, },

/* records the currently selected calendar service */ /* records the currently selected calendar service */
selectedCalendarTarget: null, selectedCalendarTarget: null,
/* positioning of the addtocal widget */ /* positioning of the addtocal widget */
Expand All @@ -127,7 +127,7 @@
at: "left bottom", at: "left bottom",
collision: "none" collision: "none"
}, },

/* main method called on selection of calendar service */ /* main method called on selection of calendar service */
select: function(event, ui) { select: function(event, ui) {
var eventDetails = ui.sanitizeEventDetails( ui.getEventDetails($(this)) ); var eventDetails = ui.sanitizeEventDetails( ui.getEventDetails($(this)) );
Expand All @@ -138,9 +138,9 @@
if(link) window.open(link); if(link) window.open(link);
} }
}, },

source:[], source:[],

_create: function() { _create: function() {
var self = this, var self = this,
doc = this.element[ 0 ].ownerDocument; doc = this.element[ 0 ].ownerDocument;
Expand All @@ -160,15 +160,15 @@
selected: function( event, ui ) { selected: function( event, ui ) {
var item = ui.item.data( "item.addtocal" ), var item = ui.item.data( "item.addtocal" ),
previous = self.previous; previous = self.previous;

// only trigger when focus was lost (click on menu) // only trigger when focus was lost (click on menu)
if ( self.element[0] !== doc.activeElement ) { if ( self.element[0] !== doc.activeElement ) {
self.element.focus(); self.element.focus();
self.previous = previous; self.previous = previous;
} }
self.options.selectedCalendarTarget = item.value; self.options.selectedCalendarTarget = item.value;
self._trigger( "select", event, self.options ); self._trigger( "select", event, self.options );

self.close( event ); self.close( event );
self.selectedItem = item; self.selectedItem = item;
} }
Expand All @@ -177,38 +177,38 @@
.css({ top: 0, left: 0 }) .css({ top: 0, left: 0 })
.hide() .hide()
.data( "menu" ); .data( "menu" );

if ( $.fn.bgiframe ) { if ( $.fn.bgiframe ) {
this.menu.element.bgiframe(); this.menu.element.bgiframe();
} }

//Close the popup if click elsewhere in the window //Close the popup if click elsewhere in the window
$(document).bind("click", function(event, ui) { self.close( event ); }); $(document).bind("click", function(event, ui) { self.close( event ); });

}, },

destroy: function() { destroy: function() {
this.element this.element
.removeClass( "ui-addtocal" ); .removeClass( "ui-addtocal" );
this.menu.element.remove(); this.menu.element.remove();
$.Widget.prototype.destroy.call( this ); $.Widget.prototype.destroy.call( this );
}, },

_setOption: function( key, value ) { _setOption: function( key, value ) {
$.Widget.prototype._setOption.apply( this, arguments ); $.Widget.prototype._setOption.apply( this, arguments );
if ( key === "appendTo" ) { if ( key === "appendTo" ) {
this.menu.element.appendTo( $( value || "body", this.element[0].ownerDocument )[0] ) this.menu.element.appendTo( $( value || "body", this.element[0].ownerDocument )[0] )
} }
}, },

_initSource: function() { _initSource: function() {
var self = this; var self = this;
self.source=[]; self.source=[];
$.each( this.options.calendars, function(index, value) { $.each( this.options.calendars, function(index, value) {
if(value.enabled(self)) self.source.push( {value: value.value, label: value.label } ); if(value.enabled(self)) self.source.push( {value: value.value, label: value.label } );
}); });
}, },

toggleMenu: function( event ) { toggleMenu: function( event ) {
var content = this.source; var content = this.source;
if ( content.length && ! ( this.menu.element.is(":visible") ) ) { if ( content.length && ! ( this.menu.element.is(":visible") ) ) {
Expand All @@ -220,7 +220,7 @@
this.close(); this.close();
} }
}, },

close: function( event ) { close: function( event ) {
clearTimeout( this.closing ); clearTimeout( this.closing );
if ( this.menu.element.is(":visible") ) { if ( this.menu.element.is(":visible") ) {
Expand All @@ -229,7 +229,7 @@
this.menu.deactivate(); this.menu.deactivate();
} }
}, },

_normalize: function( items ) { _normalize: function( items ) {
// assume all items have the right format when the first item is complete // assume all items have the right format when the first item is complete
if ( items.length && items[0].label && items[0].value ) { if ( items.length && items[0].label && items[0].value ) {
Expand All @@ -248,7 +248,7 @@
}, item ); }, item );
}); });
}, },

_suggest: function( items ) { _suggest: function( items ) {
var ul = this.menu.element var ul = this.menu.element
.empty() .empty()
Expand All @@ -262,30 +262,30 @@
this.menu.element.show().position( $.extend({ this.menu.element.show().position( $.extend({
of: this.element of: this.element
}, this.options.position )); }, this.options.position ));

menuWidth = ul.width( "" ).outerWidth(); menuWidth = ul.width( "" ).outerWidth();
textWidth = this.element.outerWidth(); textWidth = this.element.outerWidth();
ul.outerWidth( Math.max( menuWidth, textWidth ) ); ul.outerWidth( Math.max( menuWidth, textWidth ) );
}, },

_renderMenu: function( ul, items ) { _renderMenu: function( ul, items ) {
var self = this; var self = this;
$.each( items, function( index, item ) { $.each( items, function( index, item ) {
self._renderItem( ul, item ); self._renderItem( ul, item );
}); });
}, },

_renderItem: function( ul, item) { _renderItem: function( ul, item) {
return $( "<li></li>" ) return $( "<li></li>" )
.data( "item.addtocal", item ) .data( "item.addtocal", item )
.append( $( "<a></a>" ).text( item.label ) ) .append( $( "<a></a>" ).text( item.label ) )
.appendTo( ul ); .appendTo( ul );
}, },

widget: function() { widget: function() {
return this.menu.element; return this.menu.element;
} }

}); });


}(jQuery)); }(jQuery));
Expand Down

0 comments on commit 9bcfd03

Please sign in to comment.