Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <style>
- #adjuntos .line {
- margin: 4px 0;
- padding: 0;
- border: 0;
- margin: 0;
- }
- #adjuntos .line td {
- padding: 4px;
- margin: 4px 0;
- border-top: 1px solid #dfdfdf;
- }
- #adjuntos {
- width: 100%;
- border: 0;
- padding: 0;
- }
- </style>
- <table id="template" style="display: none">
- <tr class="line">
- <td width="40%">
- <label><?php _e('Título del video:'); ?></label>
- <p>
- <input type="text" name="video_title[]" id="video_title[]" value="" class="title regular-text" style="width: 98%" />
- <span class="description"><?php _e('Nombre del video.'); ?></span>
- </p>
- </td>
- <td width="50%">
- <label><?php _e('URL del video:'); ?></label>
- <p>
- <input type="text" name="video_url[]" id="video_url[]" value="" class="url regular-text" style="width: 98%" />
- <span class="description"><?php _e('URL del video de Youtube.'); ?></span>
- </p>
- </td>
- <td width="10%" class="commands">
- <a rel="delete" class="button">-</a> <a rel="add" class="button">+</a>
- </td>
- </tr>
- </table>
- <table id="adjuntos">
- </table>
- <script>
- (function($)
- {
- lines = 0;
- function items_init()
- {
- <?php $videos = get_post_meta($post->ID, 'videos', true) ?>
- <?php if ( empty($videos) ) : ?>
- items_add();
- <?php else: ?>
- <?php
- // get serialized data
- $videos = unserialize($videos);
- // Show stored records
- foreach ($videos as $video) : ?>
- items_add({
- title: '<?php echo $video['title'] ?>',
- url: '<?php echo $video['url'] ?>'
- });
- <?php endforeach ?>
- <?php endif ?>
- // Delete the "-" button in first row
- $('#adjuntos tr:first-child .commands a[rel="delete"]').remove();
- }
- function items_add()
- {
- obj = $('#template tr:first-child').clone().appendTo('#adjuntos');
- lines++;
- if (arguments.length > 0) {
- options = arguments[0];
- $('.title', obj).val( options.title );
- $('.url', obj).val( options.url );
- }
- }
- $('#adjuntos').delegate('.commands a', 'click', function()
- {
- var action = $(this).attr('rel');
- var confirm_delete = true;
- // Add action
- if ('add' == action) {
- items_add();
- }
- // Delete action
- if ('delete' == action) {
- // La TR en la tabla
- var oTr = $(this).parent().parent();
- var video_name = $('.title', oTr).val();
- var video_url = $('.url', oTr).val();
- if (video_name != '' || video_url != '') {
- if ( !confirm('Are you sure you want to delete ' + video_name + '?') ) {
- confirm_delete = false;
- }
- }
- if (confirm_delete) {
- oTr.remove();
- lines--;
- }
- }
- });
- $(document).ready(function()
- {
- items_init();
- });
- })(jQuery);
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement