Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Commit

Permalink
[#1311] - downloads dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
samvthom16 committed Aug 14, 2018
1 parent 39dde7b commit 193cbb0
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function __construct(){
add_theme_support( 'post-thumbnails' ); // ADD THEME SUPPORT FOR THUMBNAILS
set_post_thumbnail_size( 240, 135, true ); // SET POST THUMBNAIL SIZES

/* change permalinks */
add_filter('post_type_link', function( $permalink, $post_id, $leavename ){

$post = get_post( $post_id );
Expand Down Expand Up @@ -191,14 +192,22 @@ function __construct(){
'new_item_name' => "New Akvo Foundation Group"
)
),
'foundation_type' => array(
'post_type' => array( 'foundation_member' ),
'labels' => array(
'name' => 'Akvo Foundation Type',
'add_new_item' => 'New Akvo Foundation Type',
'new_item_name' => "New Akvo Foundation Type"
)
),
);
}

function create(){

/* rewrite urls for microstory links */
global $wp_rewrite;
$microstory_structure = '/microstories/%category%/%microstory%/';
$microstory_structure = '/stories/%category%/%microstory%/';
$wp_rewrite->add_rewrite_tag( "%microstory%", '([^/]+)', "microstory=" );
$wp_rewrite->add_permastruct( 'microstory', $microstory_structure, false );

Expand Down
2 changes: 1 addition & 1 deletion code/wp-content/themes/Akvo-responsive/inc/class-akvo.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function assets(){
wp_enqueue_script('jquery-ui', get_template_directory_uri() . '/js/jquery-ui.min.js', array(), null, true);
wp_enqueue_script('akvo-common', get_template_directory_uri() . '/js/common-js.js', array('jquery'), null, true );
wp_enqueue_script('jquery-unveil', get_template_directory_uri() . '/js/jquery.unveil.js', array('jquery'), '1.0.0', true );
wp_enqueue_script('akvo-jquery', get_template_directory_uri() . '/js/akvo-jquery.js', array('jquery'), '1.2.0', true );
wp_enqueue_script('akvo-jquery', get_template_directory_uri() . '/js/akvo-jquery.js', array('jquery'), '1.2.1', true );
wp_enqueue_script('jquery-fitvids', get_template_directory_uri() . '/js/jquery.fitvids.js', array('jquery'), null, true );
wp_enqueue_script('akvo-script', get_template_directory_uri() . '/js/script.js', array('jquery'), null, true );
wp_enqueue_script('jquery-bxslider', get_template_directory_uri() . '/js/jquery.bxslider.min.js', array('jquery'), null, true );
Expand Down
28 changes: 28 additions & 0 deletions code/wp-content/themes/Akvo-responsive/js/akvo-jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,33 @@ $.fn.double_filters = function(){
});
}

$.fn.dropdown_downloads = function(){
return this.each(function(){

var $el = $( this ),
$dropdown = $el.find('select'),
$download_btn = $el.find('a[href]');

$dropdown.change( function(){

var download_link = $(this).val();

$download_btn.attr( 'href', download_link );

});

$download_btn.click( function( ev ){ /* IF THE DOWNLOAD IS CLICKED, CHECK IF THE DOWNLOAD LINK HAS BEEN ADDED */

var download_link = $download_btn.attr( 'href' );

if( download_link == '#' ){
ev.preventDefault();
}

});

});
}

$("document").ready(function() {

Expand All @@ -444,5 +471,6 @@ $("document").ready(function() {
*/
});

$('[data-behaviour~=downloads-dropdown]').dropdown_downloads();

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/*
Widget Name: Akvo Downloads Dropdown
Description: Downloads Dropdown - created for organisations page
Author: Samuel Thomas, Akvo
Author URI:
Widget URI:
Video URI:
*/

class Akvo_Downloads_Dropdown extends SiteOrigin_Widget {

function __construct() {
//Here you can do any preparation required before calling the parent constructor, such as including additional files or initializing variables.

//Call the parent constructor with the required arguments.
parent::__construct(
// The unique id for your widget.
'akvo-downloads-dropdown',

// The name of the widget for display purposes.
__('Akvo Downloads Dropdown', 'siteorigin-widgets'),

// The $widget_options array, which is passed through to WP_Widget.
// It has a couple of extras like the optional help URL, which should link to your sites help or support page.
array(
'description' => __('Downloads Dropdown - created for organisations page', 'siteorigin-widgets'),
'help' => '',
),

//The $control_options array, which is passed through to WP_Widget
array(),

//The $form_options array, which describes the form fields used to configure SiteOrigin widgets. We'll explain these in more detail later.
array(
'downloads' => array(
'type' => 'repeater',
'label' => __( 'Downloads Section' , 'siteorigin-widgets' ),
'item_name' => __( 'Repeater item', 'siteorigin-widgets' ),
'fields' => array(
'label' => array(
'type' => 'text',
'label' => __( 'Download Label', 'siteorigin-widgets' )
),
'link' => array(
'type' => 'text',
'label' => __( 'Download Link', 'siteorigin-widgets' )
),
)
)
),

//The $base_folder path string.
get_template_directory()."/so-widgets/akvo-downloads-dropdown"
);
}

function get_template_name($instance) {
return 'template';
}

function get_template_dir($instance) {
return 'templates';
}

function get_style_name($instance) {
return '';
}
}
siteorigin_widget_register('akvo-downloads-dropdown', __FILE__, 'Akvo_Downloads_Dropdown');
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php if( isset( $instance['downloads'] ) ):?>
<div class="fullWidthParag" data-behaviour='downloads-dropdown'>
<select class="articlesdropdown selectpicker" data-style="btn-primary">
<option class="selectdownloadoption" disabled selected>Click here to select your download</option>
<?php foreach( $instance['downloads'] as $download ):?>
<option value="<?php _e( $download['link'] );?>"><?php _e( $download['label'] );?></option>
<?php endforeach;?>
</select>
<a href="#" target='_blank' class="buttonblack">Download</a>
</div>
<style>

[data-behaviour~=downloads-dropdown] .buttonblack{
font-size: 16px;
-ms-box-sizing : border-box;
-moz-box-sizing : border-box;
box-sizing : border-box;
font-family : Arial, Helvetica, Geneva, sans-serif;
padding : 1em 2em;
background : transparent;
border : 2px solid #000000;
color : #000000;
-webkit-border-radius : 0em;
-moz-border-radius : 0em;
border-radius : 0em;
text-shadow : 0 1px 0 rgba(0, 0, 0, 0.05);
text-align : center;
display : inline-block;
cursor : pointer;
text-decoration : none;
line-height : 1em;
margin : 0 auto;
}

.articlesdropdown{
padding : 17px 10px;
width : 80%;
margin-right : 2%;
display : inline-block;
-webkit-appearance : none;
}
</style>
<?php endif; ?>

0 comments on commit 193cbb0

Please sign in to comment.