praiadeseselle/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.min.js

1 line
8.1 KiB
JavaScript
Raw Normal View History

$(document).ready(function(){if(!ProcessWire.config.ProcessPageEditLink)return;var cfg=ProcessWire.config.ProcessPageEditLink;var options={selectStartLabel:cfg.selectStartLabel,selectSelectLabel:cfg.selectStartLabel,langID:cfg.langID};var options2={selectStartLabel:options.selectStartLabel,selectSelectLabel:options.selectStartLabel,langID:options.langID,rootPageID:cfg.pageID};var selectedPageData={id:0,title:"",url:""};var $fileSelect=$("#link_page_file");var $anchorSelect=$("#link_page_anchor");var $linkPageURL=$("#link_page_url_input");var $linkText=$("#link_text");$linkPageURL.val($("#link_page_url").val());function populateFileSelect(selectedPageData){var $wrap=$("#wrap_link_page_file");$.getJSON("./files?id="+selectedPageData.id,function(data){$fileSelect.empty();$fileSelect.append("<option></option>");$.each(data,function(key,val){var $option=$("<option value='"+key+"'>"+val+"</option>");$fileSelect.append($option)});$wrap.find("p.notes strong").text(selectedPageData.url);if($fileSelect.is(":visible")){$wrap.children().effect("highlight",{},500);$fileSelect.effect("bounce",{},50)}})}function absoluteToRelativePath(path){if(cfg.urlType==0)return path;function slashesToRelative(url){url=url.replace(/\//g,"../");url=url.replace(/[^.\/]/g,"");return url}var url;if(path===cfg.pageUrl){path="./";if(!cfg.slashUrls)path+=cfg.pageName}else if(path.indexOf(cfg.pageUrl)===0){path=path.substring(cfg.pageUrl.length);if(!cfg.slashUrls)path=cfg.pageName+path}else if(cfg.pageUrl.indexOf(path)===0){url=cfg.pageUrl.substring(path.length);if(url.indexOf("/")!=-1){url=slashesToRelative(url)}else{url="./"}path=url}else if(path.indexOf(cfg.rootParentUrl)===0){url=path.substring(cfg.rootParentUrl.length);var url2=url;url=slashesToRelative(url)+url2;path=url}else if(cfg.urlType==2){url=cfg.pageUrl.substring(ProcessWire.config.urls.root.length);url=slashesToRelative(url);path=path.substring(ProcessWire.config.urls.root.length);path=url+path}return path}function pageSelected(event,data){if(data.url&&data.url.length){selectedPageData=data;selectedPageData.url=ProcessWire.config.urls.root+data.url.substring(1);selectedPageData.url=absoluteToRelativePath(selectedPageData.url);$linkPageURL.val(selectedPageData.url).trigger("change");populateFileSelect(selectedPageData)}$(this).parents(".InputfieldInteger").children(".InputfieldHeader").trigger("click").parent().find(".PageListSelectHeader").removeClass("hidden").show()}$("#link_page_id").ProcessPageList(options).hide().on("pageSelected",pageSelected);$("#child_page_id").ProcessPageList(options2).hide().on("pageSelected",pageSelected);$fileSelect.on("change",function(){var $t=$(this);var src=$t.val();if(src.length)$linkPageURL.val(src).trigger("change")});if($anchorSelect.length){var anchorPreviousValue=$anchorSelect.val();$anchorSelect.on("change",function(){var val=$(this).val();if(val.length){$linkPageURL.val(val);anchorPreviousValue=val}else{if($linkPageURL.val()==anchorPreviousValue)$linkPageURL.val("")}$linkPageURL.trigger("change")})}function updateLinkPreview(){if(!$linkPageURL.val().length){$("#link_markup").text("");return}var $link=$("<a />");$link.attr("href",$linkPageURL.val());var $linkTitle=$("#link_title");if($linkTitle.length&&$linkTitle.val().length){var val=$("<div />").text($linkTitle.val()).html();$link.attr("title",val)}if(cfg.noLinkTextEdit){}else if($linkText.length&&$linkText.val().length){$link.text($linkText.val())}var $linkRel=$("#link_rel");if($linkRel.length&&$linkRel.val()&&$linkRel.val().length){$link.attr("rel",$linkRel.val())}var $linkTarget=$("#link_target");if($linkTarget.length&&$linkTarget.val().length){$link.attr("target",$linkTarget.val())}var $linkClass=$("#wrap_link_class").find("input:checked");if($linkClass.length){$linkClass.each(function(){$link.addClass($(this).val())})}$("#link_markup").text($link[0].outerHTML)}function urlKeydown(){var $this=$linkPageURL;var val=ProcessWire.trim($this.val());var dotpos=val.indexOf(".");var slashespos=val.indexOf("//");var hasScheme=slashespos>-1&&slashespos<dotpos;var slashpos=slashespos>-1?val.indexOf("/",slashe