PageRenderTime 73ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/bower_components/holderjs/README.md

https://gitlab.com/thienvdt/KPIApp
Markdown | 289 lines | 195 code | 94 blank | 0 comment | 0 complexity | f5230618d9ae97b71356ab9bc455a8cc MD5 | raw file
  1. # Holder
  2. ![](http://imsky.github.io/holder/images/header.png)
  3. Holder renders image placeholders on the client side using SVG.
  4. Used by [Bootstrap](http://getbootstrap.com), thousands of [open source projects](https://github.com/search?q=holder.js+in%3Apath&type=Code&ref=searchresults), and [many other sites](https://search.nerdydata.com/search/#!/searchTerm=holder.js/searchPage=1/sort=pop).
  5. [![Build Status](https://travis-ci.org/imsky/holder.svg?branch=master)](https://travis-ci.org/imsky/holder)
  6. ## Installing
  7. * [npm](http://npmjs.com/): `npm install holderjs`
  8. * [Bower](http://bower.io/): `bower install holderjs`
  9. * [RawGit](http://rawgit.com): <https://cdn.rawgit.com/imsky/holder/master/holder.js>
  10. * [cdnjs](http://cdnjs.com/): <http://cdnjs.com/libraries/holder>
  11. * [jsDelivr](http://www.jsdelivr.com): <http://www.jsdelivr.com/#!holder>
  12. * [Rails Assets](https://rails-assets.org): `gem 'rails-assets-holderjs'`
  13. * [Meteor](http://atmospherejs.com/): `meteor add imsky:holder`
  14. * [Composer](https://packagist.org/): `php composer.phar update imsky/holder`
  15. * [NuGet](http://www.nuget.org/): `Install-Package Holder.js`
  16. ## Usage
  17. Include ``holder.js`` in your HTML:
  18. ```html
  19. <script src="holder.js"></script>
  20. ```
  21. Holder will then process all images with a specific ``src`` attribute, like this one:
  22. ```html
  23. <img src="holder.js/300x200">
  24. ```
  25. The above tag will render as a placeholder 300 pixels wide and 200 pixels tall.
  26. To avoid console 404 errors, you can use ``data-src`` instead of ``src``.
  27. ### Programmatic usage
  28. To programmatically insert a placeholder use the `run()` API:
  29. ```js
  30. var myImage = document.getElementById('myImage');
  31. Holder.run({
  32. images: myImage
  33. });
  34. ```
  35. ## Placeholder options
  36. Placeholder options are set through URL properties, e.g. `holder.js/300x200?x=y&a=b`. Multiple options are separated by the `&` character.
  37. * `theme`: The theme to use for the placeholder. Example: `holder.js/300x200?theme=sky`
  38. * `random`: Use random theme. Example: `holder.js/300x200?random=yes`
  39. * `bg`: Background color. Example: `holder.js/300x200?bg=2a2025`
  40. * `fg`: Foreground (text) color. Example: `holder.js/300x200?fg=ffffff`
  41. * `text`: Custom text. Example: `holder.js/300x200?text=Hello`
  42. * `size`: Custom text size. Defaults to `pt` units. Example: `holder.js/300x200?size=50`
  43. * `font`: Custom text font. Example: `holder.js/300x200?font=Helvetica`
  44. * `align`: Custom text alignment (left, right). Example: `holder.js/300x200?align=left`
  45. * `outline`: Draw outline and diagonals for placeholder. Example: `holder.js/300x200?outline=yes`P
  46. ### Themes
  47. ![](http://imsky.github.io/holder/images/holder_sky.png)![](http://imsky.github.io/holder/images/holder_vine.png)![](http://imsky.github.io/holder/images/holder_lava.png)
  48. Holder includes support for themes, to help placeholders blend in with your layout.
  49. There are 6 default themes: ``sky``, ``vine``, ``lava``, ``gray``, ``industrial``, and ``social``.
  50. #### Customizing themes
  51. Themes have 5 properties: ``foreground``, ``background``, ``size``, ``font`` and ``fontweight``. The ``size`` property specifies the minimum font size for the theme. The ``fontweight`` default value is ``bold``. You can create a sample theme like this:
  52. ```js
  53. Holder.addTheme("dark", {
  54. background: "#000",
  55. foreground: "#aaa",
  56. size: 11,
  57. font: "Monaco",
  58. fontweight: "normal"
  59. });
  60. ```
  61. If you have a group of placeholders where you'd like to use particular text, you can do so by adding a ``text`` property to the theme:
  62. ```js
  63. Holder.addTheme("thumbnail", { background: "#fff", text: "Thumbnail" });
  64. ```
  65. #### Using custom themes
  66. There are two ways to use custom themes with Holder:
  67. * Include theme at runtime to render placeholders already using the theme name
  68. * Include theme at any point and re-render placeholders that are using the theme name
  69. The first approach is the easiest. After you include ``holder.js``, add a ``script`` tag that adds the theme you want:
  70. ```html
  71. <script src="holder.js"></script>
  72. <script>
  73. Holder.addTheme("bright", {
  74. background: "white", foreground: "gray", size: 12
  75. });
  76. </script>
  77. ```
  78. The second approach requires that you call ``run`` after you add the theme, like this:
  79. ```js
  80. Holder.addTheme("bright", {background: "white", foreground: "gray", size: 12}).run();
  81. ```
  82. #### Using custom themes and domain on specific images
  83. You can use Holder in different areas on different images with custom themes:
  84. ```html
  85. <img data-src="example.com/100x100?theme=simple" id="new">
  86. ```
  87. ```js
  88. Holder.run({
  89. domain: "example.com",
  90. themes: {
  91. "simple": {
  92. background: "#fff",
  93. foreground: "#000",
  94. size: 12
  95. }
  96. },
  97. images: "#new"
  98. });
  99. ```
  100. #### Inserting an image with custom theme
  101. You can add a placeholder programmatically by chaining Holder calls:
  102. ```js
  103. Holder.addTheme("new", {
  104. foreground: "#ccc",
  105. background: "#000",
  106. size: 10
  107. }).addImage("holder.js/200x100?theme=new", "body").run();
  108. ```
  109. The first argument in ``addImage`` is the ``src`` attribute, and the second is a CSS selector of the parent element.
  110. ### Text
  111. Holder automatically adds line breaks to text that goes outside of the image boundaries. If the text is so long it goes out of both horizontal and vertical boundaries, the text is moved to the top. If you prefer to control the line breaks, you can add `\n` to the `text` property:
  112. ```html
  113. <img data-src="holder.js/300x200?text=Add \n line breaks \n anywhere.">
  114. ``````
  115. If you would like to disable line wrapping, set the `nowrap` option to `true`:
  116. ```html
  117. <img data-src="holder.js/300x200?text=Add \n line breaks \n anywhere.&amp;nowrap=true">
  118. ```
  119. Placeholders using a custom font are rendered using canvas by default, due to SVG's constraints on cross-domain resource linking. If you're using only locally available fonts, you can disable this behavior by setting `noFontFallback` to `true` in `Holder.run` options. However, if you need to render a SVG placeholder using an externally loaded font, you have to use the `object` tag instead of the `img` tag and add a `holderjs` class to the appropriate `link` tags. Here's an example:
  120. ```html
  121. <head>
  122. <link href="http://.../font-awesome.css" rel="stylesheet" class="holderjs">
  123. </head>
  124. <body>
  125. <object data-src="holder.js/300x200?font=FontAwesome"></object>
  126. ```
  127. **Important:** When testing locally, font URLs must have a `http` or `https` protocol defined.
  128. `<object>` placeholders work like `<img>` placeholders, with the added benefit of their DOM being able to be inspected and modified. As with `<img>` placeholders, the `data-src` attribute is more reliable than the `data` attribute.
  129. ### Fluid placeholders
  130. Specifying a dimension in percentages creates a fluid placeholder that responds to media queries.
  131. ```html
  132. <img data-src="holder.js/100px75?theme=social">
  133. ```
  134. By default, the fluid placeholder will show its current size in pixels. To display the original dimensions, i.e. 100%x75, set the ``textmode`` flag to ``literal`` like so: `holder.js/100px75?textmode=literal`.
  135. ### Automatically sized placeholders
  136. If you'd like to avoid Holder enforcing an image size, use the ``auto`` flag like so:
  137. ```html
  138. <img data-src="holder.js/200x200?auto=yes">
  139. ```
  140. The above will render a placeholder without any embedded CSS for height or width.
  141. To show the current size of an automatically sized placeholder, set the ``textmode`` flag to ``exact`` like so: `holder.js/200x200?auto=yes&textmode=exact`.
  142. ### Preventing updates on window resize
  143. Both fluid placeholders and automatically sized placeholders in exact mode are updated when the window is resized. To set whether or not a particular image is updated on window resize, you can use the `setResizeUpdate` method like so:
  144. ```js
  145. var img = $('#placeholder').get(0);
  146. Holder.setResizeUpdate(img, false);
  147. ```
  148. The above will pause any render updates on the specified image (which must be a DOM object).
  149. To enable updates again, run the following:
  150. ```js
  151. Holder.setResizeUpdate(img, true);
  152. ```
  153. This will enable updates and immediately render the placeholder.
  154. ### Background placeholders
  155. Holder can render placeholders as background images for elements with the `holderjs` class, like this:
  156. ```css
  157. #sample {background:url(?holder.js/200x200?theme=social) no-repeat}
  158. ```
  159. ```html
  160. <div id="sample" class="holderjs"></div>
  161. ```
  162. The Holder URL in CSS should have a `?` in front. Like in image placeholders, you can specify the Holder URL in a `data-background-src` attribute:
  163. ```html
  164. <div class="holderjs" data-background-src="?holder.js/300x200"></div>
  165. ```
  166. **Important:** Make sure to define a height and/or width for elements with background placeholders. Fluid background placeholders are not yet supported.
  167. ## Runtime settings
  168. Holder provides several options at runtime that affect the process of image generation. These are passed in through `Holder.run` calls.
  169. * `domain`: The domain to use for image generation. Default value: `holder.js`.
  170. * `dataAttr`: The HTML attribute used to define a fallback to the native `src` attribute. Default value: `data-src`.
  171. * `renderer`: The renderer to use. Options available: `svg`, `canvas`. Default value: `svg`.
  172. * `images`: The CSS selector used for finding `img` tags. Default value: `img`.
  173. * `objects`: The CSS selector used for finding `object` placeholders. Default value: `object`.
  174. * `bgnodes`: The CSS selector used for finding elements that have background palceholders. Default value: `body .holderjs`.
  175. * `stylenodes`: The CSS selector used for finding stylesheets to import into SVG placeholders. Default value: `head link.holderjs`.
  176. * `lineWrapRatio`: The ratio at which text will wrap from the edge of the image. Default value: `0.9`.
  177. ### Using custom settings on load
  178. You can prevent Holder from running its default configuration by executing ``Holder.run`` with your custom settings right after including ``holder.js``. However, you'll have to execute ``Holder.run`` again to render any placeholders that use the default configuration.
  179. ## Using with [lazyload.js](https://github.com/tuupola/jquery_lazyload)
  180. Holder is compatible with ``lazyload.js`` and works with both fluid and fixed-width images. For best results, run `.lazyload({skip_invisible:false})`.
  181. ## Using with Angular.js
  182. You can use Holder in Angular projects with [ng-holder](https://github.com/joshvillbrandt/ng-holder).
  183. ## Using with Meteor
  184. Because Meteor includes scripts at the top of the document by default, the DOM may not be fully available when Holder is called. For this reason, place Holder-related code in a "DOM ready" event listener.
  185. ## Browser support
  186. * Chrome
  187. * Firefox 3+
  188. * Safari 4+
  189. * Internet Explorer 9+ (with partial support for 6-8)
  190. * Opera 12+
  191. * Android (with fallback)
  192. ## License
  193. Holder is provided under the [MIT License](http://opensource.org/licenses/MIT).
  194. ## Credits
  195. Holder is a project by [Ivan Malopinsky](http://imsky.co).