/* * Aloha Editor * Author & Copyright (c) 2010 Gentics Software GmbH * aloha-sales@gentics.com * Licensed unter the terms of http://www.aloha-editor.com/license.html */ GENTICS.Aloha.Link=new GENTICS.Aloha.Plugin("com.gentics.aloha.plugins.Link");GENTICS.Aloha.Link.languages=["en","de","fr","ru","pl"];GENTICS.Aloha.Link.config=["a"];GENTICS.Aloha.Link.targetregex="";GENTICS.Aloha.Link.target="";GENTICS.Aloha.Link.cssclassregex="";GENTICS.Aloha.Link.cssclass="";GENTICS.Aloha.Link.objectTypeFilter=[];GENTICS.Aloha.Link.onHrefChange=null;GENTICS.Aloha.Link.init=function(){if(GENTICS.Aloha.Link.settings.targetregex!=undefined){GENTICS.Aloha.Link.targetregex=GENTICS.Aloha.Link.settings.targetregex}if(GENTICS.Aloha.Link.settings.target!=undefined){GENTICS.Aloha.Link.target=GENTICS.Aloha.Link.settings.target}if(GENTICS.Aloha.Link.settings.cssclassregex!=undefined){GENTICS.Aloha.Link.cssclassregex=GENTICS.Aloha.Link.settings.cssclassregex}if(GENTICS.Aloha.Link.settings.cssclass!=undefined){GENTICS.Aloha.Link.cssclass=GENTICS.Aloha.Link.settings.cssclass}if(GENTICS.Aloha.Link.settings.objectTypeFilter!=undefined){GENTICS.Aloha.Link.objectTypeFilter=GENTICS.Aloha.Link.settings.objectTypeFilter}if(GENTICS.Aloha.Link.settings.onHrefChange!=undefined){GENTICS.Aloha.Link.onHrefChange=GENTICS.Aloha.Link.settings.onHrefChange}this.createButtons();this.subscribeEvents();this.bindInteractions()};GENTICS.Aloha.Link.createButtons=function(){var that=this;this.formatLinkButton=new GENTICS.Aloha.ui.Button({iconClass:"GENTICS_button GENTICS_button_a",size:"small",onclick:function(){that.formatLink()},tooltip:this.i18n("button.addlink.tooltip"),toggle:true});GENTICS.Aloha.FloatingMenu.addButton("GENTICS.Aloha.continuoustext",this.formatLinkButton,GENTICS.Aloha.i18n(GENTICS.Aloha,"floatingmenu.tab.format"),1);this.insertLinkButton=new GENTICS.Aloha.ui.Button({iconClass:"GENTICS_button GENTICS_button_a",size:"small",onclick:function(){that.insertLink(false)},tooltip:this.i18n("button.addlink.tooltip"),toggle:false});GENTICS.Aloha.FloatingMenu.addButton("GENTICS.Aloha.continuoustext",this.insertLinkButton,GENTICS.Aloha.i18n(GENTICS.Aloha,"floatingmenu.tab.insert"),1);GENTICS.Aloha.FloatingMenu.createScope(this.getUID("link"),"GENTICS.Aloha.continuoustext");this.browser=new GENTICS.Aloha.ui.Browser();this.browser.setObjectTypeFilter(GENTICS.Aloha.Link.objectTypeFilter);this.browser.onSelect=function(item){that.hrefField.setItem(item);that.hrefChange()};this.repositoryButton=new GENTICS.Aloha.ui.Button({iconClass:"GENTICS_button_big GENTICS_button_tree",size:"large",onclick:function(){that.browser.show()},tooltip:this.i18n("button.addlink.tooltip"),toggle:false});GENTICS.Aloha.FloatingMenu.addButton(this.getUID("link"),this.repositoryButton,this.i18n("floatingmenu.tab.link"),1);this.hrefField=new GENTICS.Aloha.ui.AttributeField({width:320});this.hrefField.setObjectTypeFilter(GENTICS.Aloha.Link.objectTypeFilter);GENTICS.Aloha.FloatingMenu.addButton(this.getUID("link"),this.hrefField,this.i18n("floatingmenu.tab.link"),1);this.removeLinkButton=new GENTICS.Aloha.ui.Button({iconClass:"GENTICS_button GENTICS_button_a_remove",size:"small",onclick:function(){that.removeLink()},tooltip:this.i18n("button.removelink.tooltip")});GENTICS.Aloha.FloatingMenu.addButton(this.getUID("link"),this.removeLinkButton,this.i18n("floatingmenu.tab.link"),1)};GENTICS.Aloha.Link.bindInteractions=function(){var that=this;this.hrefField.addListener("keyup",function(obj,event){if(event.keyCode==27){var curval=that.hrefField.getQueryValue();if(curval[0]=="/"||curval.match(/^.*\.([a-z]){2,4}$/i)||curval[0]=="#"||curval.match(/^htt.*/i)){}else{}}that.hrefChange()});this.hrefField.addListener("blur",function(obj,event){if(this.getValue()==""){that.removeLink()}});for(var i=0;i'+linkText+"");GENTICS.Utils.Dom.insertIntoDOM(newLink,range,jQuery(GENTICS.Aloha.activeEditable.obj));range.startContainer=range.endContainer=newLink.contents().get(0);range.startOffset=0;range.endOffset=linkText.length}else{var newLink=jQuery('');GENTICS.Utils.Dom.addMarkup(range,newLink,false)}range.select();this.hrefField.focus();this.hrefChange()};GENTICS.Aloha.Link.removeLink=function(){var range=GENTICS.Aloha.Selection.getRangeObject();var foundMarkup=this.findLinkMarkup();if(foundMarkup){GENTICS.Utils.Dom.removeFromDOM(foundMarkup,range,true);GENTICS.Aloha.activeEditable.obj[0].focus();range.select()}};GENTICS.Aloha.Link.hrefChange=function(){this.hrefField.setAttribute("target",this.target,this.targetregex,this.hrefField.getQueryValue());this.hrefField.setAttribute("class",this.cssclass,this.cssclassregex,this.hrefField.getQueryValue());if(typeof this.onHrefChange=="function"){this.onHrefChange.call(this,this.hrefField.getTargetObject(),this.hrefField.getQueryValue(),this.hrefField.getItem())}GENTICS.Aloha.EventRegistry.trigger(new GENTICS.Aloha.Event("hrefChanged",GENTICS.Aloha,{obj:this.hrefField.getTargetObject(),href:this.hrefField.getQueryValue(),item:this.hrefField.getItem()}))};GENTICS.Aloha.Link.makeClean=function(obj){obj.find("a").each(function(){jQuery(this).removeClass("GENTICS_link_pointer");jQuery(this).removeClass("GENTICS_link_text")})};