Skip to content

Commit 6c29b15

Browse files
committed
[add] core widgetkit ex code
1 parent 450728a commit 6c29b15

14 files changed

+2079
-2
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/* ==========================================================================
2+
3+
jQuery FormChimp - v1.2.1
4+
A customizable MailChimp ajax plugin for jQuery
5+
Fabio Quarantini - @febba
6+
http://www.fabioquarantini.com/formchimp/
7+
8+
========================================================================== */
9+
10+
11+
;( function( $, window, document, undefined ) {
12+
13+
$.fn.formchimp = function( settings ) {
14+
15+
var $form = $(this);
16+
var $body = $('body');
17+
var actionUrl = $form.attr('action').replace('/post?', '/post-json?').concat('&c=?');
18+
var $button = $form.find('[type="submit"]');
19+
var defaults = {
20+
'appendElement': $form, // Declare where the new element, containing the messages from Mailchimp will be appended to.
21+
'buttonSelector': $button, // Set the button selector.
22+
'buttonText': '', // The message to be written on the submit button after a successful subscription.
23+
'debug': false, // Activate debug message in console.
24+
'errorMessage': '', // Set custom error message given when return an error.
25+
'onMailChimpSuccess': function() {}, // Callback that fires on success.
26+
'onMailChimpError': function() {}, // Callback that fires on errors.
27+
'responseClass': "mc-response", // Declare custom element in page for message output. (Set different classes for multiple sign-up forms)
28+
'successMessage': '', // Set a custom success message.
29+
'url': actionUrl, // The mailchip list subscription url, to get the JSONP address just change `post` to `post-json` and append `&c=?` at the end.
30+
};
31+
var originalButtonText = defaults.buttonSelector.text();
32+
33+
// Merge default whith settings
34+
$.extend( defaults, settings );
35+
36+
// On submit
37+
$( $form ).on( 'submit', function( event ) {
38+
39+
// Disable default action of submit
40+
event.preventDefault();
41+
42+
// Remove status class and add the loading
43+
$body.removeClass('mc-success mc-error').addClass('mc-loading');
44+
45+
// If the response container does not exists
46+
if ( $("." + defaults.responseClass).length === 0 ) {
47+
48+
// Add response container to append element
49+
$responseContainer = $('<div/>').addClass( defaults.responseClass ).appendTo( defaults.appendElement );
50+
51+
} else {
52+
53+
// Remove old message
54+
$responseContainer.html('');
55+
56+
}
57+
58+
// Perform an Ajax request
59+
$.ajax({
60+
61+
url: defaults.url,
62+
data: $form.serialize(),
63+
dataType: 'jsonp'
64+
65+
}).done( function( data ) {
66+
67+
// If debug is active
68+
if ( defaults.debug ) {
69+
70+
// Log in cosole the Mailchimp data
71+
console.log( JSON.stringify(data) );
72+
}
73+
74+
// Save the Mailchimp data
75+
var responseMessage = data.msg;
76+
77+
// If the message start with a number and contains "-"
78+
if( !isNaN(responseMessage.charAt(0)) && responseMessage.charAt(2) === '-' ) {
79+
80+
// Remove first 3 characters
81+
responseMessage = responseMessage.substring(3);
82+
83+
}
84+
85+
// Add status class and remove the loading class
86+
$body.addClass('mc-' + data.result).removeClass('mc-loading');
87+
88+
// If the Mailchimp result is success
89+
if ( data.result === 'success' ) {
90+
91+
// If success message parameter is not empty
92+
if ( defaults.successMessage !== '' ) {
93+
94+
// Replace the default success message with parameter
95+
responseMessage = defaults.successMessage;
96+
97+
}
98+
99+
// If button text parameter is not empty
100+
if ( defaults.buttonText !== '' ) {
101+
102+
// Replace the default button text with parameter
103+
defaults.buttonSelector.text(defaults.buttonText);
104+
105+
}
106+
107+
// Add event on error
108+
$(document).trigger('mailChimpSuccess');
109+
110+
// Run callback
111+
defaults.onMailChimpSuccess.call();
112+
113+
} else { // If there is an error
114+
115+
// If error message parameter is not empty
116+
if ( defaults.errorMessage !== '' ) {
117+
118+
// Replace the default error message with parameter
119+
responseMessage = defaults.errorMessage;
120+
121+
}
122+
123+
// If button text parameter is not empty
124+
if ( defaults.buttonText !== '' ) {
125+
126+
// Replace the default button text with the original text
127+
defaults.buttonSelector.text(originalButtonText);
128+
129+
}
130+
131+
// Add event on error
132+
$(document).trigger('mailChimpError');
133+
134+
// Run callback
135+
defaults.onMailChimpError.call();
136+
137+
}
138+
139+
// Show the message
140+
$responseContainer.html(responseMessage);
141+
142+
});
143+
144+
});
145+
146+
};
147+
148+
})( jQuery, window, document );

grid-stack-ex/assets/jquery.formchimp.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(function ($) {
2+
/**
3+
* @function
4+
* @property {object} jQuery plugin which runs handler function once specified element is inserted into the DOM
5+
* @param {function} handler A function to execute at the time when the element is inserted
6+
* @param {bool} shouldRunHandlerOnce Optional: if true, handler is unbound after its first invocation
7+
* @example $(selector).waitUntilExists(function);
8+
*/
9+
10+
$.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild) {
11+
var found = 'found';
12+
var $this = $(this.selector);
13+
var $elements = $this.not(function () { return $(this).data(found); }).each(handler).data(found, true);
14+
15+
if (!isChild)
16+
{
17+
(window.waitUntilExists_Intervals = window.waitUntilExists_Intervals || {})[this.selector] =
18+
window.setInterval(function () { $this.waitUntilExists(handler, shouldRunHandlerOnce, true); }, 500);
19+
}
20+
else if (shouldRunHandlerOnce && $elements.length)
21+
{
22+
window.clearInterval(window.waitUntilExists_Intervals[this.selector]);
23+
}
24+
25+
return $this;
26+
};
27+
}(jQuery));

grid-stack-ex/assets/jquery.wait.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grid-stack-ex/assets/marked.min.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grid-stack-ex/assets/replacer.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
This code is used for replacements of data in string, usually after $translate service
3+
*/
4+
"use strict";
5+
/*
6+
data - original string
7+
expression - associative array, key => value.
8+
The function replaces all occurances of %key% in data into value.
9+
Returns the string with all replacements done.
10+
*/
11+
function replaceTransAll(data,expression){
12+
for (var key in expression)
13+
data=data.replace('%'+key+'%',expression[key]);
14+
return data;
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"use strict";function replaceTransAll(r,e){for(var n in e)r=r.replace("%"+n+"%",e[n]);return r}

grid-stack-ex/assets/underscore-min.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grid-stack-ex/assets/underscore-min.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)