123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class='ui'>
  <div class='multiperiodos-component'>
    <ul>
      <li data-id='1' data-start='01/01/2018' data-end='30/06/2018'>
        <div class='period'>
          <a href='#' class='edit-period' onclick='edit(this)'><i class="material-icons">mode_edit</i> 01/01/2018 a 30/06/2018</a>
          <a href='#' class='handle' tooltip='Arraste e solte para reordenar' flow='up'><i class="material-icons">drag_handle</i></a>
          <a href='#' class='delete tip_red' tooltip='Remover período' flow='up' onclick='remove(this)'><i class="material-icons">remove_circle</i></a>
        </div>
        <div class='edit hided'>
          <a href='#' class='cancel' tooltip='Cancelar edição' flow='up' onclick='cancel(this)'><i class="material-icons">clear</i></a>
          <input type='text' value='' placeholder='data inicial' class='date-start'><span>até</span> 
          <input type='text' value='' placeholder='data final' class='date-end'>
          <a href='#' class='add' tooltip='Atualizar período' flow='up' onclick='save(this)'><i class="material-icons">check_circle</i></a>
        </div>   
      </li>
      <li>
        <a href='#' class='bt-new' onclick='addNew(this,999)'>Adicionar um período <i class="material-icons">add_circle</i></a><a href='#' class='bt-new-options' onclick='openPoplist(this)'><i class="material-icons">arrow_drop_down</i></a>
      </li>
    </ul>
  </div>
</div>

  <div class='poplist hided'>
    <ul>
      <li onclick='addNew(this,0)'>Este mês</li>
      <li onclick='addNew(this,1)'>Último mês</li>
      <li onclick='addNew(this,3)'>Último trimestre</li>
      <li onclick='addNew(this,6)'>Último semestre</li>
      <li onclick='addNew(this,6)'>Último ano</li>
      <li onclick='addNew(this,999)'>Outro período</li>
    </ul>
  </div>

            
          
!
            
              /*--------------------
General Styles
---------------------*/

*,
*::before,
*::after {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
}

body {
  font-family: 'Open Sans', sans-serif;
  font-size: 12px;
  background: #f4f5f9;
}

a {
  text-decoration: none;
  display: inline-block;
}

input[type=text]{
  outline: 0;
  height: 31px;
  width: 80px;
  color: #3B3B3B;
  text-align: center;
  border: 1px solid #D6D6D6;
  border-radius: 3px;
  display: inline-block;
  background: #FFF;
  padding: 8px 8px;
  -webkit-user-select: all;
  -moz-user-select: all;
  -ms-user-select: all;
  user-select: all;
}

input[type=text]:focus {
    outline: none;
}

input::-webkit-input-placeholder {
    color: #999;
}

input:focus::-webkit-input-placeholder {
    color: transparent;
}

.ui {
  width: 305px;
  padding: 20px;
  position: absolute;
  top: 45%;
  left: 50%;
  background-color: #fff;
  
  transform: translate(-50%, -50%);
  border-radius: 6px;
  box-shadow: 0 30px 48px rgba(50,54,70,0.24);
}

.hided {
  display: none;
}

/*--------------------
Component
---------------------*/

.multiperiodos-component{
  width: 265px;
  background: #FFFFFF;
  border: 1px solid #E0E0E0;
  border-radius: 3px;
}

.multiperiodos-component ul{
  list-style: none;
  margin: 0;
  padding: 0;
}

.multiperiodos-component li{
  
}

.multiperiodos-component li:nth-child(odd){
  position: relative;
}

.multiperiodos-component li:nth-child(odd){
  background-color: #fafafa;
}

.multiperiodos-component li:last-child{
  border-top: 1px solid #ffffff;
  background-color: #f5f5f5;
  text-align: center;
}

.period, .bt-new{
  height: 35px;
  line-height: 25px;
  padding: 5px 10px;
  z-index: 0;
  transition: all 0.6s;
}

.period a{
  color: #1E88E5; /*Blue 600*/
}

.period a > i{
  font-size: 18px;
  float: left;
  margin-right: 5px;
  margin-top: 3px;
}

a.handle, a.delete{
  float: right;
}

a.handle{
  color: #9E9E9E;
  margin-top: -2px;
}

a.handle > i {
  font-size: 24px;
}

a.delete{
  color: #EF5350; /*Red 400*/
  margin-right: 5px;
  margin-top: -1px;
  visibility: hidden;
}

a.delete:hover{
  color: #D32F2F; /*Red 700*/
  cursor: pointer;
}

a.delete > i {
  font-size: 22px;
}

.period:hover > a.delete{
  visibility: visible;
}

li:first-child > .period:hover > a.delete{
  
}

.edit{
  position: absolute;
  top: 0px;
  height: 35px;
  width: 100%;
  padding: 2px 10px;
  z-index: 1;
}

a.cancel{
  color: #9E9E9E; /*Gray 500*/
  line-height: 30px;
  float: left;
  margin-right: 3px;
  margin-top: 6px;
}

a.cancel:hover{
  color: #424242; /*Gray 800*/
  cursor: pointer;
}

a.cancel > i{
  font-size: 18px;
  float: left;
  margin-right: 2px;
}

a.add{
  color: #4B2F7E; /*Purple 900*/
  float: right;
  margin-right: 5px;
  margin-top: 4px;
}

a.add:hover{
  color: #3E2F68; /*Purple 1000*/
  cursor: pointer;
}

a.add > i{
  font-size: 22px;
}

.edit > span{
  display: inline-block;
  margin: 0 3px;
}

input[type=text]{
  outline: 0;
  height: 31px;
  width: 80px;
  color: #3B3B3B;
  text-align: center;
  border: 1px solid #D6D6D6;
  border-radius: 3px;
  display: inline-block;
  background: #FFF;
  padding: 8px 8px;
  -webkit-user-select: all;
  -moz-user-select: all;
  -ms-user-select: all;
  user-select: all;
}

input[type=text]:focus {
    outline: none;
}

input::-webkit-input-placeholder {
    color: #999;
}
input:focus::-webkit-input-placeholder {
    color: transparent;
}

a.bt-new, a.bt-new-options{
  color: #4B2F7E; /*Purple 900*/
  font-weight: 700;
}

a.bt-new:hover, a.bt-new-options:hover{
  color: #3E2F68; /*Purple 1000*/
  cursor: pointer;
}

a.bt-new > i {
  font-size: 22px;
  float: left;
  margin-right: 5px;
}

a.bt-new-options {
  display: inline-block;
  float: right;
  margin-right: 5px;
  width: 45px;
  height: 35px;
  text-align: center;
  border-left: .5px solid #fff;
}

a.bt-new-options > i {
  font-size: 22px;
  margin-top: 7px;
}


/*--------------------
Poplist
---------------------*/

.poplist {
  width: 265px;
  padding: 5px 0;
  position: absolute;
  top: 20px;
  left: 20px;
  background-color: #fff;
  border-radius: 6px;
  border: 1px solid #eee;
  box-shadow: 0 15px 24px rgba(50,54,70,0.16);
  overflow: hidden;
}

.poplist ul{
  list-style: none;
  margin: 0;
  padding: 0;
}

.poplist li{
  background-color: #fff;
  color: #212121;
  line-height: 26px;
  padding: 0 10px;
}

.poplist li:hover{
  background-color: #3E2F68; /*Purple 1000*/
  color: #fff;
  line-height: 26px;
  padding: 0 10px;
  cursor: pointer;
}



/*--------------------
Tooltip
---------------------*/

[tooltip] {
  position: relative;
}

/* Applies to all tooltips */
[tooltip]::before,
[tooltip]::after {
  text-transform: none;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  user-select: none;
  pointer-events: none;
  position: absolute;
  display: none;
  opacity: 0;
}
[tooltip]::before {
  content: '';
  border: 5px solid transparent;
  z-index: 22; /* absurdity 1 */
}
[tooltip]::after {
  content: attr(tooltip); /* magic! */
  text-align: center;

  /*
    Let the content set the size of the tooltips
    but this will also keep them from being obnoxious
  */
  min-width: 88px;
  max-width: 218px;
  /* white-space: initial;
  overflow: hidden;
  text-overflow: ellipsis; */
  padding: 6px;
  border-radius: 2px;
  box-shadow: 0 1em 2em -.5em rgba(0, 0, 0, 0.35);
  background: #3E2F68;
  color: #fff;
  z-index: 21; /* absurdity 2 */
}

/* Make the tooltips respond to hover */
[tooltip]:hover::before,
[tooltip]:hover::after {
  display: block;
}

/* don't show empty tooltips */
[tooltip='']::before,
[tooltip='']::after {
  display: none !important;
}

/* FLOW: UP */
[tooltip]:not([flow])::before,
[tooltip][flow^="up"]::before {
  bottom: calc(100% + 3px);
  border-bottom-width: 0;
  border-top-color: #3E2F68;
}
[tooltip]:not([flow])::after,
[tooltip][flow^="up"]::after {
  bottom: calc(100% + 8px);
}
[tooltip]:not([flow])::before,
[tooltip]:not([flow])::after,
[tooltip][flow^="up"]::before,
[tooltip][flow^="up"]::after {
  left: 50%;
  transform: translate(-50%, -.5em);
}

a[class~="tip_red"][tooltip]::after {
  background: #F75E5E;
}
a[class~="tip_red"][tooltip][flow^="up"]::before {
  border-top-color: #F75E5E;
}

/* KEYFRAMES */
@keyframes tooltips-vert {
  to {
    opacity: .9;
    transform: translate(-50%, 0);
  }
}

@keyframes tooltips-horz {
  to {
    opacity: .9;
    transform: translate(0, -50%);
  }
}

/* FX All The Things */
[tooltip]:not([flow]):hover::before,
[tooltip]:not([flow]):hover::after,
[tooltip][flow^="up"]:hover::before,
[tooltip][flow^="up"]:hover::after {
  animation: tooltips-vert 300ms ease-out forwards;
}

            
          
!
            
              

$('.date-start').mask("00/00/0000", {placeholder: "data inicial"});
$('.date-end').mask("00/00/0000", {placeholder: "data final"});

var edit = function(el){
  var $period = $(el).parent();
  var $edit = $period.parent().find(".edit");
  var $edit_period = $period.find(".edit-period");
  
  var text_period = $edit_period.html();
  text_period = text_period.replace('<i class="material-icons">mode_edit</i> ','');
  console.log(text_period);
  var date_start = text_period.substring(0,10);
  var date_end = text_period.substring(text_period.length - 10,text_period.length);
  console.log('date_start '+date_start+' :: date_end '+date_end);
  $edit.find(".date-start").val(date_start);
  $edit.find(".date-end").val(date_end);
  
  $period.addClass("hided");
  $edit.css("position", "relative");
  $edit.removeClass("hided"); 
};

var cancel = function(el){
  var $edit = $(el).parent();
  $edit.addClass("hided");
  $edit.parent().find(".period").removeClass("hided"); 
};

var save = function(el){
  var $edit = $(el).parent();
  var $period = $edit.parent().find(".period");
  var text_period = $edit.find(".date-start").val() + ' a ' + $edit.find(".date-end").val();
  
  $edit.addClass("hided");
  $period.find(".edit-period").html('<i class="material-icons">mode_edit</i> '+text_period);
  $period.removeClass("hided"); 
};

var remove = function(el){
  var $period = $(el).parent();
  var $li = $period.parent();
  $li.remove();
  positionPoplist();
};

var addNew = function(el,month){
  var $li = $(el).parent();
  
  if(!$(el).hasClass('bt-new')){
    $li = $('.bt-new').parent();
  }
  
  var $edit = $li.find(".edit");
  
  var date_format = 'dd/MM/yyyy';
  var isCustomPeriod = false;
  
  if(month == 999){ 
    month = 0; 
    isCustomPeriod = true;
  }
  
  var first_day = new Date();
  first_day.setDate(1);
  first_day.setMonth(first_day.getMonth()-month);
  
  var last_day = new Date();
  if( month > 0 ){
    last_day.setMonth(last_day.getMonth(), 0);
  }
  var date_start = $.format.date(first_day, date_format);
  var date_end = $.format.date(last_day, date_format);
  
  console.log('date_start '+date_start+' :: date_end '+date_end);
  
  var new_id = $('.multiperiodos-component ul').length +1;
  
  var code = "<li data-id='"+ new_id +"' data-start='"+ date_start +"' data-end='"+ date_end +"'><div class='period'><a href='#' class='edit-period' onclick='edit(this)'><i class='material-icons'>mode_edit</i> "+ date_start +" a "+ date_end +"</a><a href='#' class='handle' tooltip='Arraste e solte para reordenar' flow='up'><i class='material-icons'>drag_handle</i></a><a href='#' class='delete tip_red' tooltip='Remover período' flow='up' onclick='remove(this)'><i class='material-icons'>remove_circle</i></a></div><div class='edit hided'><a href='#' class='cancel' tooltip='Cancelar edição' flow='up' onclick='cancel(this)'><i class='material-icons'>clear</i></a><input type='text' value='"+ date_start +"' placeholder='data inicial' class='date-start'><span>até</span><input type='text' value='"+ date_end +"' placeholder='data final' class='date-end'><a href='#' class='add' tooltip='Atualizar período' flow='up' onclick='save(this)'><i class='material-icons'>check_circle</i></a></div></li>";
  $(code).insertBefore($li);
  
  if( isCustomPeriod ){ 
    edit( $li.prev().find('.edit-period') ); 
  };
  
  positionPoplist();
  closePoplist();
};

var openPoplist = function(el){
  var $poplist = $('.poplist');
  
  if($poplist.hasClass('hided')){
    positionPoplist();
    $poplist.removeClass("hided");
  } else {
    closePoplist();
  }
};

var positionPoplist = function(){
  var $ui = $('.ui');
  var $poplist = $('.poplist');
  var position = $ui.position();
  var positionTop = ($ui.height() + position.top);
  $poplist.css("top",positionTop+21);
  $poplist.css("left",position.left+20); 
};

var closePoplist = function(){
  $('.poplist').addClass("hided"); 
};

$(window).on('resize', function(){
  positionPoplist();
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console