Plugin Directory

Changeset 3334620


Ignore:
Timestamp:
07/26/2025 05:21:07 PM (7 months ago)
Author:
shrikantgaur
Message:

Updated styles and functionality: added zoom, print, and download buttons

Location:
sk-epaper-manager/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sk-epaper-manager/trunk/assets/admin/epaper-admin.css

    r3325982 r3334620  
    1414  position: relative;
    1515  flex: 1 1 calc(33.33% - 10px);
     16  max-width: calc(33.33% - 10px);
    1617  border: 1px solid #ccc;
    1718  border-radius: 5px;
     
    2122.sk-epaper-image-list img {
    2223  width: 100%;
    23   height: auto;
     24  height: 250px;
     25  object-fit: cover;
    2426  display: block;
    2527  border-radius: 4px;
  • sk-epaper-manager/trunk/assets/epaper-script.js

    r3325982 r3334620  
    55const slides = document.querySelectorAll('.image-slide');
    66
     7const zoomInBtn = document.getElementById('zoom-in');
     8const zoomOutBtn = document.getElementById('zoom-out');
     9const downloadBtn = document.getElementById('download-btn');
     10const printBtn = document.getElementById('print-btn');
     11const printAllBtn = document.getElementById('print-all-btn');
     12
    713let currentIndex = 0;
    814const numImages = slides.length;
     15let zoomLevel = 1;
    916
    1017if (currentPageDisplay) {
     18  currentPageDisplay.textContent = currentIndex + 1;
     19}
     20
     21function updateSlider() {
     22  const translateX = -currentIndex * 100;
     23  imageSlider.style.transform = `translateX(${translateX}%)`;
     24  if (currentPageDisplay) {
    1125    currentPageDisplay.textContent = currentIndex + 1;
    12 }
    13 
    14 function updateSlider() {
    15     const translateX = -currentIndex * 100;
    16     imageSlider.style.transform = `translateX(${translateX}%)`;
    17     if (currentPageDisplay) {
    18         currentPageDisplay.textContent = currentIndex + 1;
    19     }
     26  }
     27  updateDownloadLink();
     28  resetZoom();
     29}
     30
     31function resetZoom() {
     32  zoomLevel = 1;
     33  slides.forEach(slide => {
     34    const img = slide.querySelector('img');
     35    img.style.transform = 'scale(1)';
     36  });
     37}
     38
     39function zoomImage(factor) {
     40  zoomLevel += factor;
     41  if (zoomLevel < 1) zoomLevel = 1;
     42  if (zoomLevel > 5) zoomLevel = 5;
     43
     44  const currentContainer = slides[currentIndex].querySelector('.zoom-container img');
     45  currentContainer.style.transform = `scale(${zoomLevel})`;
     46}
     47
     48function updateDownloadLink() {
     49  const img = slides[currentIndex].querySelector('img');
     50  downloadBtn.href = img.src;
    2051}
    2152
    2253if (nextButton && prevButton && imageSlider && slides.length > 0) {
    23     nextButton.addEventListener('click', () => {
    24         currentIndex = (currentIndex + 1) % numImages;
    25         updateSlider();
     54  nextButton.addEventListener('click', () => {
     55    currentIndex = (currentIndex + 1) % numImages;
     56    updateSlider();
     57  });
     58
     59  prevButton.addEventListener('click', () => {
     60    currentIndex = (currentIndex - 1 + numImages) % numImages;
     61    updateSlider();
     62  });
     63
     64  zoomInBtn.addEventListener('click', () => {
     65    zoomImage(0.5);
     66  });
     67
     68  zoomOutBtn.addEventListener('click', () => {
     69    zoomImage(-0.5);
     70  });
     71
     72  updateSlider();
     73} else {
     74  console.warn('Slider elements not found.');
     75}
     76
     77// Drag-to-pan
     78slides.forEach(slide => {
     79  const container = slide.querySelector('.zoom-container');
     80  let isDown = false;
     81  let startX, startY, scrollLeft, scrollTop;
     82
     83  container.addEventListener('mousedown', e => {
     84    const img = container.querySelector('img');
     85    if (zoomLevel <= 1) return;
     86    isDown = true;
     87    container.classList.add('dragging');
     88    startX = e.pageX - container.offsetLeft;
     89    startY = e.pageY - container.offsetTop;
     90    scrollLeft = container.scrollLeft;
     91    scrollTop = container.scrollTop;
     92  });
     93
     94  container.addEventListener('mouseleave', () => {
     95    isDown = false;
     96    container.classList.remove('dragging');
     97  });
     98
     99  container.addEventListener('mouseup', () => {
     100    isDown = false;
     101    container.classList.remove('dragging');
     102  });
     103
     104  container.addEventListener('mousemove', e => {
     105    if (!isDown) return;
     106    e.preventDefault();
     107    const x = e.pageX - container.offsetLeft;
     108    const y = e.pageY - container.offsetTop;
     109    const walkX = (x - startX) * 1;
     110    const walkY = (y - startY) * 1;
     111    container.scrollLeft = scrollLeft - walkX;
     112    container.scrollTop = scrollTop - walkY;
     113  });
     114});
     115
     116// ✅ Print Button Functionality
     117if (printBtn) {
     118  printBtn.addEventListener('click', () => {
     119    const currentSlide = slides[currentIndex];
     120    const img = currentSlide.querySelector('img');
     121    if (!img) return;
     122
     123    const iframe = document.createElement('iframe');
     124    iframe.style.position = 'fixed';
     125    iframe.style.width = '0';
     126    iframe.style.height = '0';
     127    iframe.style.border = '0';
     128    document.body.appendChild(iframe);
     129
     130    const iframeDoc = iframe.contentDocument || iframe.contentWindow?.document;
     131    if (!iframeDoc) return;
     132
     133    iframeDoc.open();
     134    iframeDoc.write(`
     135      <html>
     136        <head>
     137          <title>Print Page</title>
     138          <style>
     139            @page {
     140              size: A4 portrait;
     141              margin: 0;
     142            }
     143            html, body {
     144              margin: 0;
     145              padding: 0;
     146              height: 100%;
     147              width: 100%;
     148              display: flex;
     149              justify-content: center;
     150              align-items: center;
     151              background: white;
     152            }
     153            img {
     154              width: 100%;
     155              height: auto;
     156              max-height: 100%;
     157              object-fit: contain;
     158              page-break-after: avoid;
     159            }
     160          </style>
     161        </head>
     162        <body>
     163          <img src="${img.src}" onload="window.focus(); window.print(); setTimeout(() => window.close(), 100);" />
     164        </body>
     165      </html>
     166    `);
     167    iframeDoc.close();
     168  });
     169}
     170
     171if(printAllBtn) {
     172  printAllBtn.addEventListener('click', () => {
     173    const iframe = document.createElement('iframe');
     174    iframe.style.position = 'fixed';
     175    iframe.style.width = '0';
     176    iframe.style.height = '0';
     177    iframe.style.border = 'none';
     178    document.body.appendChild(iframe);
     179
     180    const doc = iframe.contentDocument || iframe.contentWindow.document;
     181
     182    doc.open();
     183    doc.write('<html><head><title>Print All</title><style>');
     184    doc.write(`
     185      @media print {
     186        @page {
     187          size: A4;
     188          margin: 0;
     189        }
     190        body {
     191          margin: 0;
     192          text-align: center;
     193        }
     194        img {
     195          page-break-after: always;
     196          max-width: 100%;
     197          max-height: 100vh;
     198        }
     199      }
     200    `);
     201    doc.write('</style></head><body>');
     202
     203    slides.forEach(slide => {
     204      const img = slide.querySelector('img');
     205      if (img) {
     206        doc.write(`<img src="${img.src}" alt="Slide" />`);
     207      }
    26208    });
    27209
    28     prevButton.addEventListener('click', () => {
    29         currentIndex = (currentIndex - 1 + numImages) % numImages;
    30         updateSlider();
    31     });
    32 
    33     updateSlider();
    34 } else {
    35     console.warn('Slider elements not found.');
    36 }
     210    doc.write('</body></html>');
     211    doc.close();
     212
     213    iframe.onload = () => {
     214      iframe.contentWindow.focus();
     215      iframe.contentWindow.print();
     216      setTimeout(() => document.body.removeChild(iframe), 1000);
     217    };
     218  });
     219}
  • sk-epaper-manager/trunk/assets/epaper-style.css

    r3325982 r3334620  
    22.single-epaper .slider-container {
    33  position: relative;
    4   /* width: 80%; */
    54  margin: 0 auto;
    65  overflow: hidden;
     
    2221  width: 100%;
    2322  height: auto;
    24   border-radius: 5px; /* Adds rounded corners to images */
    25   box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2); /* Adds a subtle box shadow to images */
     23  border-radius: 5px;
     24  box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
    2625}
    2726
     
    4039    62%,
    4140    1
    42   ); /* Adds a semi-transparent background to the arrows */
    43   color: #fff; /* Sets the arrow color to white */
    44   border-radius: 50%; /* Makes the arrows round */
     41  );
     42  color: #fff;
     43  border-radius: 50%;
    4544  width: 40px;
    4645  height: 40px;
     
    7069.epaper-top-header .epaper-col {
    7170    display: flex;
     71    flex-wrap: wrap;
    7272    justify-content: space-between;
    7373    align-items: center;
     
    8585/* Styles for each epaper-item */
    8686.epaper-item {
    87     width: calc(33% - 10px); /* Adjust as needed for your layout */
    88     /* margin-bottom: 20px; */
     87    width: calc(33% - 10px);
    8988    border: 1px solid #e0e0e0;
    9089    box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
    9190    background-color: #fff;
    92    /* padding: 15px;*/
    9391}
    9492
     
    114112    text-align: center;
    115113}
     114.epaper-content h2 a {
     115    text-decoration: none;
     116}
     117
     118.zoom-container {
     119  overflow: auto;
     120  width: 100%;
     121  height: 100%;
     122}
     123
     124.zoom-container img {
     125  display: block;
     126  margin: 0 auto;
     127  max-width: 100%;
     128  transition: transform 0.3s ease;
     129}
     130
     131.dragging {
     132  cursor: grabbing !important;
     133}
     134
     135/* Zoom & Download Button Group Styling */
     136.epaper-center {
     137    display: flex;
     138    align-items: center;
     139    justify-content: center;
     140    padding: 10px 0;
     141}
     142
     143.epaper-center .sk-control-button {
     144    background-color: #fff;
     145    border: none;
     146    color: #000;
     147    padding: 7px 8px;
     148    margin: 0 5px;
     149    font-size: 16px;
     150    border-radius: 6px;
     151    cursor: pointer;
     152    display: inline-flex;
     153    align-items: center;
     154    justify-content: center;
     155    transition: background-color 0.3s ease, transform 0.2s ease;
     156}
     157
     158.epaper-center .sk-control-button i {
     159    font-size: 18px;
     160    pointer-events: none;
     161}
     162
     163.epaper-center .sk-control-button:hover {
     164    opacity: 0.8
     165}
  • sk-epaper-manager/trunk/sk-epaper-manager.php

    r3325982 r3334620  
    8484add_action( 'wp_enqueue_scripts', SK_EPAPER_PREFIX . 'enqueue_styles' );
    8585
     86function sk_epaper_enqueue_fontawesome() {
     87    wp_enqueue_style(
     88         SK_EPAPER_PREFIX .'fontawesome',
     89        'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css',
     90        array(),
     91        '6.5.0',
     92        'all'
     93    );
     94}
     95add_action( 'wp_enqueue_scripts', SK_EPAPER_PREFIX . 'enqueue_fontawesome' );
     96
    8697function sk_epaper_enqueue_scripts() {
    8798    wp_enqueue_script(
     
    146157    ?>
    147158    <div>
    148         <label for="<?php echo SK_EPAPER_PREFIX . 'images'; ?>">ePaper Images</label>
    149159        <ul class="sk-epaper-image-list">
    150160            <?php foreach ( $image_ids as $id ) : ?>
    151161                <li data-id="<?php echo esc_attr( $id ); ?>">
    152                     <?php echo wp_get_attachment_image( $id, 'thumbnail' ); ?>
     162                    <?php echo wp_get_attachment_image( $id, 'full' ); ?>
    153163                    <span class="remove-image"><span class="text-remove-btn hidden">Remove</span></span>
    154164                </li>
  • sk-epaper-manager/trunk/templates/single-epaper.php

    r3325982 r3334620  
    99// Get stored attachment IDs
    1010$epaper_images = get_post_meta(get_the_ID(), 'sk_epaper_images', true);
    11 
    1211if (!is_array($epaper_images)) {
    1312    $epaper_images = array_filter(explode(',', $epaper_images));
     
    2726                                    <?php single_post_title('ePaper: '); ?>
    2827                                </span>
     28                            </div>
     29                        </div>
     30                        <div class="epaper-center">
     31                            <div>
     32                                <div>
     33                                    <button id="zoom-in" class="zoom-btn sk-control-button" title="Zoom In">
     34                                        <i class="fas fa-search-plus"></i>
     35                                    </button>
     36                                    <button id="zoom-out" class="zoom-btn sk-control-button" title="Zoom Out">
     37                                        <i class="fas fa-search-minus"></i>
     38                                    </button>
     39                                    <button id="print-btn" class="sk-control-button" title="Print">
     40                                        <i class="fas fa-print"></i>
     41                                    </button>
     42                                    <button id="print-all-btn" title="Print All Pages" class="sk-control-button">
     43                                      <i class="fa-solid fa-print"></i>
     44                                    </button>
     45                                    <a id="download-btn" href="#" download class="sk-control-button" title="Download">
     46                                        <i class="fas fa-download"></i>
     47                                    </a>
     48                                </div>
    2949                            </div>
    3050                        </div>
     
    5070                    <div class="epaper-col">
    5171                        <div class="slider-container">
    52                             <div class="arrow left-arrow" id="prev">&lt;</div>
     72                            <div class="arrow left-arrow" id="prev"><i class="fas fa-chevron-left"></i></div>
    5373                            <div class="image-slider">
    5474                                <?php
     
    5777                                        $attachment_id = absint($attachment_id);
    5878                                        echo '<div class="image-slide">';
    59                                         echo wp_get_attachment_image(
    60                                             $attachment_id,
    61                                             'full',
    62                                             false,
    63                                             array('alt' => get_the_title($attachment_id))
    64                                         );
    65                                         echo '</div>';
     79                                        echo '<div class="zoom-container">';
     80                                        echo wp_get_attachment_image(
     81                                            $attachment_id,
     82                                            'full',
     83                                            false,
     84                                            array('alt' => get_the_title($attachment_id))
     85                                        );
     86                                        echo '</div>';
     87                                        echo '</div>';
    6688                                    }
    6789                                }
    6890                                ?>
    6991                            </div>
    70                             <div class="arrow right-arrow" id="next">&gt;</div>
     92                            <div class="arrow right-arrow" id="next"><i class="fas fa-chevron-right"></i></div>
    7193                        </div>
    7294                    </div>
Note: See TracChangeset for help on using the changeset viewer.