PageSourceSearch

https://mariarendon.net/_jsapps/rail/rail.app.js

js mariarendon.net collected 2026-10-05 05:54:36 UTC 11,325 bytes, 507 lines download raw bytes

1/***************************************************************************
2 *
3 *	The Rail app is the controller of the right rail housing
4 *	following, tracemarks and other things
5 *
6 *	This is meant to be agnostic to Cargo 1.0 or 2.0
7 *	Uses Backbone and Handlebars
8 *
9 *	Assumes the Cargo namespace exists
10 *	Sets the Cargo.app namepsace if one does not exist
11 *
12 **************************************************************************/
13Cargo.app = window.Cargo.app || { };
14Cargo.app.Rail = { };
15
16/* Create the default objects */
17Cargo.app.Rail.Model 		= { };	// All models base
18Cargo.app.Rail.Collection	= { };	// All collections base
19Cargo.app.Rail.View  		= { };	// All views base
20Cargo.app.Rail.view  		= { };	// instanciated views
21Cargo.app.Rail.Events  		= { };	// All events base
22Cargo.app.Rail.Templates	= { };	// All templates (these are loaded on init)
23
24
25/***************************************************************************
26 *
27 *	Models
28 *
29 **************************************************************************/
30
31/**
32 *	This is the init and loads all models that are passed
33 *	Expects an array of models as name => data
34 *	name = "masterview_model"
35 *	Create the model name for this application like "MasterviewModel"
36 */
37Cargo.app.Rail.Model.LoadModels = function( models ) {
38	
39	_( models ).each(function( value, key ) {
40		var model_name = ucFirst(key.split("_")[0]) + ucFirst(key.split("_")[1]) + "";
41		
42		/* Create a new Backbone model based on the data coming in */		
43		Cargo.app.Rail.Model[model_name] = new Backbone.Model( value );
44
45	});
46};
47
48
49/***************************************************************************
50 *
51 *	Events
52 *
53 **************************************************************************/
54
55/* Init the events */
56Cargo.app.Rail.Events = _.extend({}, Backbone.Events);
57
58
59/**
60 *	An event for showing the following
61 *	This is triggered when the following icon is clicked
62 */
63Cargo.app.Rail.Events.on("show_rail_following", function() { 
64	
65	/* Make sure to destroy old versions */
66	Cargo.app.Rail.Events.trigger("following:destroy");
67	
68	/* Init a new version of this view */
69	Cargo.app.Rail.view.following = new Cargo.app.Rail.View.Following({ 
70		el : "#rail_following",
71		collection: Cargo.app.Rail.Model.FollowingModel 
72	});
73
74});
75
76
77/* 
78+ * Event for image drag start 
79+ * Init the tracemarks view
80+ */
81Cargo.app.Rail.Events.on("image_drag_start", function() { 
82  
83  /* Make sure to destroy old versions */
84  Cargo.app.Rail.Events.trigger("selections:destroy");
85
86  /* Init a new version of this view */
87  new Cargo.app.Rail.View.Selections({ 
88    el : "#rail_selections",
89    collection: Cargo.app.Rail.Model.SelectionsModel 
90  });
91
92});
93
94
95/***************************************************************************
96 *
97 *	Views
98 *
99 **************************************************************************/
100
101/**************************
102 *	Master
103 *************************/
104Cargo.app.Rail.View.Master = Backbone.View.extend({
105
106	initialize : function() {
107
108		var self = this;
109
110		// Set an event to listen for showing the rail
111		Cargo.app.Rail.Events.bind("rail:show", this.Show, this);
112
113		// Set an event to listen for hiding the rail
114		Cargo.app.Rail.Events.bind("rail:hide", this.Hide, this);
115
116		// IE check
117		if ( $.browser.msie ) {
118			$("#rail_wrapper").addClass("rail_ie");
119		}
120
121        new Cargo.app.Rail.View.Screen({ 
122            el : "#rail_screen"
123        });
124
125        if(Cargo.hasOwnProperty('Core')){
126        	Cargo.Core.ReplaceLoadingAnims.init();
127    	} else {
128    		Cargo.ReplaceLoadingAnims();
129    	}
130
131	},
132
133	events : {
134		
135	},
136
137	render : function() {
138
139	},
140
141	/**
142	 * Hide the rail and reset the data
143	 */
144	Show : function() {
145
146		if ( ! $.browser.msie ) {
147
148			_.delay(function() {
149				$("body, html").addClass("rail_active");
150		        $("#rail_wrapper").addClass("active");
151		    }, 1);
152
153		} else {
154
155			$("body, html").addClass("rail_active");
156		    $("#rail_wrapper").addClass("active");
157
158		}
159	},
160	
161	Hide : function() {
162		$("body, html").removeClass("rail_active");
163        $("#rail_wrapper").attr("class", "api");
164
165
166		// IE check
167		if ( $.browser.msie ) {
168			$("#rail_wrapper").addClass("rail_ie");
169		}
170
171		// Hide the follow popup
172		if( typeof Cargo.Follow != "undefined" ) {
173			Cargo.Follow.Hide();	
174		}
175		
176
177        // Trigger the rail hide event
178		_.delay(function() { Cargo.app.Rail.Events.trigger("following:hide") }, 300);
179	}
180
181});
182
183/**************************
184 *	Screen
185 *************************/
186Cargo.app.Rail.View.Screen = Backbone.View.extend({
187
188	initialize : function() {
189
190	},
191
192	events : {
193		"click"     : "clicked",
194		"mouseover" : "hovered"
195	},
196
197	render : function() {
198
199	},
200
201	clicked : function() {
202		Cargo.app.Rail.Events.trigger("rail:hide");
203	},
204
205	hovered : function() {
206		if ( !Cargo.Rail.Data.dragging && 
207			 !Cargo.Rail.Data.is_saving &&
208			 $("#rail_selections").is(":visible") 
209		) {
210		 	Cargo.app.Rail.Events.trigger("rail:hide");
211		}
212	}
213
214});
215
216
217/**************************
218 *	Following
219 *************************/
220Cargo.app.Rail.View.Following = Backbone.View.extend({
221
222	initialize : function() {
223		// Set the template
224		this.template = Cargo.app.Rail.Templates.following_tpl;
225
226		// Set an event to wait for the model to change
227		if(this.collection) {
228			this.collection.bind("reset", this.render, this);
229
230			// Show the rail
231			Cargo.app.Rail.Events.trigger("rail:show");
232
233			// Create an event for the destroy method
234			Cargo.app.Rail.Events.bind("following:destroy", this.destroy, this);
235
236			// Set an event to listen for hiding the rail
237			Cargo.app.Rail.Events.bind("following:hide", this.Hide, this);
238
239			this.render();
240		}
241	},
242
243
244	events: {
245		"click #rail_follow a" : "DoFollow"
246	},
247
248	render : function() {
249
250		/* Empty the container */
251		this.$el.empty();
252
253		var markup = Handlebars.compile( this.template )( this.collection );
254		this.$el.append( markup ).show();
255
256		// Active state
257		$("#rail_wrapper").addClass("following_active");
258
259		// Close rail when clicking name
260		$(".rail_name").click(function() {
261			Cargo.app.Rail.Events.trigger("rail:hide");
262			return false;
263		});
264
265		var self = this;
266		this.columns();
267
268		$(window).resize(function() { self.columns() });
269
270	},
271
272	columns : function() {
273
274        var width = $(this.$el).width() - 40;
275        var ratio = Math.floor((width / 120));
276        var percent = 100 / ratio;
277
278        if ( width < 181 ) {
279        	percent = 100;
280        }
281        
282        // $(".rail_module", this.$el).width(percent + "%");
283
284    },
285
286	/* Hide this */
287	Hide : function() {
288		this.$el.hide();
289	},
290
291	/**
292	 *  Destroy this view and unbind it's events
293	 */
294	destroy : function() {
295		this.undelegateEvents();
296   },
297
298   /*
299	 *	This does the actual follow / unfollow action
300	 */
301	DoFollow : function( e ) {
302		e.preventDefault();
303
304		var target 		= e.currentTarget;
305		var ftype		= $(target).attr("data-ftype");
306		var ucase_which = ucFirst(ftype);
307
308		if(typeof Cargo.Follow == "object") {
309			Cargo.Follow.ShowFollowWindow($(target));
310			
311		} else if(typeof Cargo.View.Following == "object") {
312			Cargo.View.Following.ShowFollowWindow($(target));
313		}
314
315	}
316
317});
318
319
320
321/**************************
322 *	Selections
323 *************************/
324Cargo.app.Rail.View.Selections = Backbone.View.extend({
325
326	last_id_drop : 0,
327
328	initialize : function() {
329		// Set the template
330		this.template = Cargo.app.Rail.Templates.selections_tpl;
331
332		// Set an event to wait for the model to change
333		this.collection.bind("reset", this.render, this);
334
335		// Show the rail
336		Cargo.app.Rail.Events.trigger("rail:show");
337
338		// Create an event for the destroy method
339		Cargo.app.Rail.Events.bind("selections:destroy", this.destroy, this);
340
341		// Set an event to listen for hiding the rail
342		Cargo.app.Rail.Events.bind("rail:hide", this.Hide, this);
343
344		this.render();
345	},
346
347
348	events: {
349		"mouseover" : "hovered",
350		"mouseout" : "hoverout"
351	},
352
353	hovered : function() {
354		Cargo.Rail.Data.is_on_screen = false;
355	},
356
357	hoverout : function() {
358		Cargo.Rail.Data.is_on_screen = true;
359	},
360
361	render : function() {
362		/* Empty the container */
363		this.$el.empty();
364
365		var markup = Handlebars.compile( this.template )( this.collection );
366		this.$el.append( markup ).show();
367
368		this.SetDropZone();
369
370		$("#rail_wrapper").addClass("selection_active");
371	},
372
373	SetDropZone : function() {
374	    var self = this;
375
376	    $("#rail_screen").droppable(
377            '*',
378            // Drag enter
379            function(e) { },
380            // Drag leave
381            function() { },
382            // Drop!
383            function(e) {
384            	Cargo.app.Rail.Events.trigger("rail:hide");
385            }
386		);
387
388		$("#selections_login").droppable(
389            '*',
390            // Drag enter
391            function(e) { },
392            // Drag leave
393            function() { },
394            // Drop!
395            function(e) {
396               Cargo.Rail.Data.dragging = false;
397            }
398		);
399
400	    $("#rail_droplet").droppable(
401            // Accepts
402            '*',
403            
404            // Drag enter
405            function(e) {
406              $(this).addClass("active");
407              Cargo.Rail.Data.is_on_screen = false;
408            },
409            
410            // Drag leave
411            function() {
412                $(this).removeClass("active");
413            },
414            
415            // Drop!
416            function(e) {
417                self.HandleImageDrop();
418            }
419
420        ); // end drop
421
422	  },
423
424	  HandleImageDrop : function() {
425	  	Cargo.Rail.Data.is_saving = true;
426
427	  	var id = this.collection.get("mid");
428	  	// don't allow for the image in the rail to be dropped again
429	  	if(this.last_id_drop == id) {
430	  		return;
431	  	}
432
433	  	this.last_id_drop = id;
434
435		$("#rail_save").addClass("active");
436		$(".rail_add").addClass("hidden");
437
438		$("#rail_preview").addClass("selection_dropped");
439		$("#rail_preview").attr("data-id", id);
440
441		/*
442		 * Rail Preview
443		 */
444		$("#rail_preview img:not(.rail_preview_spinner)").attr("src", this.collection.get("src"));
445		$("#rail_preview .rail_preview_spinner").css("top", ( $("#rail_preview img:not(.rail_preview_spinner)").height() / 2 ) + 40 + "px");
446
447		if( typeof Cargo.ReplaceLoadingAnims == "function") {
448			Cargo.ReplaceLoadingAnims();
449		} else {
450			Cargo.Core.ReplaceLoadingAnims.init();
451		}
452		
453		// Save the image
454		var cuid = "";
455
456		if(typeof Cargo.Helper == "undefined"){
457			cuid = Cargo.Config.GetCookieUid();
458		} else {
459			cuid = Cargo.Helper.GetUrl();
460		}
461
462		$.post("/dispatch/selections/selection", { mid : this.collection.get("mid"), cuid : cuid }, function(server_data) {
463			if(server_data.error) {
464				$(".rail_preview_spinner").hide();
465				alert(server_data.message);
466				Cargo.app.Rail.Events.trigger("rail:hide");
467
468			} else {
469
470				// Remove the fake spinner
471				_.delay(function() { 
472					$("#rail_preview[data-id=" + id + "]").addClass("selection_sent");
473				}, 600);
474
475				_.delay(function() {
476					if(Cargo.Rail.Data.is_on_screen) {
477						Cargo.app.Rail.Events.trigger("rail:hide");
478					}
479					Cargo.Rail.Data.is_saving = false; 
480				}, 1000);
481
482			}
483		});
484
485		// Tell the app the dragging has stopped, but give it a beat
486		_.delay(function() { Cargo.Rail.Data.dragging = false; }, 500);
487
488	  },
489
490	
491
492	/* Hide this */
493	Hide : function() {
494		this.last_id_drop = 0;
495		this.$el.hide();
496	},
497
498	/**
499	 *  Destroy this view and unbind it's events
500	 */
501	destroy : function() {
502		this.undelegateEvents();
503   }
504 
505
506});
507

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.