Coder Social home page Coder Social logo

raafacachoeira / jquery-file-viewer Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 5.0 7 KB

An extensive jQuery Plugin for rendering files. e.g.: audio, video, html, etc

License: MIT License

JavaScript 100.00%
jquery-plugin fileviewer file-viewer audio video pdf html jquery

jquery-file-viewer's Introduction

fileViewer.js

An extensive jQuery Plugin for rendering files

Basic Usage

Declare a div target

<div id="foo" data-file-name="myFile.jpg" data-file-path="content\myfile.jpg" data-file-contenttype="image/jpg"></div>
$('#foo').fileViewer();

It is also possible to instantiate with many divs.

<div class="bar" data-file-name="myFile.jpg" data-file-path="content\myfile.jpg" data-file-contenttype="image/jpg"></div>
<div class="bar" data-file-name="anotherFile.mp3" data-file-path="content\anotherFile.mp3" data-file-contenttype="audio/mpeg"></div>
...
...
$('.bar').fileViewer();

Advanced Options

All options can be informed by html attributes or parameters options method or defaults ($.fn.fileViewer.defaults).

$('.bar').fileViewer(
    filePath: 'content\myfile.jpg',
    fileName: 'myFile.jpg', 
    fileExtension: '.jpg', //optional
    contentType: 'image/jpg', //optional: If a contentType a not filled, it will be discovered by fileExtension
    generateId: true //Sets the id to element render, e.g: id="pdf-viewer"
);

Changing defaults

It is possible changes all parameters on fileViewer plugin, even viewers properties or viewers templates

Adding new viewer support

First, we make the viewer object

$.fn.fileViewer.defaults.viewers.cad = {
    id: 'cad-viewer',
    class: 'cad-viewer',
    render: function (file) {
        return ''; /*Add here a Cad template render*/
    }
}

After, we making the map for extension file to match the new viewer

$.extend($.fn.fileViewer.defaults.map.extension, { '.dwg': 'cad'}) 

(Optional) Also, it is possible makes the map with contentType

$.extend($.fn.fileViewer.defaults.map.contentType, { 'application/acad': 'cad'}) 

Browser Support

This library passed on tests in the IE11 Browser.

License

MIT License © Rafael Cachoeira

jquery-file-viewer's People

Contributors

raafacachoeira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jquery-file-viewer's Issues

No error is reported, but the effect is not displayed

Hi, I have introduced your js in my project, but no effect appears. My project uses thymeleaf

<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('浏览培训资料')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div id="foo" data-file-name="file" data-file-path="url"></div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var url = [[${imgUrl}]];
        var file=[[${fileName}]];
        console.log(url);
        console.log(file);
        $('.foo').fileViewer();
    </script>
</body>
</html>```

File viewer's PDF toolbar not rendering on Safari

Issue Title

File viewer's PDF toolbar not rendering on Safari

Description

The file viewer toolbar is not rendering on Safari, but it renders on other browsers.

Steps to reproduce

  1. Open a web page that contains an embedded PDF file.
  2. The toolbar should appear at the top of the PDF file.
  3. Open the same web page in Safari.
  4. The toolbar will not appear.

Expected behavior

The toolbar should appear in all browsers.

Actual behavior

The toolbar only appears in browsers other than Safari.

Reproduced on

  • Safari 14.1+
  • Other browsers: Chrome, Firefox, Edge

file-viewer-pdf-no-toolbar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.