PageSourceSearch

https://www.jhrl.com/sites/all/modules/contrib/caption_filter/js/caption-filter.js?tlse4v

js jhrl.com collected 2026-10-06 13:18:09 UTC 2,879 bytes, 63 lines download raw bytes

1/**
2 * @file
3 * JavaScript integrations between the Caption Filter module and particular
4 * WYSIWYG editors. This file also implements Insert module hooks to respond
5 * to the insertion of content into a WYSIWYG or textarea.
6 */
7(function ($) {
8
9$(document).bind('insertIntoActiveEditor', function(event, options) {
10  if (options['fields']['title'] && Drupal.settings.captionFilter.widgets[options['widgetType']]) {
11    options['content'] = '[caption caption="' + options['fields']['title'].replace(/"/g, '\\"') + '"]' + options['content'] + '[/caption]';
12  }
13});
14
15Drupal.captionFilter = Drupal.captionFilter || {};
16
17Drupal.captionFilter.toHTML = function(co, editor) {
18  return co.replace(/(?:<p>)?\[caption([^\]]*)\]([\s\S]+?)\[\/caption\](?:<\/p>)?[\s\u00a0]*/g, function(a,b,c){
19    var id, cls, w, tempClass;
20
21    b = b.replace(/\\?'|\\&#39;|\\&#039;/g, '&#39;').replace(/\\"|\\&quot;/g, '&quot;');
22    c = c.replace(/\\&#39;|\\&#039;/g, '&#39;').replace(/\\&quot;/g, '&quot;');
23    id = b.match(/id=['"]([^'"]+)/i);
24    cls = b.match(/align=['"]([^'"]+)/i);
25    ct = b.match(/caption=['"]([^'"]+)/i);
26    w = c.match(/width=['"]([0-9]+)/);
27
28    id = ( id && id[1] ) ? id[1] : '';
29    cls = ( cls && cls[1] ) ? 'caption-' + cls[1] : '';
30    ct = ( ct && ct[1] ) ? ct[1].replace(/\\\\"/,'"') : '';
31    w = ( w && w[1] ) ? parseInt(w[1])+'px' : 'auto';
32
33    if (editor == 'tinymce')
34      tempClass = (cls == 'caption-center') ? 'mceTemp mceIEcenter' : 'mceTemp';
35    else if (editor == 'ckeditor')
36      tempClass = (cls == 'caption-center') ? 'mceTemp mceIEcenter' : 'mceTemp';
37    else
38      tempClass = '';
39
40    if (ct) {
41      return '<div class="caption ' + cls + ' ' + tempClass + ' draggable"><div class="caption-width-container" style="width: ' + w + '"><div class="caption-inner">' + c + '<p class="caption-text">' + ct + '</p></div></div></div><br />';
42    }
43    else {
44      return '<div class="caption ' + cls + ' ' + tempClass + ' draggable"><div class="caption-width-container" style="width: ' + w + '"><div class="caption-inner">' + c + '</div></div></div><br />';
45    }
46  });
47};
48
49Drupal.captionFilter.toTag = function(co) {
50  return co.replace(/(<div class="caption [^"]*">)\s*<div[^>]+>\s*<div[^>]+>(.+?)<\/div>\s*<\/div>\s*<\/div>\s*/gi, function(match, captionWrapper, contents) {
51    var align;
52    align = captionWrapper.match(/class=.*?caption-(left|center|right)/i);
53    align = (align && align[1]) ? align[1] : '';
54    caption = contents.match(/\<p class=\"caption-text\"\>(.*)\<\/p\>/);
55    caption_html = (caption && caption[0]) ? caption[0] : '';
56    caption = (caption && caption[1]) ? caption[1].replace(/"/g, '\\"') : '';
57    contents = contents.replace(caption_html, '');
58
59    return '[caption' + (caption ? (' caption="' + caption + '"') : '') + (align ? (' align="' + align + '"') : '') + ']' + contents + '[/caption]';
60  });
61};
62
63})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.