-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
148 lines (116 loc) · 5.31 KB
/
script.js
File metadata and controls
148 lines (116 loc) · 5.31 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* DokuWiki Plugin TagSections (JavaScript Component)
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author gamma
*/
(function(jQuery) {
// Use the internal reference of jQuery.
// this is due to jQuery reloading in initJQuery() so that we keep the correct reference
var currentNamespace = JSINFO['namespace'];
var $currentButton = null;
var init = function() {
jQuery('.editbutton_section form.btn_secedit').submit(loadEditDialog);
};
var loadEditDialog = function(event){
$currentButton = jQuery(this);
console.log($currentButton);
request({'do':'edit'}, showEditDialog);
return false;
};
var showEditDialog = function(data) {
var $dialog = getDialog('open').html(data);
initJQuery();
$dialog.find('.editButtons').detach();
};
var request = function(data, success) {
data['id'] = $currentButton.find('input[name=id]').val() || JSINFO['id'];
data['rev'] = $currentButton.find('input[name=rev]').val();
data['call'] = 'sectionedit';
data['target'] = $currentButton.find('input[name=target]').val();
data['range'] = $currentButton.find('input[name=range]').val();
return jQuery.post(DOKU_BASE + 'lib/exe/ajax.php', data, success);
};
var saveSection = function() {
var $form = jQuery(this);
var objects = {
'do': 'save'
};
$form.find('input[name][value], textarea[name]').each(function(){
var $element = jQuery(this);
if ( this.tagName.toLowerCase() == 'input' && $element.is(':checkbox') && !$element.is(':checked') ) {
return;
}
objects[this.name] = $element.val();
});
var hasParentsWithDokuWikiContent = function( $nodeWithParents ) {
if ( $nodeWithParents.is( 'body' ) ) {
return false;
}
if ( $nodeWithParents.children().filter('h1,h2,h3,h4,h5,h6,.level1,.level2,.level3,.level4,.level5,.level6').length ) {
return true;
}
return hasParentsWithDokuWikiContent( $nodeWithParents.parent() );
};
request(objects, function(){
// We need to wrap this once more, because otherwise the edit buttons will have the wrong ranges
request({}, function(data){
var $toRemove = $currentButton.parent(),
$tmpWrap = jQuery('<div style="display:none"></div>').html(data); // temporary wrapper
while( hasParentsWithDokuWikiContent( $toRemove.parent() ) ) {
$toRemove = $toRemove.parent();
}
$toRemove = $toRemove.children();
// insert the section highlight wrapper before the last element added to $tmpStore
$toRemove.filter(':last').before($tmpWrap);
// and remove the elements
$toRemove.detach();
// Now remove the content again
$tmpWrap.before($tmpWrap.children().detach());
// ...and remove the section highlight wrapper
$tmpWrap.detach();
closeDialog();
initJQuery();
});
});
};
var closeDialog = function() {
getDialog('close').dialog('destroy').detach();
// This is being set by the edit.js - needs reset before unloading
window.onbeforeunload = '';
deleteDraft && deleteDraft();
textChanged = false;
dw_locktimer.clear();
};
var initJQuery = function() {
// Remove current edit handler
jQuery('.editbutton_section form.btn_secedit').unbind('submit', loadEditDialog);
jQuery('script[src]').each(function(){
var $xchange = jQuery(this);
var $new = jQuery('<script/>').attr('type', $xchange.attr('type')).attr('defer', 'true');
$xchange.before($new).detach();
$new.attr('src', $xchange.attr('src'));
});
};
var getDialog = function(action) {
if(!jQuery('#sectionedit__dilaog').length){
jQuery('body').append('<div id="sectionedit__dilaog" position="absolute" border=1 height="800px" class="dokuwiki page"><div id="sectionedit__dialog_div"></div></div>');
jQuery( "#sectionedit__dilaog" ).dialog({title:LANG.plugins.sectionedit['edit'],
height: Math.min(700,jQuery(window).height()-50),
width: Math.min(700,jQuery(window).width()-50),
autoOpen:true,
closeOnEscape:false,
modal:true,
buttons:[
{text:LANG.plugins.sectionedit['closeDialog'],click: closeDialog },
{text:LANG.plugins.sectionedit['save'],click: saveSection},
],
});
}
if ( action ) {
return jQuery('#sectionedit__dilaog').dialog(action);
}
return jQuery('#sectionedit__dilaog');
};
jQuery(document).ready(init);
})(jQuery);