This file is indexed.

/usr/share/horde/ansel/js/smartmobile.js is in php-horde-ansel 3.0.5+debian0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/**
 * mobile.js - Base mobile application logic.
 *
 * Copyright 2010-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @author   Michael J. Rubinsky <mrubinsk@horde.org>
 * @category Horde
 * @license  http://www.horde.org/licenses/gpl GPL
 * @package  Ansel
 */
var AnselMobile = {

    /**
     * The currently displayed gallery
     *
     * @var object
     */
    currentGallery: null,

    /**
     * Array of images in the currentGallery
     *
     * @var array
     */
    currentImages: null,

    /**
     * The index in currentImages[] for the currently displayed image
     *
     * @var integer
     */
    currentImage: null,

    /**
     * Build a gallery list
     *
     * @param object l   The ul object to append to
     * @param object gs  A hash of the galleries
     *
     * @return a ul dom object
     */
    buildGalleryList: function(l, gs)
    {
        $.each(gs, function(k, g) {
            var item = $('<li>').attr({'ansel-gallery-id': g.id}).addClass('ansel-gallery');
            item.append($('<img>').attr({src: g.ki}).addClass('ui-li-icon'));
            item.append($('<h3>').append($('<a>').attr({href: '#'}).text(g.n)));
            item.append($('<p>').text(g.d));
            l.append(item);
        });

        return l;
    },

    /**
     * Build a <UL> node to hold the current gallery's subgalleries
     *
     * @return dom object
     */
    getSubGalleryUL: function()
    {
        return $('<ul>').addClass('anselgalleries').attr({'data-role': 'listview', 'data-inset': 'true'});
    },

    /**
     * Load the specified gallery
     *
     * @param integer id  The gallery id to return
     */
    toGallery: function(id)
    {
        HordeMobile.doAction('getGallery', {id: id}, AnselMobile.galleryLoaded);
    },

    /**
     * Display the selected image
     *
     * @param integer index  The index into the currentImages array
     */
    toImage: function(index)
    {
        var i = $('<img>').load(
            function() {
               // AnselMobile.resize($(this));
            }).attr({'src': ((AnselMobile.currentGallery.tiny) ? 'http://i.tinysrc.mobi/' : '') + AnselMobile.currentImages[index].screen});

        AnselMobile.currentImage = index;
        $('#anselimageview').empty();
        $('#anselimageview').append(i);
        $('#imageview h1').text(AnselMobile.currentImages[index].fn)
        $('#ansel-image-back .ui-btn-text').text(AnselMobile.currentGallery.n);

        if ($.mobile.activePage.attr('id') != 'imageview') {
            $.mobile.changePage($('#imageview'), { transition: 'slide' });
        }
    },

    /**
     * Callback for after a gallery is loaded.
     *
     * @param object r  The response object
     */
    galleryLoaded: function(r)
    {
        var sg, thumbs;

        if ($.mobile.currentPage != 'galleryview' &&
            AnselMobile.currentGallery && (r.id == AnselMobile.currentGallery.id)) {

            $.mobile.changePage($('#galleryview'), { transistion: 'slide' });
            return;
        }
        AnselMobile.currentGallery = r;
        $('#anselgalleryview').empty();
        if (r.sg.length) {
            sg = AnselMobile.buildGalleryList(
                $('<ul>').addClass('anselgalleries').attr({ 'data-role': 'listview', 'data-inset': 'true' }),
                r.sg);
        }
        $('#galleryview h1').text(r.n);
        thumbs = $('<ul>').addClass('thumbView');
        AnselMobile.currentImages = r.imgs;
        $.each(r.imgs, function(k, i) {
            var img = $('<li>').addClass('anselthumb').append($('<a>').attr({ 'href': '#', 'image-key': k }).append($('<img>').attr({ 'width': Ansel.conf.thumbWidth, 'height': Ansel.conf.thumbHeight, src: i.url })));
            thumbs.append(img);
        });
        if ($.mobile.activePage.attr('id') != 'galleryview') {
           $.mobile.changePage($('#galleryview'), { transistion: 'slide' });
        }
        $('#anselgalleryview').append(sg).append(thumbs).trigger('create');
        if (r.p) {
            $('#ansel-gallery-back .ui-btn-text').text(r.pn);
            $('#ansel-gallery-back').attr({'action': 'gallery', 'gallery-id': r.p});
        } else {
            $('#ansel-gallery-back .ui-btn-text').text($.mobile.page.prototype.options.backBtnText);
            $('#ansel-gallery-back').attr({'action': 'home', 'gallery-id': null});
        }
        AnselMobile.centerGrid();
    },

    /**
     * Utility function to attempt to center the thumbnail grid
     *
     * Logic unabashedly borrowed from:
     *  http://tympanus.net/codrops/2010/05/27/awesome-mobile-image-gallery-web-app/
     */
    centerGrid: function()
    {
		if ($('.anselthumb').size() > 0) {
			var perRow = Math.floor($(window).width() / 80);
			var left = Math.floor(($(window).width() - (perRow * 80)) / 2);
			$('.anselthumb').each(function(i) {
				var $this = $(this);
				if (i % perRow == 0) {
					$this.css('margin-left', left + 'px');
				} else {
					$this.css('margin-left', '0px');
				}
			});
		}
    },

    /**
     * Resize the image, based on windows width and height.
     *
     * @param dom object $image the image node
     */
    resize: function($image)
    {
		var widthMargin = 10;
		var heightMargin = 80;

		var windowH = $(window).height() - heightMargin;
		var windowW = $(window).width() - widthMargin;
		var theImage = new Image();
		theImage.src = $image.attr('src');
		var imgwidth = theImage.width;
		var imgheight = theImage.height;
		if (imgwidth > windowW || imgheight > windowH) {
			if (imgwidth > imgheight) {
				var newwidth = windowW;
				var ratio = imgwidth / windowW;
				var newheight = imgheight / ratio;
				theImage.height = newheight;
				theImage.width= newwidth;
				if (newheight > windowH) {
					var newnewheight = windowH;
					var newratio = newheight / windowH;
					var newnewwidth =newwidth / newratio;
					theImage.width = newnewwidth;
					theImage.height= newnewheight;
				}
			} else {
				var newheight = windowH;
				var ratio = imgheight / windowH;
				var newwidth = imgwidth / ratio;
				theImage.height = newheight;
				theImage.width = newwidth;
				if (newwidth > windowW) {
					var newnewwidth = windowW;
					var newratio = newwidth / windowW;
					var newnewheight =newheight / newratio;
					theImage.height = newnewheight;
					theImage.width = newnewwidth;
				}
			}
		}
		$image.css({'width': theImage.width + 'px', 'height': theImage.height + 'px'});
    },

    /**
     * Global click handler
     *
     */
    clickHandler: function(e)
    {
        var elt = $(e.target), id;

        while (elt && elt != window.document && elt.parent().length) {
            // Navigate to a gallery
            if (elt.hasClass('ansel-gallery')) {
                AnselMobile.toGallery(elt.attr('ansel-gallery-id'));
                return;
            } else if (elt.attr('image-key')) {
                AnselMobile.toImage(elt.attr('image-key'));
                return;
            }

            switch (elt.attr('id')) {
                case 'ansel-image-prev':
                    AnselMobile.prevImage();
                    return;
                case 'ansel-image-next':
                    AnselMobile.nextImage();
                    return;
                case 'ansel-gallery-back':
                    switch (elt.attr('action')) {
                    case 'home':
                        $.mobile.changePage($('#gallerylist'),
                            {
                                transition: 'slide',
                                reverse:  true
                            });
                        break;
                    case 'gallery':
                        AnselMobile.toGallery(elt.attr('gallery-id'));
                    }
                    return;
                case 'ansel-image-back':
                    window.history.back();
                    return;
            }
            elt = elt.parent();
        }
    },

    /**
     * Global swipe handler
     *
     */
    handleSwipe: function(map)
    {
        if ($.mobile.activePage.attr('id') != 'imageview') {
            return;
        }
        if (map.type == 'swipeleft') {
            AnselMobile.nextImage();
        } else if (map.type == 'swiperight') {
            AnselMobile.prevImage();
        }
    },

    nextImage: function()
    {
        AnselMobile.currentImage++;
        if (AnselMobile.currentImage >= AnselMobile.currentImages.length) {
            AnselMobile.currentImage = 0;
        }
        AnselMobile.toImage(AnselMobile.currentImage);
    },

    prevImage: function()
    {
        AnselMobile.currentImage--;
        if (AnselMobile.currentImage < 0) {
            AnselMobile.currentImage = AnselMobile.currentImages.length - 1;
        }
        AnselMobile.toImage(AnselMobile.currentImage);
    },

    /**
     * Initial document ready entry point
     *
     */
    onDocumentReady: function()
    {
        // Bind click and swipe events
        $(document).bind('vclick', AnselMobile.clickHandler);
        $('body').bind('swipeleft', AnselMobile.handleSwipe);
        $('body').bind('swiperight', AnselMobile.handleSwipe);

        var list = $('<ul>').addClass('anselgallerylist').attr({'data-role': 'listview'});
        $('#anselgallerylist').append(AnselMobile.buildGalleryList(list, Ansel.conf.galleries, 'anselgallerylist'));

        // We need to recenter the thumbnail grid, and (eventually) try to
        // resize the main image if it's  being shown.
        $(window).bind('resize', function() {
            AnselMobile.centerGrid();
            //if ($('#anselimageview').find('img').length) {
            //    AnselMobile.resize($('#anselimageview').find('img'));
            //}
        });

        $('body').bind('orientationchange', function() {
            AnselMobile.centerGrid();
//            if ($('#anselimageview').find('img').length) {
//                AnselMobile.resize($('#anselimageview').find('img'));
//            }
        });
    }
};
$(AnselMobile.onDocumentReady);