国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

Drupal 7 擴展Overlay的方法詳解?

2024-05-04 21:49:34
字體:
來源:轉載
供稿:網友

在Drupal 7 以后我們可以輕松使用類似模態框的overlay模塊來實現一個彈出層,下面我介紹2個實例,如何自定義擴展Overlay.

擴展 Overlay 模塊頭部顯示用戶頭像實例,在你的自定義模塊中加入overlay腳本JS文件,通過overlay的鉤子,代碼如下:

  1. function mymodule_overlay_child_initialize() { 
  2.   // Add our custom JavaScript. 
  3.   drupal_add_js(drupal_get_path('module''mymodule') . '/overlay-child.js'); 
  4. }然后通過Add JS 頭像路徑到header中。 
  5.  
  6. /** 
  7.  * @see hook_js_alter(). 
  8.  */ 
  9. function yourtheme_js_alter(&$javascript) { 
  10.   global $theme$user
  11.   if (isset($user->picture) && is_string($user->picture)) { 
  12.     $picture = file_load($user->picture); 
  13.   } www.survivalescaperooms.com 
  14.   elseif (isset($user->picture) && is_object($user->picture)) { 
  15.     $picture = $user->picture; 
  16.   } 
  17.   if (isset($picture) && $picture && isset($picture->uri)) { 
  18.     $filepath = file_create_url($picture->uri); 
  19.     $javascript['settings']['data'][]['user_picture'] = $filepath
  20.   } 

在overlay-child.js文件中加入以下Javascript代碼:

  1. (function ($) { 
  2.     Drupal.behaviors.yourmodule = { 
  3.         attach: function (context) { 
  4.             $('#overlay:not(.your-module-adjusted)', context).each(function() { 
  5.                 if (Drupal.settings.user_picture) { 
  6.                     $('#overlay-titlebar', this).css('padding-left', 0); 
  7.                     $('#overlay-title-wrapper', this).find('h1#overlay-title').prepend('<img src="'+Drupal.settings.user_picture+'" />'); 
  8.                 } 
  9.             }).addClass('your-module-adjusted'); 
  10.             $('.overlay .footer').hide(); 
  11.         } 
  12.     }; 
  13. })(jQuery); 

修改overlay覆蓋層的寬度和隱藏元素實例,下面這個例子向你展示如何修改overlay (覆蓋層) 內的內容,當一個指定的節點類型(test)被展示在overlay 覆蓋層,這個腳本向你展示修改overlay層的寬度為450px 和 隱藏一些不想見到的元素.

在你的模塊中同樣需要想上面的例子那樣加入overlay-child.js腳本,在overlay-child.js文件中加入以下Javascript 代碼:

  1. (function ($) { 
  2.   // Adjust the overlay dimensions. 
  3.   Drupal.behaviors.myModule = { 
  4.     attach: function (context) { 
  5.       $('#overlay:not(.mymodule-adjusted)', context).each(function() { 
  6.         var $test = $(this).find('.node-type-test'); 
  7.         if ($test.length){ 
  8.           // adjust the overlay 
  9.           $(this).css({ 
  10.             'width'     : '450px'
  11.             'min-width' : '450px' 
  12.           });www.survivalescaperooms.com 
  13.           $('.add-or-remove-shortcuts', this).hide();  // hide "add short-cut" button 
  14.           $('#branding', this).hide();  // hide branding container 
  15.         } 
  16.       }).addClass('mymodule-adjusted'); 
  17.     } 
  18.   }; 
  19. })(jQuery); 

如果你想修改所有overlay層里的布局,請找到overlay.tpl.php然后修改它.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 神木县| 绿春县| 清徐县| 新营市| 罗平县| 富裕县| 绵竹市| 方正县| 东山县| 安达市| 广西| 托克托县| 宣化县| 余庆县| 枞阳县| 教育| 尉犁县| 石阡县| 临城县| 开江县| 石柱| 阿拉善右旗| 吉林省| 水富县| 定日县| 通榆县| 章丘市| 合山市| 曲阳县| 宜兰市| 连城县| 滨海县| 镇雄县| 井冈山市| 通州市| 江城| 遂平县| 侯马市| 双桥区| 牙克石市| 招远市|