1/** 2 * Cargo traceMark 3 * Currently used for the team image blog 4 */ 5 6/** 7 * Only allow this to be added once, prevents memory errors 8 */ 9if (typeof (TraceMarklet) === "undefined") { 10 11 var TraceMarklet = { 12 13 /** 14 * Store some data 15 */ 16 Data : { 17 // Seperate the data that will be passed to Ajax 18 Ajax : { 19 "uid" : window.tracemark_id || 0, 20 "mid" : 0, 21 "collection" : $("tracemark_data").attr("collection"), 22 "type" : "add" 23 }, 24 "ajax_route" : "/dispatch/tracemark/trace", // What the ajax route is 25 26 "min_height" : 200, // Don't tracemark images below this size 27 "min_width" : 200, 28 "add_icon" : "â¶", // When adding a tracemark 29 "remove_icon" : "â", // When removing a tracemark 30 "dupe_icon" : "â", // Where a tracemark has already been added 31 "saved_icon" : "â", // Once done, show this 32 "start_icon" : "", // Left blank, it will be filled in later 33 34 "network_image_class" : "featured_img_parent", 35 }, 36 37 /** 38 * The selected element, deinfed later 39 */ 40 Element : { }, 41 42 /** 43 * Start the tracemarklet 44 */ 45 Init : function() { 46 // Setup the page 47 $("body").append('<div id="tracemark_container"><div id="tracemark_load" />'); 48 49 // Set what the start icon will be, based on what page we are on 50 this.Data.start_icon = this.Data.add_icon; 51 52 // When lacking a user ID, only tracemark within network 53 if (this.Data.Ajax.uid == 0) 54 this.Data.Ajax.collection = $("tracemark_data").attr("collection"); 55 56 this.IMG.Locate(); 57 58 }, // end Init 59 60 /** 61 * Adds the click state for each tracemark on the page 62 */ 63 HandleClick : function() { 64 // Send the image on click 65 $("a.tracemark_icon").on("click", function() { 66 // Update the AJAX data 67 TraceMarklet.Data.Ajax.type = TraceMarklet.ActionForIcon($(this).text()); 68 69 // Verify that we want to remove this 70 if(TraceMarklet.Data.Ajax.type == "remove") { 71 if( !confirm("Delete?") ) { 72 TraceMarklet.Unload(); 73 return false; 74 } 75 } 76 77 TraceMarklet.Data.Ajax.mid = $(this).attr("id"); 78 79 // Define the Element, hide the icon, and display the load spinner 80 TraceMarklet.Element = $(this); 81 $(this).text(""); 82 $("#tracemark_load").css({ 83 "display" : "block", 84 "left" : $(this).offset().left, 85 "top" : $(this).offset().top, 86 }); 87 88 // Make the AJAX call 89 TraceMarklet.Post(); 90 91 return false; 92 }); 93 }, 94 95 /** 96 * IconForIMG 97 * 98 * Handle the special case of showing a removal icon when viewing a network feature, 99 * otherwise return the icon as determined at Init(). 100 */ 101 IconForIMG : function(parent_class) { 102 // When in a network, the removal icon is shown based upon the parent class of the image 103 return this.Data.start_icon; 104 }, 105 106 /** 107 * ActionForIcon 108 * 109 * Discern the 'type' variable to pass via AJAX based upon the current icon. 110 */ 111 ActionForIcon : function(icon_text) { 112 if (icon_text == this.Data.add_icon) 113 return 'add'; 114 115 return 'remove'; 116 }, 117 118 /** 119 * Send this to AJAX 120 */ 121 Post : function() { 122 $.post( 123 TraceMarklet.Data.ajax_route, 124 TraceMarklet.Data.Ajax, 125 function(data, text_status) { TraceMarklet.Callback(data); } 126 ); 127 }, 128 129 /** 130 * Handles the return callback from AJAX 131 */ 132 Callback : function(data) { 133 var return_data = $.parseJSON(data); 134 135 // Reformat the icon 136 $("#tracemark_load").css("display", "none"); 137 138 // If there is an error 139 if (return_data.error == "mid_dupe") { 140 141 $(this.Element).html(this.Data.dupe_icon); 142 alert("This was already Tracemarked"); 143 144 } 145 // Project was already featured 146 else if(return_data.error == "pid_dupe") { 147 $(this.Element).html(this.Data.dupe_icon); 148 alert("Project has already been featured"); 149 150 } 151 // Not part of the network 152 else if (return_data.error == "not_in_network") { 153 this.Unload(); 154 alert("You're not a member of this network"); 155 156 } 157 // Not logged in 158 else if (return_data.error == "login") { 159 this.Unload(); 160 alert("You must be logged in"); 161 162 } 163 // If the image was saved 164 else { 165 166 $(this.Element).html(this.Data.saved_icon); 167 168 // Wait a second, then unload 169 setTimeout('TraceMarklet.Unload()', 2000); 170 } 171 172 }, 173 174 /** 175 * Get rid of this thing 176 */ 177 Unload : function() { 178 179 $("#tracemark_container").remove(); 180 181 } 182 183 }; 184 185 /** 186 * Tracemarklet class that deals with image handling 187 */ 188 /*! IMG */ 189 TraceMarklet.IMG = { 190 191 Data : { 192 193 }, 194 195 /** 196 * Find all of the potentially loggable images on the page 197 */ 198 Locate : function() { 199 200 // Loop through all of the images on the page 201 $("img").each(function() { 202 203 var height = $(this).height(), 204 parent_class = $(this).parent().attr("class"), 205 parent_id = $(this).parent().attr("id"), 206 width = $(this).width(); 207 208 // If the image is larger than 200px, has a Media ID 209 if ( 210 height > TraceMarklet.Data.min_height 211 && width > TraceMarklet.Data.min_width 212 && $(this).attr("data-mid") !== undefined 213 ) { 214 var img_src = $(this).attr("src"), 215 mid = $(this).attr("data-mid"), 216 element = mid, 217 pos_x = $(this).offset().left, 218 pos_y = $(this).offset().top; 219 220 // Create the icon 221 $("#tracemark_container").append('<a href="#" id="' + element + '" class="tracemark_icon">' + TraceMarklet.IconForIMG(parent_class) + '</a>'); 222 223 $("#" + element).css({ 224 "left" : pos_x, 225 "top" : pos_y 226 }) 227 228 } // end size check 229 230 }); // end image loop 231 232 // Add the click state to each found image 233 TraceMarklet.HandleClick(); 234 235 } // end Locate 236 237 }; // end FindIMGs 238 239 240} // end if == undefined 241 242 243/* 244 * Unload possible previous instances 245 * Fire the traceMarker 246 */ 247 248TraceMarklet.Unload(); 249TraceMarklet.Init(); 250 251 252/* 253 * On slideshow transition, update the position of the img reg tags 254 */ 255$(document).bind("slideshowTransitionFinish", function(e, nextSlide) { 256 TraceMarklet.IMG.Locate(); 257}); 258 259/* 260 * Event handling for designs 261 */ 262$(document).bind("projectLoadComplete", function() { TraceMarklet.Unload() }); 263$(document).bind("projectClose", function() { TraceMarklet.Unload() });
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.