Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 51... Línea 51...
51
 * @param {TinyMCE} editor
51
 * @param {TinyMCE} editor
52
 * @param {object} messages
52
 * @param {object} messages
53
 * @param {String} urlString
53
 * @param {String} urlString
54
 */
54
 */
55
const setNoAutoLink = (editor, messages, urlString) => {
55
const setNoAutoLink = (editor, messages, urlString) => {
56
    // Check whether the string is a URL. Otherwise, show an error notification.
-
 
57
    if (isValidUrl(urlString)) {
-
 
58
        const pendingPromise = new Pending('tiny_noautolink/setNoautolink');
56
    const pendingPromise = new Pending('tiny_noautolink/setNoautolink');
59
        // Applying the auto-link prevention.
57
    // Applying the auto-link prevention.
60
        setNoautolinkOnSelection(editor, urlString)
58
    setNoautolinkOnSelection(editor, urlString)
61
        .catch(error => {
59
    .catch(error => {
62
            editor.notificationManager.open({text: error, type: 'error', timeout: notificationTimeout});
60
        editor.notificationManager.open({text: error, type: 'error', timeout: notificationTimeout});
63
        })
61
    })
64
        .finally(() => {
62
    .finally(() => {
65
            editor.notificationManager.open({text: messages.infoAddSuccess, type: 'success', timeout: notificationTimeout});
63
        editor.notificationManager.open({text: messages.infoAddSuccess, type: 'success', timeout: notificationTimeout});
66
            pendingPromise.resolve();
64
        pendingPromise.resolve();
67
        });
-
 
68
    } else {
-
 
69
        editor.notificationManager.open({text: messages.errorInvalidURL, type: 'error', timeout: notificationTimeout});
-
 
70
    }
65
    });
71
};
66
};
Línea 72... Línea 67...
72
 
67
 
73
/**
68
/**
74
 * Display notification feedback when removing the noautolink to the selected text.
69
 * Display notification feedback when removing the noautolink to the selected text.
Línea 171... Línea 166...
171
    const currentSpan = editor.dom.getParent(editor.selection.getNode(), noautolinkTagHTML);
166
    const currentSpan = editor.dom.getParent(editor.selection.getNode(), noautolinkTagHTML);
172
    currentSpan.outerHTML = url;
167
    currentSpan.outerHTML = url;
173
};
168
};
Línea 174... Línea 169...
174
 
169
 
175
/**
-
 
176
 * Check if given string is a valid URL.
-
 
177
 *
-
 
178
 * @param {String} urlString URL the link will point to.
-
 
179
 * @returns {boolean} True is valid, otherwise false.
-
 
180
 */
-
 
181
const isValidUrl = urlString => {
-
 
182
    const urlPattern = new RegExp('^((http|https):\\/\\/|www\\.)' + // A URL must have one of these https/https/www.
-
 
183
                                '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // Validate domain name.
-
 
184
                                '((\\d{1,3}\\.){3}\\d{1,3}))' + // Validate ip (v4) address.
-
 
185
                                '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // Validate port and path.
-
 
186
                                '(\\?[;&a-z\\d%_.~+=-]*)?' + // Validate query string.
-
 
187
                                '(\\#[-a-z\\d_]*)?$', 'i'); // Validate fragment locator.
-
 
188
 
-
 
189
    return !!urlPattern.test(urlString);
-
 
190
};
-
 
191
 
-
 
192
/**
170
/**
193
 * Get anchor element.
171
 * Get anchor element.
194
 *
172
 *
195
 * @param {TinyMCE} editor
173
 * @param {TinyMCE} editor
196
 * @param {Element} selectedElm
174
 * @param {Element} selectedElm
Línea 231... Línea 209...
231
 */
209
 */
232
export const toggleActiveState = (editor) => (api) => {
210
export const toggleActiveState = (editor) => (api) => {
233
    const updateState = () => api.setActive(!editor.mode.isReadOnly() && isInAnchor(editor, editor.selection.getNode()));
211
    const updateState = () => api.setActive(!editor.mode.isReadOnly() && isInAnchor(editor, editor.selection.getNode()));
234
    updateState();
212
    updateState();
235
    return toggleState(editor, updateState);
213
    return toggleState(editor, updateState);
236
};
-
 
237
214
};
-
 
215