项目作者: trkin

项目描述 :
JS helper to show and hide alert text
高级语言: JavaScript
项目地址: git://github.com/trkin/alert-text-show-hide.git
创建时间: 2018-04-20T10:27:16Z
项目社区:https://github.com/trkin/alert-text-show-hide

开源协议:MIT License

下载


Alert Text Show Hide

Show and hide any alert text Demo.

Installation

You can include as a module (UMD) from npm package
https://www.npmjs.com/package/alert-text-show-hide

  1. npm install alert-text-show-hide

If you are using bower than use

  1. npm add bower-npm-resolver
  2. # update your .bowerrc
  3. {
  4. "resolvers": [
  5. "bower-npm-resolver"
  6. ]
  7. }
  8. bower install npm:alert-text-show-hide --save

You can use github cdn and include with a script tag and use global object
alertTextShowHide on some element and text.

  1. <script src="./dist/element_text.js"></script>

It needs element id and text which needs to be shown:

  1. let el = document.getElementById('notice')
  2. let text = 'This is my notice'
  3. alertTextShowHide.element_text(el, text)
  4. // or in one line
  5. alertTextShowHide.element_text(document.getElementById('notice'), 'This is my notice');

You can also change delay and show speed, split message by any character and use
html tags:

  1. alertTextShowHide.element_text(
  2. document.getElementById('notice'),
  3. "<span class='error'>This is my notice</span>
  4. <a href='http://trk.in.rs'>TRK</a>",
  5. 10000,
  6. 500,
  7. ','
  8. );

Styling of alerts and notices is completelly on your side. This just show and
hide text inside it.

Example usage in Ruby on Rails

  1. <%# app/views/layouts/_alerts.html.erb
  2. <div class="alert alert-info" id="notice"></div>
  3. <div class="alert alert-danger" id="alert"></div>
  4. <script>
  5. <%=raw "alertTextShowHide.element_text(document.getElementById('notice'), '#{j notice}', 10000);" if notice %>
  6. <%=raw "alertTextShowHide.element_text(document.getElementById('alert'), '#{j alert}', 10000);" if alert %>
  7. </script>

For Bootstrap you should override padding in case when there is empty message.

  1. .alert:empty {
  2. /* remove padding for empty messages */
  3. padding: 0px;
  4. /* when innerText is cleared somehow background and border remains */
  5. background: none;
  6. border: none;
  7. }

Develop

  1. npm run build
  2. gnome-open test/index.html

Run tests

  1. ./node_modules/mocha/bin/mocha

Add new version with

  1. npm run build
  2. vi package.json # increase version
  3. git add .
  4. git commit -m 'Fix something'
  5. npm publish

Contributing

Bug reports and pull requests are welcome on GitHub at
github.com/duleorlovic/alert-text-show-hide

License

The gem is available as open source under the terms of the MIT License.

Authors

This project is designed and created at TRK INNOVATIONS llc by: