| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 2 if (Drupal.jsEnabled) { 3 $(document).ready(function () { 4 lastObj = false; 5 thmrSpanified = false; 6 strs = Drupal.settings.thmrStrings; 7 $('body').addClass("thmr_call").attr("id", "thmr_" + Drupal.settings.page_id); 8 $('body.thmr_call,span.thmr_call') 9 .hover( 10 function () { 11 if (themerEnabled && this.parentNode.nodeName != 'BODY' && $(this).attr('thmr_curr') != 1) { 12 $(this).css('outline', 'red solid 1px'); 13 } 14 }, 15 function () { 16 if (themerEnabled && $(this).attr('thmr_curr') != 1) { 17 $(this).css('outline', 'none'); 18 } 19 } 20 ); 21 22 var themerEnabled = 0; 23 var themerToggle = function () { 24 themerEnabled = 1 - themerEnabled; 25 $('#themer-toggle :checkbox').attr('checked', themerEnabled ? 'checked' : ''); 26 $('#themer-popup').css('display', themerEnabled ? 'block' : 'none'); 27 if (themerEnabled) { 28 document.onclick = themerEvent; 29 if (lastObj != false) { 30 $(lastObj).css('outline', '3px solid #999'); 31 } 32 if (!thmrSpanified) { 33 spanify(); 34 } 35 } 36 else { 37 document.onclick = null; 38 if (lastObj != false) { 39 $(lastObj).css('outline', 'none'); 40 } 41 } 42 }; 43 $(Drupal.settings.thmr_popup) 44 .appendTo($('body')); 45 46 $('<div id="themer-toggle"><input type="checkbox" />'+ strs.themer_info +'</div>') 47 .appendTo($('body')) 48 .click(themerToggle); 49 50 $('#themer-popup') 51 .draggable({ 52 opacity: .6, 53 handle: $('#themer-popup .topper') 54 }) 55 //.prepend(strs.toggle_throbber) 56 ; 57 58 // close box 59 $('#themer-popup .topper .close').click(function() { 60 themerToggle(); 61 }); 62 }); 63 } 64 65 /** 66 * Known issue: IE does NOT support outline css property. 67 * Solution: use another browser 68 */ 69 function themerHilight(obj) { 70 // hilight the current object (and un-highlight the last) 71 if (lastObj != false) { 72 $(lastObj).css('outline', 'none').attr('thmr_curr', 0); 73 } 74 $(obj).css('outline', '#999 solid 3px').attr('thmr_curr', 1); 75 lastObj = obj; 76 } 77 78 function themerDoIt(obj) { 79 if (thmrInPop(obj)) { 80 return true; 81 } 82 // start throbber 83 //$('#themer-popup img.throbber').show(); 84 var objs = thmrFindParents(obj); 85 if (objs.length) { 86 themerHilight(objs[0]); 87 thmrRebuildPopup(objs); 88 } 89 return false; 90 } 91 92 function spanify() { 93 $('span.thmr_call') 94 .each(function () { 95 // make spans around block elements into block elements themselves 96 var kids = $(this).children(); 97 for(i=0;i<kids.length;i++) { 98 //console.log(kids[i].style.display); 99 if ($(kids[i]).css('display') != 'inline' && $(kids[i]).is('DIV, P, ADDRESS, BLOCKQUOTE, CENTER, DIR, DL, FIELDSET, FORM, H1, H2, H3, H4, H5, H6, HR, ISINDEX, MENU, NOFRAMES, NOSCRIPT, OL, PRE, TABLE, UL, DD, DT, FRAMESET, LI, TBODY, TD, TFOOT, TH, THEAD, TR')) { 100 $(this).css('display', 'block'); 101 } 102 } 103 }); 104 thmrSpanified = true; 105 // turn off the throbber 106 //$('#themer-toggle img.throbber').hide(); 107 } 108 109 function thmrInPop(obj) { 110 //is the element in either the popup box or the toggle div? 111 if (obj.id == "themer-popup" || obj.id == "themer-toggle") return true; 112 if (obj.parentNode) { 113 while (obj = obj.parentNode) { 114 if (obj.id=="themer-popup" || obj.id == "themer-toggle") return true; 115 } 116 } 117 return false; 118 } 119 120 function themerEvent(e) { 121 if (!e) { 122 var e = window.event; 123 }; 124 if (e.target) var tg = e.target; 125 else if (e.srcElement) var tg = e.srcElement; 126 return themerDoIt(tg); 127 } 128 129 /** 130 * Find all parents with class="thmr_call" 131 */ 132 function thmrFindParents(obj) { 133 var parents = new Array(); 134 if ($(obj).hasClass('thmr_call')) { 135 parents[parents.length] = obj; 136 } 137 if (obj && obj.parentNode) { 138 while (obj = obj.parentNode) { 139 if ($(obj).hasClass('thmr_call')) { 140 parents[parents.length] = obj; 141 } 142 } 143 } 144 return parents; 145 } 146 147 /** 148 * Check to see if object is a block element 149 */ 150 function thmrIsBlock(obj) { 151 if (obj.style.display == 'block') { 152 return true; 153 } 154 else if (obj.style.display == 'inline' || obj.style.display == 'none') { 155 return false; 156 } 157 if (obj.tagName != undefined) { 158 var i = blocks.length; 159 if (i > 0) { 160 do { 161 if (blocks[i] === obj.tagName) { 162 return true; 163 } 164 } while (i--); 165 } 166 } 167 return false; 168 } 169 170 function thmrRefreshCollapse() { 171 $('#themer-popup .devel-obj-output dt').each(function() { 172 $(this).toggle(function() { 173 $(this).parent().children('dd').show(); 174 }, function() { 175 $(this).parent().children('dd').hide(); 176 }); 177 }); 178 } 179 180 /** 181 * Rebuild the popup 182 * 183 * @param objs 184 * The array of the current object and its parents. Current object is first element of the array 185 */ 186 function thmrRebuildPopup(objs) { 187 // rebuild the popup box 188 var id = objs[0].id; 189 // vars is the settings array element for this theme item 190 var vars = Drupal.settings[id]; 191 // strs is the translatable strings 192 var strs = Drupal.settings.thmrStrings; 193 var type = vars.type; 194 var key = vars.name; 195 196 // clear out the initial "click on any element" starter text 197 $('#themer-popup div.starter').empty(); 198 199 if (type == 'func') { 200 // populate the function name 201 $('#themer-popup dd.key').empty().prepend('<a href="'+ strs.api_site +'api/search/'+ strs.drupal_version +'/'+ key +'" title="'+ strs.drupal_api_docs +'">'+ key +'()</a>'); 202 $('#themer-popup dt.key-type').empty().prepend(strs.function_called); 203 } 204 else { 205 // populate the template name 206 $('#themer-popup dd.key').empty().prepend(key); 207 $('#themer-popup dt.key-type').empty().prepend(strs.template_called); 208 } 209 210 // parents 211 var parents = ''; 212 parents = strs.parents +' <span class="parents">'; 213 for(i=1;i<objs.length;i++) { 214 var pvars = Drupal.settings[objs[i].id]; 215 parents += i!=1 ? '< ' : ''; 216 // populate the parents 217 // each parent is wrapped with a span containing a 'trig' attribute with the id of the element it represents 218 parents += '<span class="parent" trig="'+ objs[i].id +'">'+ pvars.name +'</span> '; 219 } 220 parents += '</span>'; 221 // stick the parents spans in the #parents div 222 $('#themer-popup #parents').empty().prepend(parents); 223 $('#themer-popup span.parent').click(function() { 224 // make them clickable 225 $('#'+ $(this).attr('trig')).each(function() { themerDoIt(this) }); 226 }) 227 .hover(function() { 228 // make them highlight their element on mouseover 229 $('#'+ $(this).attr('trig')).trigger('mouseover'); 230 }, 231 function() { 232 // and unhilight on mouseout 233 $('#'+ $(this).attr('trig')).trigger('mouseout'); 234 }); 235 236 if (vars == undefined) { 237 // if there's no item in the settings array for this element 238 $('#themer-popup dd.candidates').empty(); 239 $('#themer-popup dd.preprocessors').empty(); 240 $('#themer-popup div.attributes').empty(); 241 $('#themer-popup div.used').empty(); 242 $('#themer-popup div.duration').empty(); 243 } 244 else { 245 $('#themer-popup div.duration').empty().prepend('<span class="dt">' + strs.duration + '</span>' + vars.duration + ' ms'); 246 $('#themer-popup dd.candidates').empty().prepend(vars.candidates.join('<span class="delimiter"> < </span>')); 247 var uri = Drupal.settings.devel_themer_uri + '/' + id; 248 if (type == 'func') { 249 if (vars.candidates != undefined && vars.candidates.length != 0) { 250 // populate the candidates 251 $('#themer-popup dt.candidates-type').empty().prepend(strs.candidate_functions); 252 // empty the preprocessors - functions don't have them :( 253 $('#themer-popup dd.preprocessors').empty(); 254 $('#themer-popup dt.preprocessors-type').empty(); 255 } 256 $('#themer-popup div.attributes').empty().load(uri, {}, function() { 257 $(this).prepend('<h4>'+ strs.function_arguments + '</h4>'); 258 }); 259 $('#themer-popup div.used').empty(); 260 } 261 else { 262 $('#themer-popup dt.candidates-type').empty().prepend(strs.candidate_files); 263 $('#themer-popup dd.preprocessors').empty().prepend(vars.preprocessors.join('<span class="delimiter"> + </span>')); 264 $('#themer-popup dt.preprocessors-type').empty().prepend(strs.preprocessors); 265 $('#themer-popup div.attributes').empty().load(uri, {}, function(){ 266 $(this).prepend('<h4>'+ strs.template_variables + '</h4>'); 267 }); 268 $('#themer-popup div.used').empty().prepend('<dt>'+ strs.file_used +'</a></dt><dd><a href="'+ strs.source_link + vars.used +'" title="'+ strs.source_link_title +'">'+ vars.used +'</a></dd>'); 269 } 270 thmrRefreshCollapse(); 271 } 272 // stop throbber 273 //$('#themer-popup img.throbber').hide(); 274 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |