/* * 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"];GENTICS.Aloha.Link.config=["a"];GENTICS.Aloha.Link.targetregex="";GENTICS.Aloha.Link.target="";GENTICS.Aloha.Link.cssclassregex="";GENTICS.Aloha.Link.cssclass="";GENTICS.Aloha.Link.mouseOverLink=null;GENTICS.Aloha.Link.ressource=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.ressource!=undefined){GENTICS.Aloha.Link.ressource=GENTICS.Aloha.Link.settings.ressource}this.initButtons();this.subscribeEvents();this.bindInteractions()};GENTICS.Aloha.Link.initButtons=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.srcFieldButton=new GENTICS.Aloha.Link.SrcField();GENTICS.Aloha.FloatingMenu.addButton(this.getUID("link"),this.srcFieldButton,this.i18n("floatingmenu.tab.link"),1);GENTICS.Aloha.FloatingMenu.addButton(this.getUID("link"),new GENTICS.Aloha.ui.Button({iconClass:"GENTICS_button GENTICS_button_a_remove",size:"small",onclick:function(){that.removeLink()},tooltip:this.i18n("button.removelink.tooltip")}),this.i18n("floatingmenu.tab.link"),1)};GENTICS.Aloha.Link.bindInteractions=function(){var that=this;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.srcFieldButton.focus()};GENTICS.Aloha.Link.removeLink=function(){var that=this;var range=GENTICS.Aloha.Selection.getRangeObject();var foundMarkup=that.findLinkMarkup();if(foundMarkup){GENTICS.Utils.Dom.removeFromDOM(foundMarkup,range,true);GENTICS.Aloha.activeEditable.obj[0].focus();range.select()}};GENTICS.Aloha.Link.makeClean=function(obj){obj.find("a").each(function(){})};Ext.ux.LinkSrcButton=Ext.extend(Ext.Component,{wrapper:null,input:null,anchor:null,onRender:function(){var that=this;Ext.ux.LinkSrcButton.superclass.onRender.apply(this,arguments);this.wrapper=jQuery(this.el.dom);this.input=jQuery('');if(GENTICS.Aloha.Link.settings.ressource||1==1){var data=[{id:1,text:"Link A",url:"/page1"},{id:2,text:"Link B",url:"/page2"},{id:3,text:"Link C",url:"/page3"},{id:4,text:"Link D",url:"/page4"}];this.input.autocomplete(data,{formatItem:function(item){return item.text+'
'+item.url+""}}).result(function(event,item){that.input.val(item.url);jQuery(that.anchor).attr("id",item.id)})}this.input.keyup(function(event){if(that.anchor){if(that.input.val().length>=2){jQuery(that.anchor).attr("href",that.input.val())}else{jQuery(that.anchor).attr("href","#")}}if(event.keyCode==13||event.keyCode==27){GENTICS.Aloha.activeEditable.obj[0].focus();GENTICS.Aloha.Selection.getRangeObject().select()}else{that.setAttribute(that.input.val(),"target",GENTICS.Aloha.Link.targetregex,GENTICS.Aloha.Link.target);that.setAttribute(that.input.val(),"class",GENTICS.Aloha.Link.cssclassregex,GENTICS.Aloha.Link.cssclass)}});this.input.blur(function(event){if(that.input.val()==""){GENTICS.Aloha.Link.removeLink()}});this.wrapper.append(this.input);if(this.getFocus){this.getFocus=undefined;this.input.select();this.input.focus()}},setAttribute:function(input,attr,regex,value){var that=this;if(typeof value!="undefined"){var setTarget=true;if(typeof regex!="undefined"){var regex=new RegExp(regex);if(input.match(regex)){setTarget=true}else{setTarget=false}}if(setTarget){jQuery(that.anchor).attr(attr,value)}else{jQuery(that.anchor).removeAttr(attr)}}},setAnchor:function(anchor){this.anchor=anchor;if(this.input){if(this.anchor){this.input.val(jQuery(this.anchor).attr("href"))}else{this.input.val("")}}},focus:function(){if(this.input){this.input.select();this.input.focus()}else{this.getFocus=true}}});Ext.reg("linksrcbutton",Ext.ux.LinkSrcButton);GENTICS.Aloha.Link.SrcField=function(){GENTICS.Aloha.ui.Button.apply(this,arguments)};GENTICS.Aloha.Link.SrcField.prototype=new GENTICS.Aloha.ui.Button();GENTICS.Aloha.Link.SrcField.prototype.getExtConfigProperties=function(){return{xtype:"linksrcbutton",id:this.id}};GENTICS.Aloha.Link.SrcField.prototype.setAnchor=function(anchor){if(this.extButton){this.extButton.setAnchor(anchor)}};GENTICS.Aloha.Link.SrcField.prototype.focus=function(){if(this.extButton){this.extButton.focus()}};