فهرست منبع

move list helper classes into own files

Adam Shaw 8 سال پیش
والد
کامیت
7e1eab8706
4فایلهای تغییر یافته به همراه104 افزوده شده و 105 حذف شده
  1. 2 0
      src.json
  2. 21 0
      src/list/ListEventPointing.js
  3. 78 0
      src/list/ListEventRenderer.js
  4. 3 105
      src/list/ListView.js

+ 2 - 0
src.json

@@ -88,6 +88,8 @@
     "agenda/TimeGrid.js",
     "agenda/AgendaView.js",
     "agenda/config.js",
+    "list/ListEventRenderer.js",
+    "list/ListEventPointing.js",
     "list/ListView.js",
     "list/config.js",
     "outro.js"

+ 21 - 0
src/list/ListEventPointing.js

@@ -0,0 +1,21 @@
+
+var ListEventPointing = EventPointing.extend({
+
+    // for events with a url, the whole <tr> should be clickable,
+    // but it's impossible to wrap with an <a> tag. simulate this.
+    handleClick: function(seg, ev) {
+        var url;
+
+        EventPointing.prototype.handleClick.apply(this, arguments); // super. might prevent the default action
+
+        // not clicking on or within an <a> with an href
+        if (!$(ev.target).closest('a[href]').length) {
+            url = seg.footprint.eventDef.url;
+
+            if (url && !ev.isDefaultPrevented()) { // jsEvent not cancelled in handler
+                window.location.href = url; // simulate link click
+            }
+        }
+    }
+
+});

+ 78 - 0
src/list/ListEventRenderer.js

@@ -0,0 +1,78 @@
+
+var ListEventRenderer = EventRenderer.extend({
+
+    renderFgSegs: function(segs) {
+        if (!segs.length) {
+            this.component.renderEmptyMessage();
+        }
+        else {
+            this.component.renderSegList(segs);
+        }
+    },
+
+    // generates the HTML for a single event row
+    fgSegHtml: function(seg) {
+        var view = this.view;
+        var calendar = view.calendar;
+        var theme = calendar.theme;
+        var eventFootprint = seg.footprint;
+        var eventDef = eventFootprint.eventDef;
+        var componentFootprint = eventFootprint.componentFootprint;
+        var url = eventDef.url;
+        var classes = [ 'fc-list-item' ].concat(this.getClasses(eventDef));
+        var bgColor = this.getBgColor(eventDef);
+        var timeHtml;
+
+        if (componentFootprint.isAllDay) {
+            timeHtml = view.getAllDayHtml();
+        }
+        // if the event appears to span more than one day
+        else if (view.isMultiDayRange(componentFootprint.unzonedRange)) {
+            if (seg.isStart || seg.isEnd) { // outer segment that probably lasts part of the day
+                timeHtml = htmlEscape(this._getTimeText(
+                    calendar.msToMoment(seg.startMs),
+                    calendar.msToMoment(seg.endMs),
+                    componentFootprint.isAllDay
+                ));
+            }
+            else { // inner segment that lasts the whole day
+                timeHtml = view.getAllDayHtml();
+            }
+        }
+        else {
+            // Display the normal time text for the *event's* times
+            timeHtml = htmlEscape(this.getTimeText(eventFootprint));
+        }
+
+        if (url) {
+            classes.push('fc-has-url');
+        }
+
+        return '<tr class="' + classes.join(' ') + '">' +
+            (this.displayEventTime ?
+                '<td class="fc-list-item-time ' + theme.getClass('widgetContent') + '">' +
+                    (timeHtml || '') +
+                '</td>' :
+                '') +
+            '<td class="fc-list-item-marker ' + theme.getClass('widgetContent') + '">' +
+                '<span class="fc-event-dot"' +
+                (bgColor ?
+                    ' style="background-color:' + bgColor + '"' :
+                    '') +
+                '></span>' +
+            '</td>' +
+            '<td class="fc-list-item-title ' + theme.getClass('widgetContent') + '">' +
+                '<a' + (url ? ' href="' + htmlEscape(url) + '"' : '') + '>' +
+                    htmlEscape(eventDef.title || '') +
+                '</a>' +
+            '</td>' +
+        '</tr>';
+    },
+
+
+    // like "4:00am"
+    computeEventTimeFormat: function() {
+        return this.opt('mediumTimeFormat');
+    }
+
+});

+ 3 - 105
src/list/ListView.js

@@ -4,9 +4,10 @@ Responsible for the scroller, and forwarding event-related actions into the "gri
 */
 var ListView = FC.ListView = View.extend({
 
+	eventRendererClass: ListEventRenderer,
+	eventPointingClass: ListEventPointing,
+
 	segSelector: '.fc-list-item', // which elements accept event actions
-	//eventRendererClass is below
-	//eventPointingClass is below
 
 	scroller: null,
 	contentEl: null,
@@ -120,109 +121,6 @@ var ListView = FC.ListView = View.extend({
 	},
 
 
-	eventRendererClass: EventRenderer.extend({
-
-
-		renderFgSegs: function(segs) {
-			if (!segs.length) {
-				this.component.renderEmptyMessage();
-			}
-			else {
-				this.component.renderSegList(segs);
-			}
-		},
-
-
-		// generates the HTML for a single event row
-		fgSegHtml: function(seg) {
-			var view = this.view;
-			var calendar = view.calendar;
-			var theme = calendar.theme;
-			var eventFootprint = seg.footprint;
-			var eventDef = eventFootprint.eventDef;
-			var componentFootprint = eventFootprint.componentFootprint;
-			var url = eventDef.url;
-			var classes = [ 'fc-list-item' ].concat(this.getClasses(eventDef));
-			var bgColor = this.getBgColor(eventDef);
-			var timeHtml;
-
-			if (componentFootprint.isAllDay) {
-				timeHtml = view.getAllDayHtml();
-			}
-			// if the event appears to span more than one day
-			else if (view.isMultiDayRange(componentFootprint.unzonedRange)) {
-				if (seg.isStart || seg.isEnd) { // outer segment that probably lasts part of the day
-					timeHtml = htmlEscape(this._getTimeText(
-						calendar.msToMoment(seg.startMs),
-						calendar.msToMoment(seg.endMs),
-						componentFootprint.isAllDay
-					));
-				}
-				else { // inner segment that lasts the whole day
-					timeHtml = view.getAllDayHtml();
-				}
-			}
-			else {
-				// Display the normal time text for the *event's* times
-				timeHtml = htmlEscape(this.getTimeText(eventFootprint));
-			}
-
-			if (url) {
-				classes.push('fc-has-url');
-			}
-
-			return '<tr class="' + classes.join(' ') + '">' +
-				(this.displayEventTime ?
-					'<td class="fc-list-item-time ' + theme.getClass('widgetContent') + '">' +
-						(timeHtml || '') +
-					'</td>' :
-					'') +
-				'<td class="fc-list-item-marker ' + theme.getClass('widgetContent') + '">' +
-					'<span class="fc-event-dot"' +
-					(bgColor ?
-						' style="background-color:' + bgColor + '"' :
-						'') +
-					'></span>' +
-				'</td>' +
-				'<td class="fc-list-item-title ' + theme.getClass('widgetContent') + '">' +
-					'<a' + (url ? ' href="' + htmlEscape(url) + '"' : '') + '>' +
-						htmlEscape(eventDef.title || '') +
-					'</a>' +
-				'</td>' +
-			'</tr>';
-		},
-
-
-		// like "4:00am"
-		computeEventTimeFormat: function() {
-			return this.opt('mediumTimeFormat');
-		}
-
-	}),
-
-
-	eventPointingClass: EventPointing.extend({
-
-		// for events with a url, the whole <tr> should be clickable,
-		// but it's impossible to wrap with an <a> tag. simulate this.
-		handleClick: function(seg, ev) {
-			var url;
-
-			EventPointing.prototype.handleClick.apply(this, arguments); // super. might prevent the default action
-
-			// not clicking on or within an <a> with an href
-			if (!$(ev.target).closest('a[href]').length) {
-				url = seg.footprint.eventDef.url;
-
-				if (url && !ev.isDefaultPrevented()) { // jsEvent not cancelled in handler
-					window.location.href = url; // simulate link click
-				}
-			}
-		}
-
-	}),
-
-
 	renderEmptyMessage: function() {
 		this.contentEl.html(
 			'<div class="fc-list-empty-wrap2">' + // TODO: try less wraps