forked from marcostoll/processwire-fieldtype-assisted-url
-
Notifications
You must be signed in to change notification settings - Fork 4
/
InputfieldAssistedURL.js
101 lines (80 loc) · 3.33 KB
/
InputfieldAssistedURL.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// based on /ProcessWire/wire/modules/Inputfield/InputfieldCKEditor/plugins/pwlink/plugin.js
$(document).ready(function() {
if(!ProcessWire.config.InputfieldCKEditor) {
ProcessWire.config.InputfieldCKEditor = {
"language": "en",
"timestamp": "2015030801.169",
"editors": [],
"pwlink": {
"label": "Insert Link",
"edit": "Edit Link",
"cancel": "Cancel",
"classOptions": ""
}
}
}
$(document).on("click", ".InputfieldAssistedURLOpen", function(e) {
loadIframeLinkPicker(e.currentTarget);
$(this).removeClass('ui-state-active');
return false;
});
function loadIframeLinkPicker(opener) {
var pageID = $(opener).attr('data-page-id');
// build the modal URL
var modalUrl = config.urls.admin + 'page/link/?id=' + pageID + '&modal=1';
// labels
var insertLinkLabel = ProcessWire.config.InputfieldCKEditor.pwlink.label;
var cancelLabel = ProcessWire.config.InputfieldCKEditor.pwlink.cancel;
var $iframe; // set after modalSettings down
// action when insert link button is clicked
function clickInsert() {
var $i = $iframe.contents();
var $a = $($("#link_markup", $i).text());
$(opener).siblings('.InputfieldAssistedUrlText').find('.InputfieldAssistedURLInput').val($a.attr('href'));
$iframe.dialog("close");
}
// settings for modal window
var modalSettings = {
title: "<i class='fa fa-link'></i> " + insertLinkLabel,
open: function() {
//if($(".cke_maximized").length > 0) {
// // the following is required when CKE is maximized to make sure dialog is on top of it
// $('.ui-dialog').css('z-index', 9999);
// $('.ui-widget-overlay').css('z-index', 9998);
//}
},
buttons: [ {
class: "pw_link_submit_insert",
html: "<i class='fa fa-link'></i> " + insertLinkLabel,
click: clickInsert
}, {
html: "<i class='fa fa-times-circle'></i> " + cancelLabel,
click: function() { $iframe.dialog("close"); },
class: 'ui-priority-secondary'
}
]
};
// create modal window
var $iframe = pwModalWindow(modalUrl, modalSettings, 'medium');
// modal window load event
$iframe.load(function() {
var $i = $iframe.contents();
$i.find("#ProcessPageEditLinkForm").data('iframe', $iframe);
// remove tab navigation
$i.find('#breadcrumbs').remove();
$i.find('#PageEditLinkTabs').hide();
// hide generated link code
$i.find('#link_markup').hide();
// capture enter key in main URL text input
$("#link_page_url", $i).keydown(function(event) {
var $this = $(this);
var val = $.trim($this.val());
if (event.keyCode == 13) {
event.preventDefault();
if(val.length > 0) clickInsert();
return false;
}
});
}); // load
} // loadIframeLinkPicker
});