<commit_before>// thumb images must have file name to the following format: imagename_800x600.jpg
// large images must have file name to the following format: imagename_1200x1000.jpg
// alt must have the following format: imagename_1200x1000.jpg

var initPhotoSwipeFromDOM = function(gallerySelector) {

    // parse slide data (url, title, size ...) from DOM elements 
    // (children of gallerySelector)
    // var parseThumbnailElements = function(el) {
    //     var thumbElements = el.childNodes,
    //         numNodes = thumbElements.length,
    //         items = [],
    //         figureEl,
    //         linkEl,
    //         size,
    //         item;

    //     for(var i = 0; i < numNodes; i++) {

    //         figureEl = thumbElements[i]; // <figure> element

    //         // include only element nodes 
    //         if(figureEl.nodeType !== 1) {
    //             continue;
    //         }

    //         // linkEl = figureEl.children[0]; // <a> element
    //         var src = figureEl.getAttribute('src');
    //         var srcs = src.split('/');
    //         var srcNoPath = srcs[srcs.length-1];
    //         var smallImageValues = srcNoPath.split('_');

    //         var alt = figureEl.getAttribute('alt');
    //         var largeImageValues = alt.split('_');
            
    //         var baseName = smallImageValues[0]

    //         var smallSize = smallImageValues[1].split('.')[0].split('x');
    //         var smallSizeX = parseInt(smallSize[0], 10)
    //         var smallSizeY = parseInt(smallSize[1], 10)

    //         var largeSize = largeImageValues[1].split('.')[0].split('x');
    //         var largeSizeX = parseInt(largeSize[0], 10)
    //         var largeSizeY = parseInt(largeSize[1], 10)
            
    //         // create slide object
    //         item = {

    //             mediumImage: {
    //                 src: src,
    //                 w: smallSizeX,
    //                 h: smallSizeY
    //             },
    //             originalImage: {
    //                 src: alt,
    //                 w: largeSizeX,
    //                 h: largeSizeY
    //             },
    //             // msrc: figureEl.getAttribute('alt'),
    //             // src: figureEl.getAttribute('href') + alt,
    //             // w: sizeX,
    //             // h: sizeY,
    //             el: figureEl  // save link to element for getThumbBoundsFn
    //         };

    //         items.push(item);
    //     }

    //     return items;
    // };

     var parseThumbnailElements = function(el) {

        var thumbElements = el.childNodes,
            numNodes = thumbElements.length,
            items = [],
            figureEl,
            linkEl,
            size,
            item;

        for(var i = 0; i < numNodes; i++) {

            figureEl = thumbElements[i]; // <figure> element

            // include only element nodes 
            if(figureEl.nodeType !== 1) {
                continue;
            }

            linkEl = figureEl; // .children[0]; // <a> element

            var img = null
            if(linkEl.children.length > 0) {
                // <img> thumbnail element, retrieving thumbnail url
                img = linkEl.children[0];
            } 

            // find the size of the image: 
            // 1. look in 'image-size' attribute with format WIDTHxHEIGHT
            // 2. otherwise use image.clientWidth, image.clientHeight
            // 3. otherwise (possible?) find in image name (src): get string after underscore, before point (to remove extension) and parse with format WIDTHxHEIGHT

            var smallImageValues = img.getAttribute('imagesize');
            var smallSize = smallImageValues != null && smallImageValues.length > 0 ? smallImageValues.split('x') : null
            var largeImageValues = linkEl.getAttribute('imagesize');
            var largeSize = largeImageValues != null && largeImageValues.length > 0 ? largeImageValues.split('x') : null

            var src = img.getAttribute('src');
            var caption = img.getAttribute('caption');

            if(smallImageValues == null || smallImageValues == '' && smallSize == null) {
                smallSize = [img.clientWidth, img.clientHeight]
            }

            if(smallImageValues == null || smallImageValues == '' && smallSize == null) {
                var srcs = src.split('/');
                var srcNoPath = srcs[srcs.length-1];
                let srcNoPaths = srcNoPath.split('_')
                smallImageValues = srcNoPaths[srcNoPaths.length - 1];
                smallSize = smallImageValues.split('.')[0].split('x');
                if(smallSize.length != 2) {
                    throw new Error('Error while reading image size in file name.')
                }
            }
            
            var alt = linkEl.getAttribute('href');

            if(largeImageValues == null || largeImageValues == '') {
                var alts = src.split('/');
                var altNoPath = srcs[srcs.length-1];
                largeImageValues = altNoPath.split('_')[1];
                largeSize = largeImageValues.split('.')[0].split('x');
            }

            // var baseName = smallImageValues[0]
            var smallSizeX = parseInt(smallSize[0], 10)
            var smallSizeY = parseInt(smallSize[1], 10)

            var largeSizeX = parseInt(largeSize[0], 10)
            var largeSizeY = parseInt(largeSize[1], 10)

            console.log('large: ' + largeSizeX + 'x' + largeSizeY + ', small: ' + smallSizeX + 'x' + smallSizeY);

            // create slide object<commit_msg>changed js<commit_after>// thumb images must have file name to the following format: imagename_800x600.jpg
// large images must have file name to the following format: imagename_1200x1000.jpg
// alt must have the following format: imagename_1200x1000.jpg

var initPhotoSwipeFromDOM = function(gallerySelector) {

    // parse slide data (url, title, size ...) from DOM elements 
    // (children of gallerySelector)
    // var parseThumbnailElements = function(el) {
    //     var thumbElements = el.childNodes,
    //         numNodes = thumbElements.length,
    //         items = [],
    //         figureEl,
    //         linkEl,
    //         size,
    //         item;

    //     for(var i = 0; i < numNodes; i++) {

    //         figureEl = thumbElements[i]; // <figure> element

    //         // include only element nodes 
    //         if(figureEl.nodeType !== 1) {
    //             continue;
    //         }

    //         // linkEl = figureEl.children[0]; // <a> element
    //         var src = figureEl.getAttribute('src');
    //         var srcs = src.split('/');
    //         var srcNoPath = srcs[srcs.length-1];
    //         var smallImageValues = srcNoPath.split('_');

    //         var alt = figureEl.getAttribute('alt');
    //         var largeImageValues = alt.split('_');
            
    //         var baseName = smallImageValues[0]

    //         var smallSize = smallImageValues[1].split('.')[0].split('x');
    //         var smallSizeX = parseInt(smallSize[0], 10)
    //         var smallSizeY = parseInt(smallSize[1], 10)

    //         var largeSize = largeImageValues[1].split('.')[0].split('x');
    //         var largeSizeX = parseInt(largeSize[0], 10)
    //         var largeSizeY = parseInt(largeSize[1], 10)
            
    //         // create slide object
    //         item = {

    //             mediumImage: {
    //                 src: src,
    //                 w: smallSizeX,
    //                 h: smallSizeY
    //             },
    //             originalImage: {
    //                 src: alt,
    //                 w: largeSizeX,
    //                 h: largeSizeY
    //             },
    //             // msrc: figureEl.getAttribute('alt'),
    //             // src: figureEl.getAttribute('href') + alt,
    //             // w: sizeX,
    //             // h: sizeY,
    //             el: figureEl  // save link to element for getThumbBoundsFn
    //         };

    //         items.push(item);
    //     }

    //     return items;
    // };

     var parseThumbnailElements = function(el) {

        var thumbElements = el.childNodes,
            numNodes = thumbElements.length,
            items = [],
            figureEl,
            linkEl,
            size,
            item;

        for(var i = 0; i < numNodes; i++) {

            figureEl = thumbElements[i]; // <figure> element

            // include only element nodes 
            if(figureEl.nodeType !== 1) {
                continue;
            }

            linkEl = figureEl; // .children[0]; // <a> element

            var img = null
            if(linkEl.children.length > 0) {
                // <img> thumbnail element, retrieving thumbnail url
                img = linkEl.children[0];
            } 

            // find the size of the image: 
            // 1. look in 'image-size' attribute with format WIDTHxHEIGHT
            // 2. otherwise use image.clientWidth, image.clientHeight
            // 3. otherwise (possible?) find in image name (src): get string after underscore, before point (to remove extension) and parse with format WIDTHxHEIGHT

            var smallImageValues = img.getAttribute('imagesize');
            var smallSize = smallImageValues != null && smallImageValues.length > 0 ? smallImageValues.split('x') : null
            var largeImageValues = linkEl.getAttribute('imagesize');
            var largeSize = largeImageValues != null && largeImageValues.length > 0 ? largeImageValues.split('x') : null

            var src = img.getAttribute('src');
            var caption = img.getAttribute('caption');

            if((smallImageValues == null || smallImageValues == '') && smallSize == null) {
                smallSize = [img.clientWidth, img.clientHeight]
            }

            if((smallImageValues == null || smallImageValues == '') && smallSize == null) {
                var srcs = src.split('/');
                var srcNoPath = srcs[srcs.length-1];
                let srcNoPaths = srcNoPath.split('_')
                smallImageValues = srcNoPaths[srcNoPaths.length - 1];
                smallSize = smallImageValues.split('.')[0].split('x');
                if(smallSize.length != 2) {
                    throw new Error('Error while reading image size in file name.')
                }
            }
            
            var alt = linkEl.getAttribute('href');

            if(largeImageValues == null || largeImageValues == '') {
                var alts = src.split('/');
                var altNoPath = srcs[srcs.length-1];
                largeImageValues = altNoPath.split('_')[1];
                largeSize = largeImageValues.split('.')[0].split('x');
            }

            // var baseName = smallImageValues[0]
            var smallSizeX = parseInt(smallSize[0], 10)
            var smallSizeY = parseInt(smallSize[1], 10)

            var largeSizeX = parseInt(largeSize[0], 10)
            var largeSizeY = parseInt(largeSize[1], 10)

            console.log('large: ' + largeSizeX + 'x' + largeSizeY + ', small: ' + smallSizeX + 'x' + smallSizeY);

            // create slide object
{'fraction_non_alphanumeric': 0.12725495423442637, 'fraction_numerical': 0.012974317959655203, 'mean_word_length': 1.4865223155103844, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3583145', 'n_tokens_mistral': 3154, 'n_tokens_neox': 2989, 'n_words': 724}