From 168b93f6af6146a70ac4faa82ae2366d963d4ef0 Mon Sep 17 00:00:00 2001 From: vitalif Date: Sun, 16 Dec 2012 12:21:04 +0000 Subject: [PATCH] Autocomplete for local links, fix uploads in Opera --- nicEdit.js | 47 ------------------------------------ nicImageUploadGT.js | 2 +- nicLink.js | 46 +++++++++++++++++++++++++++++++++++ nicLinkGT.js | 58 +++++++++++++++++++++++++++++++++++++++++++++ nicRu.js | 1 + 5 files changed, 106 insertions(+), 48 deletions(-) create mode 100644 nicLink.js create mode 100644 nicLinkGT.js diff --git a/nicEdit.js b/nicEdit.js index 83522b1..b0f86ef 100644 --- a/nicEdit.js +++ b/nicEdit.js @@ -1245,53 +1245,6 @@ var nicEditorFontFormatSelect = nicEditorSelect.extend({ nicEditors.registerPlugin(nicPlugin,nicSelectOptions); -/** nicLink */ - -/* START CONFIG */ -var nicLinkOptions = { - buttons : { - 'link' : {name : __('Add Link'), type : 'nicLinkButton', tags : ['A']}, - 'unlink' : {name : __('Remove Link'), command : 'unlink', noActive : true} - } -}; -/* END CONFIG */ - -var nicLinkButton = nicEditorAdvancedButton.extend({ - addPane : function() { - this.ln = this.ne.selectedInstance.selElm().parentTag('A'); - this.addForm({ - '' : {type : 'title', txt : __('Add/Edit Link')}, - 'href' : {type : 'text', txt : 'URL', value : 'http://', style : {width: '150px'}}, - 'title' : {type : 'text', txt : __('Hint')}, - 'target' : {type : 'select', txt : __('Open In'), options : {'' : __('Current Window'), '_blank' : __('New Window')},style : {width : '100px'}} - },this.ln); - }, - - submit : function(e) { - var url = this.inputs['href'].value; - if(url == "http://" || url == "") { - alert(__("You must enter a URL to Create a Link")); - return false; - } - this.removePane(); - - if(!this.ln) { - var tmp = 'javascript:nicTemp();'; - this.ne.nicCommand("createlink",tmp); - this.ln = this.findElm('A','href',tmp); - } - if(this.ln) { - this.ln.setAttributes({ - href : this.inputs['href'].value, - title : this.inputs['title'].value, - target : this.inputs['target'].options[this.inputs['target'].selectedIndex].value - }); - } - } -}); - -nicEditors.registerPlugin(nicPlugin,nicLinkOptions); - /** nicColors */ /* START CONFIG */ diff --git a/nicImageUploadGT.js b/nicImageUploadGT.js index 264efad..1a42d46 100644 --- a/nicImageUploadGT.js +++ b/nicImageUploadGT.js @@ -35,7 +35,7 @@ var nicImageUploadGTButton = nicEditorAdvancedButton.extend({ s = this.inputs['upload']; this.inputs['fileName'] = new bkElement('input').setStyle({width: '150px', height: '20px'}).setAttributes({type: 'button', value: __('Select file')}).appendTo(s); this.inputs['fileName'].addEvent('click', function() { self.inputs['file'].click(); }); - this.inputs['file'] = new bkElement('input').setStyle({width: '150px', display: 'none'}).setAttributes({type: 'file', size: 5}).appendTo(s); + this.inputs['file'] = new bkElement('input').setStyle({ width: '150px', position: 'absolute', left: '0', top: '-100px' }).setAttributes({type: 'file', size: 5}).appendTo(s); this.inputs['file'].addEvent('change', this.onFileChange.closure(this)); new bkElement('br').appendTo(s); this.inputs['progress'] = new bkElement('progress') diff --git a/nicLink.js b/nicLink.js new file mode 100644 index 0000000..9ad33e0 --- /dev/null +++ b/nicLink.js @@ -0,0 +1,46 @@ +/** nicLink */ + +/* START CONFIG */ +var nicLinkOptions = { + buttons : { + 'link' : {name : __('Add Link'), type : 'nicLinkButton', tags : ['A']}, + 'unlink' : {name : __('Remove Link'), command : 'unlink', noActive : true} + } +}; +/* END CONFIG */ + +var nicLinkButton = nicEditorAdvancedButton.extend({ + addPane : function() { + this.ln = this.ne.selectedInstance.selElm().parentTag('A'); + this.addForm({ + '' : {type : 'title', txt : __('Add/Edit Link')}, + 'href' : {type : 'text', txt : 'URL', value : 'http://', style : {width: '150px'}}, + 'title' : {type : 'text', txt : __('Hint')}, + 'target' : {type : 'select', txt : __('Open In'), options : {'' : __('Current Window'), '_blank' : __('New Window')},style : {width : '100px'}} + },this.ln); + }, + + submit : function(e) { + var url = this.inputs['href'].value; + if(url == "http://" || url == "") { + alert(__("You must enter a URL to Create a Link")); + return false; + } + this.removePane(); + + if(!this.ln) { + var tmp = 'javascript:nicTemp();'; + this.ne.nicCommand("createlink",tmp); + this.ln = this.findElm('A','href',tmp); + } + if(this.ln) { + this.ln.setAttributes({ + href : this.inputs['href'].value, + title : this.inputs['title'].value, + target : this.inputs['target'].options[this.inputs['target'].selectedIndex].value + }); + } + } +}); + +nicEditors.registerPlugin(nicPlugin,nicLinkOptions); diff --git a/nicLinkGT.js b/nicLinkGT.js new file mode 100644 index 0000000..e3b6119 --- /dev/null +++ b/nicLinkGT.js @@ -0,0 +1,58 @@ +/** nicLink */ + +/* START CONFIG */ +var nicLinkGTOptions = { + buttons : { + 'link' : {name : __('Add Link'), type : 'nicLinkGTButton', tags : ['A']}, + 'unlink' : {name : __('Remove Link'), command : 'unlink', noActive : true} + } +}; +/* END CONFIG */ + +var nicLinkGTButton = nicEditorAdvancedButton.extend({ + addPane: function() { + this.ln = this.ne.selectedInstance.selElm().parentTag('A'); + this.addForm({ + '': {type: 'title', txt: __('Add/Edit Link')}, + 'href': {type: 'text', txt: __('URL or Page'), value: '', style: {width: '150px'}}, + 'title': {type: 'text', txt: __('Hint')}, + 'target': {type: 'select', txt: __('Open In'), options: {'' : __('Current Window'), '_blank': __('New Window')}, style: {width: '100px'}} + },this.ln); + this.hinter = new SimpleAutocomplete(this.inputs['href'], this.gtLoadData.closure(this), null, null, null, false, true); + }, + + gtLoadData: function(hint, value) { + POST(GT.domain+'/api.php?action=listpages&format=json', {value: value}, function(r){ + try { hint.replaceItems(JSON.parse(r.responseText)); } + catch(e) {} + }); + }, + + submit: function(e) { + var url = this.inputs['href'].value; + if(url == "http://" || url == "") { + alert(__("You must enter a URL to Create a Link")); + return false; + } + var gtId = /^#(\S+)\s+-\s+/.exec(url); + if (gtId) { + url = 'page.php?alias='+gtId[1]; + } + this.removePane(); + + if(!this.ln) { + var tmp = 'javascript:nicTemp();'; + this.ne.nicCommand("createlink",tmp); + this.ln = this.findElm('A','href',tmp); + } + if(this.ln) { + this.ln.setAttributes({ + href: url, + title: this.inputs['title'].value, + target: this.inputs['target'].options[this.inputs['target'].selectedIndex].value + }); + } + } +}); + +nicEditors.registerPlugin(nicPlugin,nicLinkGTOptions); diff --git a/nicRu.js b/nicRu.js index b15d3c6..9020092 100644 --- a/nicRu.js +++ b/nicRu.js @@ -50,6 +50,7 @@ var nicRu = { 'Save this content': 'Сохранить', 'Add Link': 'Вставить ссылку', + 'URL or Page': 'URL или страница', 'Remove Link': 'Убрать ссылку', 'Add/Edit Link': 'Ссылка', 'Hint': 'Подсказка',