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.

            
              html(lang="zh-TW")
head
  meta(charset="UTF-8")
  title 排名系統
body
  #container
    h1 簡單排名系統
    #add_item 
      label 名稱
      input.input_item#input_name
      span.button#add 新增
    ul#items_list
        //- li test 
        //-   div.item_control 
        //-     label 同上名次
        //-     input(type="checkbox" , name="" , class="checkbox_rank")
        //-     span.button x
        //- li test 
        //-   div.item_control 
        //-     label 同上名次
        //-     input(type="checkbox" , name="")
        //-     span.button.remove x
    p#countinfo 
      span 共
      span.count
      span 個
      
    #save_items
      span.button#save_obj 儲存至本機
      span.button#read_obj 讀取本機資料
      span.button#make_hashurl 產生url
      a.button(href="https://bitly.com/" , target="_blank") 開起bitly
            
          
!
            
              $color_blue: #364f6b
$color_green: #30e3ca
$color_lightgreen: #e4f9f5
$color_verygreen: #11999e
$color_white: #f3f3f3
$color_red: #fc5185
$color_black: #40514e


html,body
  height: 100%
  // display: flex
  // justify-content: center
  // align-items: center
  background: $color_black
body
  width: 80%
  margin-left: auto
  margin-right: auto
*
  // border: 1px solid black
  font-family:  'Roboto Condensed', sans-serif , "微軟正黑體"
#container
  border: solid 4px #000
  padding: 20px
  min-width: 1024px
  min-height: 80%
  background: $color_white
  position: relative
  padding-bottom: 63px
  & h1
    margin-top: -20px
    margin-left: -20px
    margin-right: -20px
    margin-bottom: 0px
    border-bottom: solid 4px #000
    background: $color_verygreen
    color: $color_lightgreen
    height: 50px
    text-align: center
  & #add_item
    margin-top: 20px
    padding: 10px
    display: flex
    align-items: center
    border: solid 3px #000
    & .input_item
      width: 100%
      flex: 1
      & input
        box-sizing: border-box
        width: 100%
  & ul#items_list
    list-style-type: none
    padding: 0px
    & li
      position: relative
      padding: 15px
      margin-bottom: 10px
      border: solid 3px #000
      & .item_control
        display: inline-block
        position: absolute
        right: 5px

  & #save_items
    background: $color_green
    padding: 20px
    margin-left: -20px
    margin-right: -20px
    width: calc(100% - 40px)
    position: absolute
    bottom: 0px
    
.button,.button:visited
  padding: 5px
  background: $color_lightgreen
  cursor: pointer
  margin-left: 5px
  border-radius: 5px
  border: solid 3px #000
  text-decoration: none
  &:hover
    background: $color_verygreen
    color: white
    

            
          
!
            
              var list = [];
show_list();
try{
  if(location.hash){
    list = JSON.parse(decodeURI(location.hash.substring(1)));
    show_list();
  } 
 }catch(err){
  list = [];
}

$( "#items_list" ).sortable({
   cursor: 'move',
   update: function(event,ui){
     list = [];
     $('#items_list').find('li').each(function(){
        list.push({
          name: $(this).find('.objName').text() ,
          same_rank: $(this).find('.checkbox_rank').prop('checked') ? 'checked' : ''
        });
     });

     show_list();
   }
});

  $('#add').click(function(){
    if(list == null) list = [];
    list.push({
      name: $('#input_name').val() ,
      same_rank: ''
    });
    show_list();
    $('#input_name').val('');
  });
   
  $(document).on('click','.remove',function(){
    list.splice($('.remove').index(this),1);
    show_list();
  });

  $(document).on('click','.edit',function(){
    var editObj = list.splice($('.edit').index(this),1);
    editObj[0]['name'] = prompt('名稱:', editObj[0]['name']);
    list.splice( $('.edit').index(this), 0, editObj[0]);
    show_list();
  });

function show_list(){
  $('#items_list').html('');
  var echo_list = '';
  $.each(list,function(index,obj){
      var name = obj.name;
      var same_rank= obj.same_rank;
      var template = `
     <li><span class="rank"></span><span class="objName">${name}</span>
      <div class="item_control">
      <label>同上名次</label>
      <input type="checkbox" ${same_rank} class="checkbox_rank">
      <span class="button edit">編輯</span>
      <span class="button remove">x</span> 
      </div>
    </li>`;
    echo_list += template;
    
  });

  //show 個數
  $('.count').text(list.length);
    
  
  $('#items_list').html(echo_list);
   refresh_rank();
}


function refresh_rank(){
  var same_rank = 0;
  $('.rank').each(function(index,obj){
    if($(this).parent().find('.checkbox_rank').prop('checked')) same_rank++;
    $(this).html(index+1 - same_rank +'. ');
  })
  
}

$(document).on('change','.checkbox_rank',function(){
  list[$('.checkbox_rank').index(this)].same_rank = $(this).prop('checked') ? 'checked' : '';
  refresh_rank();
});

$('#save_obj').click(function(){
  localStorage.setItem('list',JSON.stringify(list));
});
 
$('#read_obj').click(function(){
  try{
    list = JSON.parse(localStorage.getItem("list")); 
    show_list();
  }catch(err){ 
    list=[];
  }
});


$('#make_hashurl').click(function(){
  prompt('Ctrl+C',location.href.replace(location.hash,'') + '#' + JSON.stringify(list));
})
            
          
!
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