Welcome to mirror list, hosted at ThFree Co, Russian Federation.

JqueryExtended.js « utils « src « js - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 64c0d5735559c09b8e3e803e452845fcef28b166 (plain)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import $ from 'jquery';
import 'jquery-migrate';
import 'jquery-ui-bundle';
import 'jquery-mousewheel';
import 'jquery.event.drag';
import 'jquery-validation';
import 'jquery-ui-timepicker-addon';
import '../plugins/jquery/jquery.uitablefilter';
import { methods } from './menu_resizer';
// TODO: To use this import for replacing variables used in this file for
// extending various strings for localization.
// import { GlobalVariables, timePicker, validations } from '../variables/export_variables';
import { PMA_Messages as PMA_messages } from '../variables/export_variables';

/**
 * Make sure that ajax requests will not be cached
 * by appending a random variable to their parameters
 */
$.ajaxPrefilter(function (options, originalOptions) {
    var nocache = new Date().getTime() + '' + Math.floor(Math.random() * 1000000);
    if (typeof options.data === 'string') {
        options.data += '&_nocache=' + nocache + '&token=' + encodeURIComponent(PMA_commonParams.get('token'));
    } else if (typeof options.data === 'object') {
        options.data = $.extend(originalOptions.data, { '_nocache' : nocache, 'token': PMA_commonParams.get('token') });
    }
});

/**
 * Comes from menu_resizer.js
 */
$.fn.menuResizer = function (method) {
    if (methods[method]) {
        return methods[method].call(this);
    } else if (typeof method === 'function') {
        return methods.init.apply(this, [method]);
    } else {
        $.error('Method ' +  method + ' does not exist on jQuery.menuResizer');
    }
};

/**
 * comes from makegrid.js
 */
$.fn.noSelect = function (p) { // no select plugin by Paulo P.Marinas
    var prevent = (p === null) ? true : p;
    var is_msie = navigator.userAgent.indexOf('MSIE') > -1 || !!window.navigator.userAgent.match(/Trident.*rv\:11\./);
    var is_firefox = navigator.userAgent.indexOf('Firefox') > -1;
    var is_safari = navigator.userAgent.indexOf('Safari') > -1;
    var is_opera = navigator.userAgent.indexOf('Presto') > -1;
    if (prevent) {
        return this.each(function () {
            if (is_msie || is_safari) {
                $(this).on('selectstart', false);
            } else if (is_firefox) {
                $(this).css('MozUserSelect', 'none');
                $('body').trigger('focus');
            } else if (is_opera) {
                $(this).on('mousedown', false);
            } else {
                $(this).attr('unselectable', 'on');
            }
        });
    } else {
        return this.each(function () {
            if (is_msie || is_safari) {
                $(this).off('selectstart');
            } else if (is_firefox) {
                $(this).css('MozUserSelect', 'inherit');
            } else if (is_opera) {
                $(this).off('mousedown');
            } else {
                $(this).removeAttr('unselectable');
            }
        });
    }
};

/**
 * comes from functions.js
 */
/**
 * jQuery plugin to correctly filter input fields by value, needed
 * because some nasty values may break selector syntax
 */
$.fn.filterByValue = function (value) {
    return this.filter(function () {
        return $(this).val() === value;
    });
};

/**
 * jQuery function that uses jQueryUI's dialogs to confirm with user. Does not
 *  return a jQuery object yet and hence cannot be chained
 *
 * @param string      question
 * @param string      url           URL to be passed to the callbackFn to make
 *                                  an Ajax call to
 * @param function    callbackFn    callback to execute after user clicks on OK
 * @param function    openCallback  optional callback to run when dialog is shown
 */

$.fn.PMA_confirm = function (question, url, callbackFn, openCallback) {
    var confirmState = PMA_commonParams.get('confirm');
    if (! confirmState) {
        // user does not want to confirm
        if ($.isFunction(callbackFn)) {
            callbackFn.call(this, url);
            return true;
        }
    }
    if (PMA_messages.strDoYouReally === '') {
        return true;
    }

    /**
     * @var    button_options  Object that stores the options passed to jQueryUI
     *                          dialog
     */
    var button_options = [
        {
            text: PMA_messages.strOK,
            'class': 'submitOK',
            click: function () {
                $(this).dialog('close');
                if ($.isFunction(callbackFn)) {
                    callbackFn.call(this, url);
                }
            }
        },
        {
            text: PMA_messages.strCancel,
            'class': 'submitCancel',
            click: function () {
                $(this).dialog('close');
            }
        }
    ];

    $('<div/>', { 'id': 'confirm_dialog', 'title': PMA_messages.strConfirm })
        .prepend(question)
        .dialog({
            buttons: button_options,
            close: function () {
                $(this).remove();
            },
            open: openCallback,
            modal: true
        });
};

/**
 * jQuery function to sort a table's body after a new row has been appended to it.
 *
 * @param string      text_selector   string to select the sortKey's text
 *
 * @return jQuery Object for chaining purposes
 */
$.fn.PMA_sort_table = function (text_selector) {
    return this.each(function () {
        /**
         * @var table_body  Object referring to the table's <tbody> element
         */
        var table_body = $(this);
        /**
         * @var rows    Object referring to the collection of rows in {@link table_body}
         */
        var rows = $(this).find('tr').get();

        // get the text of the field that we will sort by
        $.each(rows, function (index, row) {
            row.sortKey = $.trim($(row).find(text_selector).text().toLowerCase());
        });

        // get the sorted order
        rows.sort(function (a, b) {
            if (a.sortKey < b.sortKey) {
                return -1;
            }
            if (a.sortKey > b.sortKey) {
                return 1;
            }
            return 0;
        });

        // pull out each row from the table and then append it according to it's order
        $.each(rows, function (index, row) {
            $(table_body).append(row);
            row.sortKey = null;
        });
    });
};

/**
 * Return POST data as stored by Util::linkOrButton
 */
$.fn.getPostData = function () {
    var dataPost = this.attr('data-post');
    // Strip possible leading ?
    if (dataPost !== undefined && dataPost.substring(0,1) === '?') {
        dataPost = dataPost.substr(1);
    }
    return dataPost;
};

/**
 * Replacing default datepicker strings for localization
 */
if ($.datepicker) {
    // Creating copy of datepicker strings object
    var datePicker = Object.assign(window.datePicker);
    // Deleting datepicker variable from window as it is of no use now
    delete window.datePicker;

    for (let key in datePicker) {
        $.datepicker.regional[''][key] = datePicker[key];
    }
}

/**
 * Replacing default timepicker strings for localozation
 */
if ($.timePicker) {
    // Creating copy of timepicker strings object
    var timePicker = Object.assign(window.timePicker);
    // Deleting timepicker variable from window as it is of no use now
    delete window.timePicker;

    for (let key in timePicker) {
        $.timepicker.regional[''][key] = timePicker[key];
    }
}

export function extendingValidatorMessages () {
    var validateMessage;
    var validateFormat;
    // Creating copy of validationMessage strings object
    if (typeof window.validateMessage !== 'undefined') {
        validateMessage = Object.assign(window.validationMessage);
    }
    // Deleting validationMessage variable from window as it is of no use now
    delete window.validationMessage;
    // Replacing default validation messages forr localization
    $.extend($.validator.messages, validateMessage);

    // Creating copy of validationFormat strings object
    if (typeof window.validationFormat !== 'undefined') {
        validateFormat = Object.assign(window.validationFormat);
    }
    // Deleting validationFormat variable from window as it is of no use now
    delete window.validationFormat;
    for (let i in validateFormat) {
        validateFormat[i] = $.validator.format(validateFormat[i]);
    }
    // Replacing default validation messages forr localization
    $.extend($.validator.messages, validateFormat);
}

window.jQ = $;

export {
    $
};