$ ->
	$("*[data-umlaut-toggle-permalink]").click (event) ->
		originalLink   = $(this)
		valueContainer = $("#umlaut-permalink-container")
		loadedLink = $(".umlaut-permalink-content a")
		url = loadedLink.attr("href")
		if url == undefined
			loadedLink = $("#umlaut-permalink-content")
			url = loadedLink.attr("href")
		input = $("<input />")
		input.attr("value", url)
		input.addClass("form-control")
		valueContainer.html("Cut and paste the following URL:")
		valueContainer.append(input)
		valueContainer.append(loadedLink.attr("id","umlaut-permalink-content"))
		loadedLink.hide()
		input.select()

$ ->
	$("*[data-umlaut-toggle-permalink]").click (event) ->
		if $(".umlaut-permalink-container input").is(":visible")
			$(".umlaut-permalink-container input").select()
		permalinkLoaded = setInterval ->
			if $(".umlaut-permalink-container a").is(":visible")
				reformatPermalink(event)
				clearInterval(permalinkLoaded)
		, 0

reformatPermalink = (event) ->
	originalLink   = $(this)
	valueContainer = $("#umlaut-permalink-container")

	loadedLink = $(".umlaut-permalink-container a")
	url = loadedLink.attr("href")
	input = $("<input />")
	input.attr("value", url)
	input.attr("readonly", "true")
	input.addClass("form-control")
	valueContainer.html("Cut and paste the following URL:")
	valueContainer.append(input)
	input.select()

Fix permalink reformat to wait for link to load if its the first time the page opened
Fix permalink reformat to wait for link to load if its the first time the page opened
