<commit_before>
/**
 * [CiiDashboard description]
 * @type {Object}
 */
var CiiDashboard = {

	// The javascript endpoint
	endPoint : $("#dashboard-endpoint").attr("value"),

	Content : {

		// Function for handling perspective changes
		bindPerspectiveChange : function() {
			$("#perspective").click(function(e) {
	            $.post(CiiDashboard.endPoint + "/content/index/perspective/" + CiiDashboard.Content.nextPerspective(), function() { 
	                window.location.reload();
	            });
	        });
		},

		// The current perspective
		currentPerspective : $("#currentPerspective").attr("value"),

		// What the next perspective should be
		nextPerspective : function() {
			return CiiDashboard.Content.currentPerspective == 1 ? 2 : 1
		},

		load : function() {},

		// Loaded on /content/index
		loadIndex: function() {

			// Bind the perspective
			CiiDashboard.Content.bindPerspectiveChange();

			// And apply the appropriate data for that perspective
			if (CiiDashboard.Content.currentPerspective == 1)
				CiiDashboard.Content.loadFuturePerspetive();
			else
				CiiDashboard.Content.loadOldPerspective();
		},

		// Loads content necessary for the Future Dashboard Perspective
		loadFuturePerspetive : function() {
			CiiDashboard.Content.futurePerspective.marked();
			CiiDashboard.Content.futurePerspective.bindPostClick();
			$(".nano").nanoScroller()
		},

		/**
		 * All functionallity related to the _future_ perspective is held here
		 * All methods and objects
		 */
		futurePerspective : {

			contentPane : null,

			// BeforeAjaxUpdate for ContentListView::beforeAjaxUpdate
			beforeAjaxUpdate : function() {
				previewPane = $("#preview .content");
	    		scrollTop = $("#preview .content").scrollTop();
	    		CiiDashboard.Content.futurePerspective.contentPane = $(".preview").html();
			},

			/**
			 * When a given post is clicked, the active class from all other items should be removed
			 * and that post should be loaded in the preview pane
			 */
			bindPostClick : function() {
				$(".post").click(function() { 
					if ($(this).hasClass("post-header"))
						return;
					
					$(".post").removeClass("active");
					$(this).addClass("active"); 
					var id = $(this).attr("data-attr-id");

					var url = CiiDashboard.endPoint + "/content/index/id/" + id;
					
					$.get(url, function(data, textStatus, jqXHR) {
						CiiDashboard.Content.futurePerspective.contentPane = $($.parseHTML(data)).find(".preview").html();
						$(".preview").remove();
						$(".posts").after("<div class=\"preview nano\" id=\"preview\"></div>");
						$(".preview").html(CiiDashboard.Content.futurePerspective.contentPane).removeClass("has-scrollbar");
						$("#md-output").html(marked($("#markdown").val()));
						$("#preview.nano").nanoScroller({ OSNativeScrolling: true});

						CiiDashboard.Content.futurePerspective.delete();
						CiiDashboard.Content.futurePerspective.bindCommentBehavior();
					});
				});
			},

			bindCommentBehavior : function() {
				$(".preview-header .icon-comment").click(function() {
					$(".preview-data").slideToggle(function() {
						$(".preview-image").fadeToggle();
						var display = true;
						$("#comments").fadeToggle();
						
						if ($("#comments").is(":visible")) {
							$("#comments").remove();
							setTimeout(function() {
									$("#preview.nano").nanoScroller({ destroy: true });
									$("#preview.nano").nanoScroller({ OSNativeScrolling: true}); 
									$("#preview .content").animate({
										scrollTop : 0
									}, 0);
								}, 500);
							return;
						}

						$.post(CiiDashboard.endPoint + "/content/getComments/id/" + $("#item-id").text(), function(data) {
							$(".preview-data").after("<div id='comments'></div>");
							$("#comments").html(data).fadeIn(function() {
								setTimeout(function() {
									$("#preview.nano").nanoScroller({ destroy: true });
									$("#preview.nano").nanoScroller({ OSNativeScrolling: true}); 
									$("#preview .content").animate({
										scrollTop : 0
									}, 0);
								}, 500);
							});

							// Rounded Image 
							$(".rounded-img").load(function() {
							    $(this).wrap(function(){
							      return '<span class="' + $(this).attr('class') + '" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
							    });
							    $(this).css("opacity","0");
							});
						});
					});
				})
			},

			/**
			 * Loads appropriate comment data
			 **/
			loadComment : function(id) {
				$(".reply-" + id).click(function() {
					$(".comment-form-" + id).slideToggle(200);
				});
			},

			// AfterAjaxUpdate for ContentL:istview::afterAjaxUpdate
			afterAjaxUpdate : function() {

				// Change perspective
				CiiDashboard.Content.bindPerspectiveChange();

				// NanoScroller for main div
		    	$("#posts.nano").nanoScroller({ iOSNativeScrolling: true }); 

		    	// Timeago
		    	$(".timeago").timeago(); 

		    	// Post Click Behavior
		    	CiiDashboard.Content.futurePerspective.bindPostClick(); 

		    	// Reset Preview Pane
		    	$(".preview").remove();
				$(".posts").after("<div class=\"preview nano\" id=\"preview\"></div>");
				$(".preview").html(CiiDashboard.Content.futurePerspective.contentPane).removeClass("has-scrollbar");
				$("#preview.nano").nanoScroller({ OSNativeScrolling: true}); 
				$("#preview .content").animate({
					scrollTop : scrollTop
				}, 0);

				CiiDashboard.Content.futurePerspective.delete();
			},

			// Allows content to be deleted without page refresh
			delete : function() {
				$(".icon-trash").click(function(e) {
					e.preventDefault();
					confirm = confirm("Are you sure you want to delete this item?");
					if (confirm==true)
					{
						$.post($(this).attr("href"), function() {
							CiiDashboard.Content.futurePerspective.contentPane = null;
							$(".preview").html("<div class=\"content\"></div>");
							$.fn.yiiListView.update('ajaxListView');
						});
					}
					delete confirm;
					return false;
				});
			},

			// Bind the marked.js behavior. This should be universal across the board, so see CiiDashboard.Content.Save.marked()
			marked : function() {
				return CiiDashboard.Content.Save.marked();
			}

		},

		// Loads the necessary scripts for the old perspective
		loadOldPerspective : function() {},

		/**
		 * All functionality related to the older perspective is held here
		 * all objects and methods
		 */
		oldPerspective : {

			// Bulk action control binding
			bulkActionClick : function() {
				 $.post(CiiDashboard.endPoint + "/content/deleteMany", values, function(data) {
                    values.each(function() {
                        $(this).parent().parent().remove();
                    });
                });
			}

		},

		// The scripts that are loaded on /content/save
		loadSave : function() {
			CiiDashboard.Content.Save.tags();
			CiiDashboard.Content.Save.datePicker();
			CiiDashboard.Content.Save.bindFlipEvent();
			CiiDashboard.Content.Save.bindPreviewEditor();
		},

		/**
		 * All functionality related to saving and preview data is stored here
		 */
		Save : {

			/**
			 * Binds promoted Dropzone functionality for promoted images
			 */
			bindPromotedDz : function() {
				$(".icon-camera").click(function() {
					$("#promotedDz").toggle();
				});

				var dz = new Dropzone("#promotedDz", {
						url : CiiDashboard.endPoint + "/content/upload/id/" + $("#Content_id").val() + "/promote/1",
						dictDefaultMessage : "Drop files here to upload promoted image - or click",
						success : function(data) {
							var json = $.parseJSON(data.xhr.response);
							$(".preview-image").attr("src", json.filepath);
							$(".icon-camera").click();
							$("#promotedDz").remove();
							$(".editor .content").prepend($("<div id='promotedDz' class='dropzone'></div>").hide());
							CiiDashboard.Content.Save.bindPromotedDz();

							$(".icon-camera").unbind("click").click(function() {
								$("#promotedDz").toggle();
							});
						}
					});
			},

			/**
			 * Provides a delete confirmation box for content
			 */
			bindDelete : function() {
				$(".icon-trash").click(function() {
					confirm = confirm("Are you sure you want to delete this item?");
					if (confirm==true)
						window.location = CiiDashboard.endPoint + "/content/delete/id/" + $("#Content_id").val();

					delete confirm;
				})
			},

			// Binds the flip event for the preview => settings pane
			bindFlipEvent : function() {
			 	$(".show-settings").click(function() {
				 	$(".flipbox").flippy({
				 		color_target : "#FFF",
					    duration: "500",
					    verso: $(".settings"),
					    onStart : function() {
					    	$(".nano").nanoScroller({ destroy: true });
					    	$(".nano").removeClass("has-scrollbar");
					    },
					    onFinish : function() {
					    	$(".show-settings").hide();
					    	$(".show-preview").show();
					    	$(".settings").show();
					    	$(".nano").nanoScroller({ flash : true});
					    	CiiDashboard.Content.Save.bindFlipEvent();
					    },
					    onReverseStart : function() {
					    	$(".body-content").after($(".settings"));
					    	$(".nano").nanoScroller({ destroy: true });
					    	$(".nano").removeClass("has-scrollbar");
					    },
					    onReverseFinish : function() {
					    	$(".settings").hide();
					    	$(".show-preview").hide();
					    	$(".show-settings").show();
					    	$(".nano").nanoScroller({ flash : true});
					    	CiiDashboard.Content.Save.bindFlipEvent();
					    }
					 });
				 });

		 		$(".show-preview").click(function() {
			 		$(".flipbox").flippyReverse();
			 	});
			},

			/**
			 * This is the majority of the preview functionality.
			 *
			 * The Preview editor ties into serveral components, namely marked.js and dropzone.js.
			 *
			 * marked.js allows the content to be rendered in near real time with syntax highlighting from highlight.js. 
			 * The use of the "{image}" keyword will instantiate a unique and persistent dropzsone.js instance which will 
			 * be held until an image is dropped in the dropzone.
			 * 
			 * Once the image is uplaoded, it will replace the corresponding "{image}" tage in the markdown editor with
			 * either a markdown syntax image tag ![]() or a <img> tag, depending upon the editor preferences set by the administrator
			 *
			 * There's a WHOLE bunch of complex logix nested into this, that probably could be optimized. It's pretty ugly, but it works magnificently
			 */
			bindPreviewEditor : function() {

				CiiDashboard.Content.Save.bindPromotedDz();
				CiiDashboard.Content.Save.bindDelete();

				$("#Content_content").bind("input propertychange change", function(event) {

					if(typeof(Storage)!=="undefined")
						localStorage.setItem("content-" + $("#Content_id").val(), $(this).val());
					
					CiiDashboard.Content.Save.marked();

					var markdown = $("<div class=\"md-preview\">" + marked($(this).val()).replace(/{image}/g, "<div class=\"dropzone\"></div>") + "</div>");

					var i = 0;

					$(".preview div.dropzone").each(function() {
						$(markdown).find("div.dropzone:eq(" + i + ")").replaceWith($(this));
						i++;
					});	

					$(".preview").html(markdown);
					$(".nano").nanoScroller();

					$("div.dropzone").each(function() {
						if (!$(this).hasClass("dz-clickable"))
		 				{
		 					// Make sure we do not have a hash collision
		 					var hash = Math.random().toString(36).substring(7);

		 					while ($(".dropzone-" + hash).length > 0)
		 						hash = Math.random().toString(36).substring(15);

							$(this).addClass("dropzone-" + hash);
							var dz = new Dropzone(".preview div.dropzone-" + hash, {
								url : CiiDashboard.endPoint + "/content/upload/id/" + $("#Content_id").val(),
								dictDefaultMessage : "Drop files here to upload - or click",
								success : function(data) {
									var response = $.parseJSON(data.xhr.response);
									if (response.success == true)
									{
										var instance = 0;

										var self = $(this);
										var classEl = "";

										var classes = $(this)[0].element.className.split(" ");
										$(classes).each(function() { 
									        var classElement = this + "";
									        if (classElement != "dropzone" && classElement != "dz-clickable" && classElement != "dz-started")
									        	classEl = classElement
									    });

										// Iterate through all the dropzone objects on the page until this one is reached
										var i = 0;
										$(".preview div.dropzone").each(function() {
											if ($(this).hasClass(classEl))
												return false;
											i++;
										});

										var index = CiiDashboard.Content.Save.GetSubstringIndex($("#Content_content").val(), "{image}", i + 1);
										if (index == '-1')
											index = 0;

										// Remove the uploader
										$("." + classEl).remove();

										// Append the text to the item at that index
										var md = $("#Content_content").val();

										// Insert either Markdown or an image tag depending upon the user preference
										if ($(".preferMarkdown").val() == 1)
											md = CiiDashboard.Content.Save.splice(md, index, 7, "![" + response.filename + "](" + response.filepath +")");
										else
										{
											var text = $(".redactor_editor").html();
											md = CiiDashboard.Content.Save.splice(md, index, 7, "<img src=\"" + response.filepath +"\" />");
											var index2 = CiiDashboard.Content.Save.GetSubstringIndex($(".redactor_editor").html(), "{image}", i + 1);
											if (index2 == -1)
												index2 = CiiDashboard.Content.Save.GetSubstringIndex($(".redactor_editor").html(), "{image}", i);
											text = CiiDashboard.Content.Save.splice(text, index2, 7, "<img src=\"" + response.filepath +"\" />");
											$(".redactor_editor").html(text);
										}

										// Then modify the markdown
										$("#Content_content").val(md).change();

										// Then change the redactor view if it exists<commit_msg>Path fix issue<commit_after>
/**
 * [CiiDashboard description]
 * @type {Object}
 */
var CiiDashboard = {

	// The javascript endpoint
	endPoint : $("#dashboard-endpoint").attr("value"),

	Content : {

		// Function for handling perspective changes
		bindPerspectiveChange : function() {
			$("#perspective").click(function(e) {
	            $.post(CiiDashboard.endPoint + "/content/index/perspective/" + CiiDashboard.Content.nextPerspective(), function() { 
	                window.location.reload();
	            });
	        });
		},

		// The current perspective
		currentPerspective : $("#currentPerspective").attr("value"),

		// What the next perspective should be
		nextPerspective : function() {
			return CiiDashboard.Content.currentPerspective == 1 ? 2 : 1
		},

		load : function() {},

		// Loaded on /content/index
		loadIndex: function() {

			// Bind the perspective
			CiiDashboard.Content.bindPerspectiveChange();

			// And apply the appropriate data for that perspective
			if (CiiDashboard.Content.currentPerspective == 1)
				CiiDashboard.Content.loadFuturePerspetive();
			else
				CiiDashboard.Content.loadOldPerspective();
		},

		// Loads content necessary for the Future Dashboard Perspective
		loadFuturePerspetive : function() {
			CiiDashboard.Content.futurePerspective.marked();
			CiiDashboard.Content.futurePerspective.bindPostClick();
			$(".nano").nanoScroller()
		},

		/**
		 * All functionallity related to the _future_ perspective is held here
		 * All methods and objects
		 */
		futurePerspective : {

			contentPane : null,

			// BeforeAjaxUpdate for ContentListView::beforeAjaxUpdate
			beforeAjaxUpdate : function() {
				previewPane = $("#preview .content");
	    		scrollTop = $("#preview .content").scrollTop();
	    		CiiDashboard.Content.futurePerspective.contentPane = $(".preview").html();
			},

			/**
			 * When a given post is clicked, the active class from all other items should be removed
			 * and that post should be loaded in the preview pane
			 */
			bindPostClick : function() {
				$(".post").click(function() { 
					if ($(this).hasClass("post-header"))
						return;
					
					$(".post").removeClass("active");
					$(this).addClass("active"); 
					var id = $(this).attr("data-attr-id");

					var url = CiiDashboard.endPoint + "/content/index/id/" + id;
					
					$.get(url, function(data, textStatus, jqXHR) {
						CiiDashboard.Content.futurePerspective.contentPane = $($.parseHTML(data)).find(".preview").html();
						$(".preview").remove();
						$(".posts").after("<div class=\"preview nano\" id=\"preview\"></div>");
						$(".preview").html(CiiDashboard.Content.futurePerspective.contentPane).removeClass("has-scrollbar");
						$("#md-output").html(marked($("#markdown").val()));
						$("#preview.nano").nanoScroller({ OSNativeScrolling: true});

						CiiDashboard.Content.futurePerspective.delete();
						CiiDashboard.Content.futurePerspective.bindCommentBehavior();
					});
				});
			},

			bindCommentBehavior : function() {
				$(".preview-header .icon-comment").click(function() {
					$(".preview-data").slideToggle(function() {
						$(".preview-image").fadeToggle();
						var display = true;
						$("#comments").fadeToggle();
						
						if ($("#comments").is(":visible")) {
							$("#comments").remove();
							setTimeout(function() {
									$("#preview.nano").nanoScroller({ destroy: true });
									$("#preview.nano").nanoScroller({ OSNativeScrolling: true}); 
									$("#preview .content").animate({
										scrollTop : 0
									}, 0);
								}, 500);
							return;
						}

						$.post(CiiDashboard.endPoint + "/content/getComments/id/" + $("#item-id").text(), function(data) {
							$(".preview-data").after("<div id='comments'></div>");
							$("#comments").html(data).fadeIn(function() {
								setTimeout(function() {
									$("#preview.nano").nanoScroller({ destroy: true });
									$("#preview.nano").nanoScroller({ OSNativeScrolling: true}); 
									$("#preview .content").animate({
										scrollTop : 0
									}, 0);
								}, 500);
							});

							// Rounded Image 
							$(".rounded-img").load(function() {
							    $(this).wrap(function(){
							      return '<span class="' + $(this).attr('class') + '" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
							    });
							    $(this).css("opacity","0");
							});
						});
					});
				})
			},

			/**
			 * Loads appropriate comment data
			 **/
			loadComment : function(id) {
				$(".reply-" + id).click(function() {
					$(".comment-form-" + id).slideToggle(200);
				});
			},

			// AfterAjaxUpdate for ContentL:istview::afterAjaxUpdate
			afterAjaxUpdate : function() {

				// Change perspective
				CiiDashboard.Content.bindPerspectiveChange();

				// NanoScroller for main div
		    	$("#posts.nano").nanoScroller({ iOSNativeScrolling: true }); 

		    	// Timeago
		    	$(".timeago").timeago(); 

		    	// Post Click Behavior
		    	CiiDashboard.Content.futurePerspective.bindPostClick(); 

		    	// Reset Preview Pane
		    	$(".preview").remove();
				$(".posts").after("<div class=\"preview nano\" id=\"preview\"></div>");
				$(".preview").html(CiiDashboard.Content.futurePerspective.contentPane).removeClass("has-scrollbar");
				$("#preview.nano").nanoScroller({ OSNativeScrolling: true}); 
				$("#preview .content").animate({
					scrollTop : scrollTop
				}, 0);

				CiiDashboard.Content.futurePerspective.delete();
			},

			// Allows content to be deleted without page refresh
			delete : function() {
				$(".icon-trash").click(function(e) {
					e.preventDefault();
					confirm = confirm("Are you sure you want to delete this item?");
					if (confirm==true)
					{
						$.post($(this).attr("href"), function() {
							CiiDashboard.Content.futurePerspective.contentPane = null;
							$(".preview").html("<div class=\"content\"></div>");
							$.fn.yiiListView.update('ajaxListView');
						});
					}
					delete confirm;
					return false;
				});
			},

			// Bind the marked.js behavior. This should be universal across the board, so see CiiDashboard.Content.Save.marked()
			marked : function() {
				return CiiDashboard.Content.Save.marked();
			}

		},

		// Loads the necessary scripts for the old perspective
		loadOldPerspective : function() {},

		/**
		 * All functionality related to the older perspective is held here
		 * all objects and methods
		 */
		oldPerspective : {

			// Bulk action control binding
			bulkActionClick : function() {
				 $.post(CiiDashboard.endPoint + "/content/deleteMany", values, function(data) {
                    values.each(function() {
                        $(this).parent().parent().remove();
                    });
                });
			}

		},

		// The scripts that are loaded on /content/save
		loadSave : function() {
			CiiDashboard.Content.Save.tags();
			CiiDashboard.Content.Save.datePicker();
			CiiDashboard.Content.Save.bindFlipEvent();
			CiiDashboard.Content.Save.bindPreviewEditor();
		},

		/**
		 * All functionality related to saving and preview data is stored here
		 */
		Save : {

			/**
			 * Binds promoted Dropzone functionality for promoted images
			 */
			bindPromotedDz : function() {
				$(".icon-camera").click(function() {
					$("#promotedDz").toggle();
				});

				var dz = new Dropzone("#promotedDz", {
						url : CiiDashboard.endPoint + "/content/upload/id/" + $("#Content_id").val() + "/promote/1",
						dictDefaultMessage : "Drop files here to upload promoted image - or click",
						success : function(data) {
							var json = $.parseJSON(data.xhr.response);
							$(".preview-image").attr("src", CiiDashboard.endPoint.replace("/dashboard", "") + json.filepath);
							$(".icon-camera").click();
							$("#promotedDz").remove();
							$(".editor .content").prepend($("<div id='promotedDz' class='dropzone'></div>").hide());
							CiiDashboard.Content.Save.bindPromotedDz();

							$(".icon-camera").unbind("click").click(function() {
								$("#promotedDz").toggle();
							});
						}
					});
			},

			/**
			 * Provides a delete confirmation box for content
			 */
			bindDelete : function() {
				$(".icon-trash").click(function() {
					confirm = confirm("Are you sure you want to delete this item?");
					if (confirm==true)
						window.location = CiiDashboard.endPoint + "/content/delete/id/" + $("#Content_id").val();

					delete confirm;
				})
			},

			// Binds the flip event for the preview => settings pane
			bindFlipEvent : function() {
			 	$(".show-settings").click(function() {
				 	$(".flipbox").flippy({
				 		color_target : "#FFF",
					    duration: "500",
					    verso: $(".settings"),
					    onStart : function() {
					    	$(".nano").nanoScroller({ destroy: true });
					    	$(".nano").removeClass("has-scrollbar");
					    },
					    onFinish : function() {
					    	$(".show-settings").hide();
					    	$(".show-preview").show();
					    	$(".settings").show();
					    	$(".nano").nanoScroller({ flash : true});
					    	CiiDashboard.Content.Save.bindFlipEvent();
					    },
					    onReverseStart : function() {
					    	$(".body-content").after($(".settings"));
					    	$(".nano").nanoScroller({ destroy: true });
					    	$(".nano").removeClass("has-scrollbar");
					    },
					    onReverseFinish : function() {
					    	$(".settings").hide();
					    	$(".show-preview").hide();
					    	$(".show-settings").show();
					    	$(".nano").nanoScroller({ flash : true});
					    	CiiDashboard.Content.Save.bindFlipEvent();
					    }
					 });
				 });

		 		$(".show-preview").click(function() {
			 		$(".flipbox").flippyReverse();
			 	});
			},

			/**
			 * This is the majority of the preview functionality.
			 *
			 * The Preview editor ties into serveral components, namely marked.js and dropzone.js.
			 *
			 * marked.js allows the content to be rendered in near real time with syntax highlighting from highlight.js. 
			 * The use of the "{image}" keyword will instantiate a unique and persistent dropzsone.js instance which will 
			 * be held until an image is dropped in the dropzone.
			 * 
			 * Once the image is uplaoded, it will replace the corresponding "{image}" tage in the markdown editor with
			 * either a markdown syntax image tag ![]() or a <img> tag, depending upon the editor preferences set by the administrator
			 *
			 * There's a WHOLE bunch of complex logix nested into this, that probably could be optimized. It's pretty ugly, but it works magnificently
			 */
			bindPreviewEditor : function() {

				CiiDashboard.Content.Save.bindPromotedDz();
				CiiDashboard.Content.Save.bindDelete();

				$("#Content_content").bind("input propertychange change", function(event) {

					if(typeof(Storage)!=="undefined")
						localStorage.setItem("content-" + $("#Content_id").val(), $(this).val());
					
					CiiDashboard.Content.Save.marked();

					var markdown = $("<div class=\"md-preview\">" + marked($(this).val()).replace(/{image}/g, "<div class=\"dropzone\"></div>") + "</div>");

					var i = 0;

					$(".preview div.dropzone").each(function() {
						$(markdown).find("div.dropzone:eq(" + i + ")").replaceWith($(this));
						i++;
					});	

					$(".preview").html(markdown);
					$(".nano").nanoScroller();

					$("div.dropzone").each(function() {
						if (!$(this).hasClass("dz-clickable"))
		 				{
		 					// Make sure we do not have a hash collision
		 					var hash = Math.random().toString(36).substring(7);

		 					while ($(".dropzone-" + hash).length > 0)
		 						hash = Math.random().toString(36).substring(15);

							$(this).addClass("dropzone-" + hash);
							var dz = new Dropzone(".preview div.dropzone-" + hash, {
								url : CiiDashboard.endPoint + "/content/upload/id/" + $("#Content_id").val(),
								dictDefaultMessage : "Drop files here to upload - or click",
								success : function(data) {
									var response = $.parseJSON(data.xhr.response);
									if (response.success == true)
									{
										var instance = 0;

										var self = $(this);
										var classEl = "";

										var classes = $(this)[0].element.className.split(" ");
										$(classes).each(function() { 
									        var classElement = this + "";
									        if (classElement != "dropzone" && classElement != "dz-clickable" && classElement != "dz-started")
									        	classEl = classElement
									    });

										// Iterate through all the dropzone objects on the page until this one is reached
										var i = 0;
										$(".preview div.dropzone").each(function() {
											if ($(this).hasClass(classEl))
												return false;
											i++;
										});

										var index = CiiDashboard.Content.Save.GetSubstringIndex($("#Content_content").val(), "{image}", i + 1);
										if (index == '-1')
											index = 0;

										// Remove the uploader
										$("." + classEl).remove();

										// Append the text to the item at that index
										var md = $("#Content_content").val();

										// Insert either Markdown or an image tag depending upon the user preference
										if ($(".preferMarkdown").val() == 1)
											md = CiiDashboard.Content.Save.splice(md, index, 7, "![" + response.filename + "](" + CiiDashboard.endPoint.replace("/dashboard", "") + response.filepath +")");
										else
										{
											var text = $(".redactor_editor").html();
											md = CiiDashboard.Content.Save.splice(md, index, 7, "<img src=\"" + CiiDashboard.endPoint.replace("/dashboard", "") + response.filepath +"\" />");
											var index2 = CiiDashboard.Content.Save.GetSubstringIndex($(".redactor_editor").html(), "{image}", i + 1);
											if (index2 == -1)
												index2 = CiiDashboard.Content.Save.GetSubstringIndex($(".redactor_editor").html(), "{image}", i);
											text = CiiDashboard.Content.Save.splice(text, index2, 7, "<img src=\"" + CiiDashboard.endPoint.replace("/dashboard", "") + response.filepath +"\" />");
											$(".redactor_editor").html(text);
										}

										// Then modify the markdown
										$("#Content_content").val(md).change();

										// Then change the redactor view if it exists
{'fraction_non_alphanumeric': 0.1743057760841184, 'fraction_numerical': 0.0033873187255213295, 'mean_word_length': 2.5844188693562664, 'pattern_counts': {'":': 2, '<': 39, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6886626', 'n_tokens_mistral': 11201, 'n_tokens_neox': 8156, 'n_words': 1745}