Giter Club home page Giter Club logo

bootstrap-linkpreview's Introduction

Link preview plugin for Twitter Bootstrap

bootstrap-linkpreview.js is a JavaScript library offering a facebook-like preview for URLs. It is very simple to use and weighs just a few kilobytes.

Demo

One limitation: the same origin policy

You may want to try this library locally from a HTML file but you will face this issue:

XMLHttpRequest cannot load *…* Origin : * is not allowed by Access-Control-Allow-Origin.

This is due to the Same origin policy concept. Ajax calls can only be achieved with a URL based on the same domain they are launched on. That’s why you usually want to process link previews on your server. But sometimes you don’t have any other way than doing it on the client’s side.

Anyway don’t panic, this library is working perfectly with some conditions.

Demos

The best way to know how to use this library is to go through the examples in the folder demos. There you find two ways to get around the same origin policy.

php-proxy

This example demonstrates how to use the library from a website. It simply filters every jQuery ajax calls and echoes it on the server. That way the ajax call get the results back. To run the code, simply upload the demo on your server or run a local Apache server.

Thanks to this thread for the php script.

chrome-extension

The advantage with Google Chrome extensions is that it gives a way to bypass the same origin policy. To run it, follow these steps.

How to use bootstrap-linkpreview?

Call the library via javascript:

$('.element').linkpreview()

$('.element') can point to <input>, <textarea> or <a>. Without any parameters, this will load the URL(s) and generate the preview just after the element(s).

Options

There are a few options available for this library, e.g:

$('.element').linkpreview({
	previewContainer: "#preview-container",
	refreshButton: "#refresh-button",
	onSuccess: function(data) {
		console.log("Winner!");
	}
})
Name Type Default Description
url URL $element.val() || $element.attr('href') URL to use instead of the element's content
previewContainer Selector $element.after() Container block receiving the preview of the link
previewContainerClass String row-fluid well Class of the previewContainer
refreshButton Selector Button refreshing the preview
errorMessage String We are sorry we couldn't load the preview. The URL is invalid. Custom error message
preProcess Function Treatment to make before we load the link
onSuccess Function Callback when the data is loaded
onError Function Callback when an error occurred while processing the preview
onComplete Function Callback when a result has been received

Dependencies

All dependencies can be found under the folder deps:

License

Copyright 2013 Ekito - http://www.ekito.fr/

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

bootstrap-linkpreview's People

Contributors

lasombra avatar romainpiel avatar

Watchers

 avatar  avatar

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.