can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[ljcom] r10752: LJSUP-8956: New calendar widget for S2 s...

Committer: dpetrov
LJSUP-8956: New calendar widget for S2 style 'Minimalism'
U   trunk/bin/upgrading/s2layers/sup/layout.s2
U   trunk/htdocs/js/jquery/jquery.lj.inlineCalendar.js
Modified: trunk/bin/upgrading/s2layers/sup/layout.s2
===================================================================
--- trunk/bin/upgrading/s2layers/sup/layout.s2	2011-07-11 07:39:54 UTC (rev 10751)
+++ trunk/bin/upgrading/s2layers/sup/layout.s2	2011-07-11 07:53:38 UTC (rev 10752)
@@ -447,10 +447,14 @@
     var YearDay[] Days;
     var YearDay noday;
     var DateTime currentDate = journal_current_datetime();
+    var string table_class_attr = "";
+    var string calendar_date = $mon->month_format("%%yyyy%%-%%mm%%-01");
+    var string table_attr = "";
 
     $noday.day = 0;
     $noday.num_entries = 0;
     if ($*reg_firstdayofweek == "monday") {
+        $table_class_attr = " class=\"monday\"";
         $weekdays = [2,3,4,5,6,7,1];
         $pre_empty = $pre_empty==0?6:$pre_empty-1;
         $post_empty = $post_empty==6?0:$post_empty+1;
@@ -471,26 +475,27 @@
         }
     }
 
-if ($place == "sidebar") {
-    $month = $mon->month_format("%%mon%%");
-    """<p class="sbar-cal-nav">""";
-    """<span class="sbar-cal-nav-month"><i class="sbar-cal-nav-prev" title="$*text_month_prev"><i class="sbar-cal-nav-arr"></i></i><span class="sbar-cal-month"><a href="$mon.url" class="month">$month</a></span><i class="sbar-cal-nav-next disabled" title="$*text_month_next"><i class="sbar-cal-nav-arr"></i></i></span>""";
-    """<span class="sbar-cal-nav-year"><i class="sbar-cal-nav-prev" title="$*text_year_prev"><i class="sbar-cal-nav-arr"></i></i><span class="sbar-cal-year"><a href="$*base_url/$year/" class="year">$year</a></span><i class="sbar-cal-nav-next disabled" title="$*text_year_next"><i class="sbar-cal-nav-arr"></i></i></span>""";
-    """</p>""";
-}
+    if ($place == "sidebar") {
+        $month = $mon->month_format("%%mon%%");
+        """<p class="sbar-cal-nav">""";
+        """<span class="sbar-cal-nav-month"><i class="sbar-cal-nav-prev" title="$*text_month_prev"><i class="sbar-cal-nav-arr"></i></i><span class="sbar-cal-month"><a href="$mon.url" class="month">$month</a></span><i class="sbar-cal-nav-next disabled" title="$*text_month_next"><i class="sbar-cal-nav-arr"></i></i></span>""";
+        """<span class="sbar-cal-nav-year"><i class="sbar-cal-nav-prev" title="$*text_year_prev"><i class="sbar-cal-nav-arr"></i></i><span class="sbar-cal-year"><a href="$*base_url/$year/" class="year">$year</a></span><i class="sbar-cal-nav-next disabled" title="$*text_year_next"><i class="sbar-cal-nav-arr"></i></i></span>""";
+        """</p>""";
+    }
 
+    $table_attr = """$table_class_attr data-date="$calendar_date\"""";
 
-if($*active_theme == "x3") {
-    """<table cellspacing="0">""";
-} else {
-    """<table cellspacing="1">""";
-}
+    if($*active_theme == "x3") {
+        """<table cellspacing="0"$table_attr>""";
+    } else {
+        """<table cellspacing="1"$table_attr>""";
+    }
 
-if ($place == "page") {
-    """
-    <caption><a href="$mon.url" class="month">$month</a>&nbsp;<a href="$*base_url/$year/" class="year">$year</a></caption>
-    """;
-}
+    if ($place == "page") {
+        """
+        <caption><a href="$mon.url" class="month">$month</a>&nbsp;<a href="$*base_url/$year/" class="year">$year</a></caption>
+        """;
+    }
 
 """
     <thead>

Modified: trunk/htdocs/js/jquery/jquery.lj.inlineCalendar.js
===================================================================
--- trunk/htdocs/js/jquery/jquery.lj.inlineCalendar.js	2011-07-11 07:39:54 UTC (rev 10751)
+++ trunk/htdocs/js/jquery/jquery.lj.inlineCalendar.js	2011-07-11 07:53:38 UTC (rev 10752)
@@ -124,63 +124,6 @@
 				getDateNumber( iDate, true ) <= getDateNumber( range[1], true );
 	}
 
-	/**
-	 * Parse date from string according following format.
-	 * We suppose that every token takes place in the string only once.
-	 *
-	 * @param string str Date string.
-	 * @param string format Date format.
-	 *
-	 * @return Date|null Returns new Date object or null on parse failure.
-	 */
-	function parseDate( str, format ) {
-		var testStr = format,
-			positions = [ null ],
-			pos = 0, token,
-			regs = {
-				'%Y' : '(\\d{4})',
-				'%M' : '(\\d{2})',
-				'%D' : '(\\d{2})',
-				'%S' : '(\\d{13})'
-			};
-
-		while( ( pos = testStr.indexOf( '%', pos ) ) !== -1 ) {
-			token = testStr.substr( pos, 2 );
-			if( token in regs ) {
-				testStr = testStr.replace( token, regs[ token ] );
-				positions.push( token );
-			} else {
-				positions.push( null );
-			}
-		}
-
-		var r = new RegExp( testStr ),
-			arr = r.exec( str );
-
-		if( !arr ) {
-			return null;
-		} else {
-			var d = new Date();
-			for( var i = 1; i < arr.length; ++i ) {
-				if( positions[ i ] ) {
-					switch( positions[ i ] ) {
-						case '%D':
-							d.setDate( arr[ i ] );
-							break;
-						case '%M':
-							d.setMonth( parseInt( arr[ i ], 10 ) - 1 );
-							break;
-						case '%Y':
-							d.setFullYear( arr[ i ] );
-							break;
-					}
-				}
-			}
-
-			return d;
-		}
-	}
-
 	function View(nodes, styles, o)
 	{
 		this.initialize = function () {
@@ -226,7 +169,7 @@
 
 			while( toAdd-- > 0 ) {
 				//add missing rows if server has rendered not enough markup
-				$( rowStr ).appendTo( nodes.tbody );
+				$( rowStr ).hide().appendTo( nodes.tbody );
 			}
 			rowsCount = 6;
 			nodes.lastRow = jQuery( tbody.rows[ tbody.rows.length - 1 ] );
@@ -356,6 +299,11 @@
 
 			this._view = new (this._getView())( this._nodes, this.options.classNames, this.options );
 			this._view.initialize();
+
+			if( this._nodes.table.hasClass( "monday" ) ) {
+				this._setOption( "startAtSunday", false );
+			}
+
 			this._bindEvents();
 		},
 
@@ -369,6 +317,11 @@
 					this._nodes[ i ] = this._nodes.container.find( this.options.selectors[ i ] );
 				}
 			}
+
+			var displayedMonth;
+			if( displayedMonth = this._parseDate( this._nodes.table.attr( "data-date" ) ) ) {
+				this.options.displayedMonth = displayedMonth;
+			}
 		},
 
 		destroy: function() {
@@ -382,6 +335,7 @@
 				switcherMouseDown = function( item ) {
 					return function (ev) {
 						ev.preventDefault();
+						ev.stopPropagation();
 						var switcherStates = self._getSwitcherStates( self.options.currentDate );
 
 						if( switcherStates[item] ) {
@@ -526,6 +480,9 @@
 					this.options.endMonth = new Date( value );
 					this._invalidateDisplay();
 					break;
+				case 'startAtSunday':
+					this.options.startAtSunday = !!value;
+					break;
 			}
 		},
 
@@ -565,6 +522,63 @@
 			}
 
 			return str;
+		},
+
+		/**
+		 * Parse date from string according following format.
+		 * We suppose that every token takes place in the string only once.
+		 *
+		 * @param string str Date string.
+		 * @param string format Date format.
+		 *
+		 * @return Date|null Returns new Date object or null on parse failure.
+		 */
+		_parseDate: function( str, format ) {
+			var testStr = format || "%Y-%M-%D",
+				positions = [ null ],
+				pos = 0, token,
+				regs = {
+					'%Y' : '(\\d{4})',
+					'%M' : '(\\d{2})',
+					'%D' : '(\\d{2})',
+					'%S' : '(\\d{13})'
+				};
+
+			while( ( pos = testStr.indexOf( '%', pos ) ) !== -1 ) {
+				token = testStr.substr( pos, 2 );
+				if( token in regs ) {
+					testStr = testStr.replace( token, regs[ token ] );
+					positions.push( token );
+				} else {
+					positions.push( null );
+				}
+			}
+
+			var r = new RegExp( testStr ),
+				arr = r.exec( str );
+
+			if( !arr ) {
+				return null;
+			} else {
+				var d = new Date();
+				for( var i = 1; i < arr.length; ++i ) {
+					if( positions[ i ] ) {
+						switch( positions[ i ] ) {
+							case '%D':
+								d.setDate( arr[ i ] );
+								break;
+							case '%M':
+								d.setMonth( parseInt( arr[ i ], 10 ) - 1 );
+								break;
+							case '%Y':
+								d.setFullYear( arr[ i ] );
+								break;
+						}
+					}
+				}
+
+				return d;
+			}
 		}
 
 	};

Tags: can3p, js, ljcom, s2
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments