Community Documentation

Image Browser 2 API

Last updated July 18, 2009. Created by jdelaune on July 18, 2009.
Log in to edit this page.

Image Browser 2 allows developers to initiate an Image Browser pop-up window and then capture data via JSON when a user selects an image to insert. Integration requires three key parts:

This example module is called my_module.

1. Plug-in function

function my_module_imagebrowserapi($op) {
  switch ($op) {
    case 'load':
      return array(
        'url' => drupal_get_path('module', 'my_module') .'/my_module.js',
      );
      break;
  }
}

2. Javascript file

// $Id$

/**
* @file my_module.js
*
* Javascript plugin for Image Browser.
*
* Variables:
* - data.fid             [File ID]
* - data.preset          [ImageCache preset name]
* - data.link_preset     [ImageCache preset name]
* - data.link_target     [Link target]
* - data.styles          [CSS classes separated by spaces]
* - data.filepath        [Filepath to image relative to drupal]
* - data.image_url       [Full URL to image]
* - data.link_url        [Full URL to link]
*/

function ib_process_insert(data) {
  // Do whatever I want with the returned JSON data here.
 
  window.close();
}

3. Calling code

Then simply call Image Browser with your module name: <a href="/index.php?q=imagebrowser/my_module">Launch Image Browser</a>

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Developers and coders

Site Building Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here