1/* 2 @file 3 Defines the simple modal behavior 4*/ 5(function ($) { 6 Drupal.behaviors.event_popup = { 7 attach: function(context, settings) { 8 9 if ($("#event-popup-container").length == 0) { 10 // Add a container to the end of the body tag to hold the dialog 11 $('body').append('<div id="event-popup-container" style="display:none;"></div>'); 12 try { 13 // Attempt to invoke the simple dialog 14 $( "#event-popup-container").dialog({ 15 autoOpen: false, 16 modal: true, 17 close: function(event, ui) { 18 // Clear the dialog on close. Not necessary for your average use 19 // case, butis useful if you had a video that was playing in the 20 // dialog so that it clears when it closes 21 $('#event-popup-container').html(''); 22 } 23 }); 24 var defaultOptions = Drupal.event_popup.explodeOptions(settings.event_popup.defaults); 25 $('#event-popup-container').dialog('option', defaultOptions); 26 } 27 catch (err) { 28 // Catch any errors and report 29 Drupal.event_popup.log('[error] Event Dialog: ' + err); 30 } 31 } 32 // Add support for custom classes if necessary 33 var classes = ''; 34 if (settings.event_popup.classes) { 35 classes = ', .' + settings.event_popup.classes; 36 } 37 $('a.event-popup' + classes, context).each(function(event) { 38 if (!event.metaKey && !$(this).hasClass('simpleEventProcessed')) { 39 // Add a class to show that this link has been processed already 40 $(this).addClass('simpleEventProcessed'); 41 $(this).click(function(event) { 42 // prevent the navigation 43 event.preventDefault(); 44 // Set up some variables 45 var url = $(this).attr('href'); 46 var title = $(this).attr('title'); 47 // Use defaults if not provided 48 var selector = $(this).attr('name') ? 'event-calendar' : 'event_calendar'; 49 50 var options = Drupal.event_popup.explodeOptions('width:auto;height:auto;position:[300,140]'); 51 52 if (url && title && selector) { 53 // Set the custom options of the dialog 54 $('#event-popup-container').dialog('option', options); 55 56 // Set the title of the dialog 57 $('#event-popup-container').dialog('option', 'title', title); 58 59 // Add a little loader into the dialog while data is loaded 60 $('#event-popup-container').html('<div class="event-popup-ajax-loader"></div>'); 61 62 // Change the height if it's set to auto 63 if (options.height && options.height == 'auto') { 64 $('#event-popup-container').dialog('option', 'height', 200); 65 } 66 67 // Use jQuery .get() to request the target page 68 $.get(url, function(data) { 69 // Re-apply the height if it's auto to accomodate the new content 70 if (options.height && options.height == 'auto') { 71 72 $('#event-popup-container').dialog('option', 'height', options.height); 73 74 } 75 // Some trickery to make sure any inline javascript gets run. 76 // Inline javascript gets removed/moved around when passed into 77 // $() so you have to create a fake div and add the raw data into 78 // it then find what you need and clone it. Fun. 79 $('#event-popup-container').html( $( '<div></div>' ).html( data ).find( ':regex(class, .*'+selector+'.*)' ).not('.field').clone() ); 80 81 // Attach any behaviors to the loaded content 82 //Drupal.attachBehaviors($('#event-popup-container')); 83 84 }); 85 // Open the dialog 86 $('#event-popup-container').dialog('open'); 87 // Return false for good measure 88 return false; 89 } 90 }); 91 } 92 }); 93 var op = Drupal.settings.event_popup.op; 94 if(op) { 95 $('table.full tr td, table.mini tr td', context).click(function () { 96 //$('.fc-sun', context).click(function () { 97 var node_type = Drupal.settings.event_popup.content_type; 98 node_type = node_type.replace('_', '-');
99 var url = Drupal.settings.basePath + 'node/add/' + node_type; 100 var title = 'Create Event'; 101 // Use defaults if not provided 102 var selector = Drupal.settings.event_popup.selector; 103 //var options = Drupal.event_popup.explodeOptions(settings.event_popup.defaults); 104 var options = Drupal.event_popup.explodeOptions('width:auto;height:auto;position:[300,140]'); 105 if (url && title && selector) { 106 var event_date = $(this).attr('data-date'); 107 /* var event_date_sep = event_date.split('-'); 108 var year = event_date_sep[0]; 109 var month = event_date_sep[1]; 110 var day = event_date_sep[2]; */ 111 // Set the custom options of the dialog 112 $('#event-popup-container').dialog('option', options); 113 // Set the title of the dialog 114 $('#event-popup-container').dialog('option', 'title', title); 115 // Add a little loader into the dialog while data is loaded 116 $('#event-popup-container').html('<div class="event-popup-ajax-loader"></div>'); 117 // Change the height if it's set to auto 118 if (options.height && options.height == 'auto') { 119 $('#event-popup-container').dialog('option', 'height', 200); 120 } 121 // Use jQuery .get() to request the target page 122 123 $.get(url, {'date':event_date}, function(data) { 124 125 // Re-apply the height if it's auto to accomodate the new content 126 if (options.height && options.height == 'auto') { 127 $('#event-popup-container').dialog('option', 'height', options.height); 128 } 129 // Some trickery to make sure any inline javascript gets run. 130 // Inline javascript gets removed/moved around when passed into 131 // $() so you have to create a fake div and add the raw data into 132 // it then find what you need and clone it. Fun. 133 $('#event-popup-container').html( $( '<div></div>' ).html( data ).find( '#' + selector ).clone() ); 134 // Attach any behaviors to the loaded content 135 //Drupal.attachBehaviors($('#event-popup-container')); 136 }); 137 // Open the dialog 138 $('#event-popup-container').dialog('open'); 139 // Return false for good measure 140 return false; 141 } 142 }); 143 } 144 } 145 146 }; 147 148 149// Create a namespace for our simple dialog module 150 Drupal.event_popup = {}; 151 152 // Convert the options to an object 153 Drupal.event_popup.explodeOptions = function (opts) { 154 var options = opts.split(';'); 155 var explodedOptions = {}; 156 for (var i in options) { 157 if (options[i]) { 158 // Parse and Clean the option 159 var option = Drupal.event_popup.cleanOption(options[i].split(':')); 160 explodedOptions[option[0]] = option[1]; 161 } 162 } 163 return explodedOptions; 164 } 165 166 // Function to clean up the option. 167 Drupal.event_popup.cleanOption = function(option) { 168 // If it's a position option, we may need to parse an array 169 if (option[0] == 'position' && option[1].match(/\[.*,.*\]/)) { 170 option[1] = option[1].match(/\[(.*)\]/)[1].split(','); 171 // Check if positions need be converted to int 172 if (!isNaN(parseInt(option[1][0]))) { 173 option[1][0] = parseInt(option[1][0]); 174 } 175 if (!isNaN(parseInt(option[1][1]))) { 176 option[1][1] = parseInt(option[1][1]); 177 } 178 } 179 // Convert text boolean representation to boolean 180 if (option[1] === 'true') { 181 option[1]= true; 182 } 183 else if (option[1] === 'false') { 184 option[1] = false; 185 } 186 return option; 187 } 188 189 Drupal.event_popup.log = function(msg) { 190 if (window.console) { 191 window.console.log(msg); 192 } 193 194 } 195 196})(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.