').css('position', 'absolute').css('z-index', '9999999').css('width', this.px(elem.outerWidth())).css('height', this.px(elem.outerHeight())).css('top', this.px(p.top)).css('left', this.px(p.left)).css('background-color', '');
+ document.body.appendChild(block.get(0));
+ setTimeout((function() {
+ return block.remove();
+ }), 400);
+ return false;
+ };
-SelectorGadget.prototype.clearEverything = function(e) {
- var self = (e && e.data && e.data.self) || this;
- self.clearSelected();
- self.resetOutputs();
-};
+ SelectorGadget.prototype.setMode = function(mode) {
+ if (mode === 'browse') {
+ this.removeEventHandlers();
+ } else if (mode === 'interactive') {
+ this.setupEventHandlers();
+ }
+ return this.clearSelected();
+ };
-SelectorGadget.prototype.resetOutputs = function() {
- this.setPath();
-};
+ SelectorGadget.prototype.suggestPredicted = function(prediction) {
+ var count;
+ if (prediction && prediction !== '') {
+ count = 0;
+ jQuerySG(prediction).each(function() {
+ count += 1;
+ if (!jQuerySG(this).hasClass('selectorgadget_selected') && !jQuerySG(this).hasClass('selectorgadget_ignore') && !jQuerySG(this).hasClass('selectorgadget_rejected')) {
+ return jQuerySG(this).addClass('selectorgadget_suggested');
+ }
+ });
+ if (this.clear_button) {
+ if (count > 0) {
+ return this.clear_button.attr('value', 'Clear (' + count + ')');
+ } else {
+ return this.clear_button.attr('value', 'Clear');
+ }
+ }
+ }
+ };
-SelectorGadget.prototype.clearSuggested = function() {
- jQuerySG('.selectorgadget_suggested').removeClass('selectorgadget_suggested');
- if (this.clear_button) this.clear_button.attr('value', 'Clear');
-};
+ SelectorGadget.prototype.setPath = function(prediction) {
+ if (prediction && prediction.length > 0) {
+ return this.path_output_field.value = prediction;
+ } else {
+ return this.path_output_field.value = 'No valid path found.';
+ }
+ };
-SelectorGadget.prototype.showHelp = function() {
- alert("(Better help coming soon! Please visit http://selectorgadget.com! Please report bugs!)\n\nClick on a page element that you would like your selector to match (it will turn green). SelectorGadget will then generate a minimal CSS selector for that element, and will highlight (yellow) everything that is matched by the selector. Now click on a highlighted element to remove it from the selector (red), or click on an unhighlighted element to add it to the selector. Through this process of selection and rejection, SelectorGadget helps you to come up with the perfect CSS selector for your needs.\n\nHolding 'shift' while moving the mouse will let you select elements inside of other selected ones.");
-};
+ SelectorGadget.prototype.refreshFromPath = function(e) {
+ var path, self;
+ self = (e && e.data && e.data.self) || this;
+ path = self.path_output_field.value;
+ self.clearSelected();
+ self.suggestPredicted(path);
+ return self.setPath(path);
+ };
-SelectorGadget.prototype.showOptions = function() {
- alert("hi!");
-};
+ SelectorGadget.prototype.showXPath = function(e) {
+ var path, self;
+ self = (e && e.data && e.data.self) || this;
+ path = self.path_output_field.value;
+ if (path === 'No valid path found.') {
+ return;
+ }
+ return prompt("The CSS selector '" + path + "' as an XPath is shown below. Please report any bugs that you find with this converter.", self.prediction_helper.cssToXPath(path));
+ };
-SelectorGadget.prototype.useRemoteInterface = function() {
- return (window.sg_options && window.sg_options.remote_interface);
-};
+ SelectorGadget.prototype.clearSelected = function(e) {
+ var self;
+ self = (e && e.data && e.data.self) || this;
+ self.selected = [];
+ self.rejected = [];
+ jQuerySG('.selectorgadget_selected').removeClass('selectorgadget_selected');
+ jQuerySG('.selectorgadget_rejected').removeClass('selectorgadget_rejected');
+ self.removeBorders();
+ return self.clearSuggested();
+ };
-SelectorGadget.prototype.updateRemoteInterface = function(data_obj) {
- this.addScript(this.composeRemoteUrl(window.sg_options.remote_interface, data_obj));
-};
+ SelectorGadget.prototype.clearEverything = function(e) {
+ var self;
+ self = (e && e.data && e.data.self) || this;
+ self.clearSelected();
+ return self.resetOutputs();
+ };
-SelectorGadget.prototype.composeRemoteUrl = function(url, data_obj) {
- var params = (url.split("?")[1] && url.split("?")[1].split("&")) || [];
- params.push("t=" + (new Date()).getTime());
- params.push("url=" + encodeURIComponent(window.location.href));
- if (data_obj) {
- for (var key in data_obj) {
- params.push(encodeURIComponent(key) + '=' + encodeURIComponent(data_obj[key]));
- }
- }
- if (this.remote_data) {
- for (var key in this.remote_data) {
- params.push(encodeURIComponent("data[" + key + "]") + '=' + encodeURIComponent(this.remote_data[key]));
- }
- }
- return (url.split("?")[0] + "?" + params.join("&"));
-};
+ SelectorGadget.prototype.resetOutputs = function() {
+ return this.setPath();
+ };
-SelectorGadget.prototype.addScript = function(src) {
- var s = document.createElement('script');
- s.setAttribute('type', 'text/javascript');
- s.setAttribute('src', src);
- var head = document.getElementsByTagName('head')[0];
- if (head) {
- head.appendChild(s);
- } else {
- document.body.appendChild(s);
- }
-};
+ SelectorGadget.prototype.clearSuggested = function() {
+ jQuerySG('.selectorgadget_suggested').removeClass('selectorgadget_suggested');
+ if (this.clear_button) {
+ return this.clear_button.attr('value', 'Clear');
+ }
+ };
-SelectorGadget.prototype.makeInterface = function() {
- this.sg_div = jQuerySG('
').attr('id', 'selectorgadget_main').addClass('selectorgadget_bottom').addClass('selectorgadget_ignore');
+ SelectorGadget.prototype.showHelp = function() {
+ return alert("(Better help coming soon! Please visit http://selectorgadget.com! Please report bugs!)\n\nClick on a page element that you would like your selector to match (it will turn green). SelectorGadget will then generate a minimal CSS selector for that element, and will highlight (yellow) everything that is matched by the selector. Now click on a highlighted element to remove it from the selector (red), or click on an unhighlighted element to add it to the selector. Through this process of selection and rejection, SelectorGadget helps you to come up with the perfect CSS selector for your needs.\n\nHolding 'shift' while moving the mouse will let you select elements inside of other selected ones.");
+ };
- if (this.useRemoteInterface()) {
- this.path_output_field = { value: null };
- this.remote_data = {};
- this.updateRemoteInterface();
- } else {
- this.makeStandardInterface();
- }
+ SelectorGadget.prototype.showOptions = function() {
+ return alert("hi!");
+ };
- jQuerySG('body').append(this.sg_div);
-};
+ SelectorGadget.prototype.useRemoteInterface = function() {
+ return window.sg_options && window.sg_options.remote_interface;
+ };
-SelectorGadget.prototype.makeStandardInterface = function() {
- var self = this;
- var path = jQuerySG('').attr('id', 'selectorgadget_path_field').addClass('selectorgadget_ignore').addClass('selectorgadget_input_field').keydown(function(e) {
- if (e.keyCode == 13) {
- return self.refreshFromPath(e);
- }
- }).focus(function() { jQuerySG(this).select(); });
- this.sg_div.append(path);
- this.clear_button = jQuerySG('').bind("click", {'self': this}, this.clearEverything).addClass('selectorgadget_ignore').addClass('selectorgadget_input_field');
- this.sg_div.append(this.clear_button);
- this.sg_div.append(jQuerySG('').click(function() {
- if (self.sg_div.hasClass('selectorgadget_top')) {
- self.sg_div.removeClass('selectorgadget_top').addClass('selectorgadget_bottom');
- } else {
- self.sg_div.removeClass('selectorgadget_bottom').addClass('selectorgadget_top');
- }
- }).addClass('selectorgadget_ignore').addClass('selectorgadget_input_field'));
+ SelectorGadget.prototype.updateRemoteInterface = function(data_obj) {
+ return this.addScript(this.composeRemoteUrl(window.sg_options.remote_interface, data_obj));
+ };
- this.sg_div.append(jQuerySG('').bind("click", {'self': this}, this.showXPath).addClass('selectorgadget_ignore').addClass('selectorgadget_input_field'));
+ SelectorGadget.prototype.composeRemoteUrl = function(url, data_obj) {
+ var key, params;
+ params = (url.split("?")[1] && url.split("?")[1].split("&")) || [];
+ params.push("t=" + (new Date()).getTime());
+ params.push("url=" + encodeURIComponent(window.location.href));
+ if (data_obj) {
+ for (key in data_obj) {
+ params.push(encodeURIComponent(key) + '=' + encodeURIComponent(data_obj[key]));
+ }
+ }
+ if (this.remote_data) {
+ for (key in this.remote_data) {
+ params.push(encodeURIComponent("data[" + key + "]") + '=' + encodeURIComponent(this.remote_data[key]));
+ }
+ }
+ return url.split("?")[0] + "?" + params.join("&");
+ };
- this.sg_div.append(jQuerySG('').bind("click", {'self': this}, this.showHelp).addClass('selectorgadget_ignore').addClass('selectorgadget_input_field'));
+ SelectorGadget.prototype.addScript = function(src) {
+ var head, s;
+ s = document.createElement('script');
+ s.setAttribute('type', 'text/javascript');
+ s.setAttribute('src', src);
+ head = document.getElementsByTagName('head')[0];
+ if (head) {
+ return head.appendChild(s);
+ } else {
+ return document.body.appendChild(s);
+ }
+ };
+
+ SelectorGadget.prototype.makeInterface = function() {
+ this.sg_div = jQuerySG('
').attr('id', 'selectorgadget_main').addClass('selectorgadget_bottom').addClass('selectorgadget_ignore');
+ if (this.useRemoteInterface()) {
+ this.path_output_field = {
+ value: null
+ };
+ this.remote_data = {};
+ this.updateRemoteInterface();
+ } else {
+ this.makeStandardInterface();
+ }
+ return jQuerySG('body').append(this.sg_div);
+ };
- this.sg_div.append(jQuerySG('').bind("click", {'self': this}, this.showOptions).addClass('selectorgadget_ignore').addClass('selectorgadget_input_field'));
+ SelectorGadget.prototype.makeStandardInterface = function() {
+ var path, self;
+ self = this;
+ path = jQuerySG('').attr('id', 'selectorgadget_path_field').addClass('selectorgadget_ignore').addClass('selectorgadget_input_field').keydown(function(e) {
+ if (e.keyCode === 13) {
+ return self.refreshFromPath(e);
+ }
+ }).focus(function() {
+ return jQuerySG(this).select();
+ });
+ this.sg_div.append(path);
+ this.clear_button = jQuerySG('').bind("click", {
+ 'self': this
+ }, this.clearEverything).addClass('selectorgadget_ignore').addClass('selectorgadget_input_field');
+ this.sg_div.append(this.clear_button);
+ this.sg_div.append(jQuerySG('').click(function() {
+ if (self.sg_div.hasClass('selectorgadget_top')) {
+ return self.sg_div.removeClass('selectorgadget_top').addClass('selectorgadget_bottom');
+ } else {
+ return self.sg_div.removeClass('selectorgadget_bottom').addClass('selectorgadget_top');
+ }
+ }).addClass('selectorgadget_ignore').addClass('selectorgadget_input_field'));
+ this.sg_div.append(jQuerySG('').bind("click", {
+ 'self': this
+ }, this.showXPath).addClass('selectorgadget_ignore').addClass('selectorgadget_input_field'));
+ this.sg_div.append(jQuerySG('').bind("click", {
+ 'self': this
+ }, this.showHelp).addClass('selectorgadget_ignore').addClass('selectorgadget_input_field'));
+ this.sg_div.append(jQuerySG('').bind("click", {
+ 'self': this
+ }, this.showOptions).addClass('selectorgadget_ignore').addClass('selectorgadget_input_field'));
+ this.sg_div.append(jQuerySG('').bind("click", {
+ 'self': this
+ }, this.unbindAndRemoveInterface).addClass('selectorgadget_ignore').addClass('selectorgadget_input_field'));
+ return this.path_output_field = path.get(0);
+ };
- this.sg_div.append(jQuerySG('').bind("click", {'self': this}, this.unbindAndRemoveInterface).addClass('selectorgadget_ignore').addClass('selectorgadget_input_field'));
+ SelectorGadget.prototype.removeInterface = function(e) {
+ this.sg_div.remove();
+ return this.sg_div = null;
+ };
- // this.sg_div.append(
- // jQuerySG('Show XPath').bind("click", {'self': this}, this.showXPath)
- // );
+ SelectorGadget.prototype.unbind = function(e) {
+ var self;
+ self = (e && e.data && e.data.self) || this;
+ self.unbound = true;
+ self.removeBorderFromDom();
+ return self.clearSelected();
+ };
- this.path_output_field = path.get(0);
-};
+ SelectorGadget.prototype.unbindAndRemoveInterface = function(e) {
+ var self;
+ self = (e && e.data && e.data.self) || this;
+ self.unbind();
+ return self.removeInterface();
+ };
-SelectorGadget.prototype.removeInterface = function(e) {
- this.sg_div.remove();
- this.sg_div = null;
-};
+ SelectorGadget.prototype.setOutputMode = function(e, output_mode) {
+ var self;
+ self = (e && e.data && e.data.self) || this;
+ return self.output_mode = (e && e.data && e.data.mode) || output_mode;
+ };
-SelectorGadget.prototype.unbind = function(e) {
- var self = (e && e.data && e.data.self) || this;
- self.unbound = true;
- self.removeBorderFromDom();
- self.clearSelected();
-};
+ SelectorGadget.prototype.rebind = function() {
+ this.unbound = false;
+ this.clearEverything();
+ return this.setupBorders();
+ };
-SelectorGadget.prototype.unbindAndRemoveInterface = function(e) {
- var self = (e && e.data && e.data.self) || this;
- self.unbind();
- self.removeInterface();
-};
+ SelectorGadget.prototype.rebindAndMakeInterface = function() {
+ this.makeInterface();
+ return this.rebind();
+ };
-SelectorGadget.prototype.setOutputMode = function(e, output_mode) {
- var self = (e && e.data && e.data.self) || this;
- self.output_mode = (e && e.data && e.data.mode) || output_mode;
-};
+ SelectorGadget.prototype.randBetween = function(a, b) {
+ return Math.floor(Math.random() * b) + a;
+ };
-SelectorGadget.prototype.rebind = function() {
- this.unbound = false;
- this.clearEverything();
- this.setupBorders();
-};
+ SelectorGadget.prototype.analytics = function() {
+ var cookie, random, referer, today, urchinUrl, uservar, utmac, utmhn, utmn, utmp;
+ utmac = 'UA-148948-9';
+ utmhn = encodeURIComponent('www.selectorgadget.com');
+ utmn = this.randBetween(1000000000, 9999999999);
+ cookie = this.randBetween(10000000, 99999999);
+ random = this.randBetween(1000000000, 2147483647);
+ today = Math.round(new Date().getTime() / 1000.0);
+ referer = encodeURIComponent(window.location.href);
+ uservar = '-';
+ utmp = 'sg';
+ urchinUrl = 'http://www.google-analytics.com/__utm.gif?utmwv=1&utmn=' + utmn + '&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn=' + utmhn + '&utmr=' + referer + '&utmp=' + utmp + '&utmac=' + utmac + '&utmcc=__utma%3D' + cookie + '.' + random + '.' + today + '.' + today + '.' + today + '.2%3B%2B__utmb%3D' + cookie + '%3B%2B__utmc%3D' + cookie + '%3B%2B__utmz%3D' + cookie + '.' + today + '.2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D' + cookie + '.' + uservar + '%3B';
+ return document.body.appendChild(jQuerySG('').attr('src', urchinUrl).get(0));
+ };
-SelectorGadget.prototype.rebindAndMakeInterface = function() {
- this.makeInterface();
- this.rebind();
-};
+ return SelectorGadget;
-SelectorGadget.prototype.randBetween = function(a, b) {
- return Math.floor(Math.random() * b) + a;
-};
+ })();
-SelectorGadget.prototype.analytics = function() {
- // http://www.vdgraaf.info/google-analytics-without-javascript.html
- var utmac = 'UA-148948-9';
- var utmhn = encodeURIComponent('www.selectorgadget.com');
- var utmn = this.randBetween(1000000000,9999999999); //random request number
- var cookie = this.randBetween(10000000,99999999); //random cookie number
- var random = this.randBetween(1000000000,2147483647); //number under 2147483647
- var today = Math.round(new Date().getTime()/1000.0);
- var referer = encodeURIComponent(window.location.href); //referer url
- var uservar='-'; //enter your own user defined variable
- var utmp='sg';
-
- var urchinUrl = 'http://www.google-analytics.com/__utm.gif?utmwv=1&utmn=' + utmn + '&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn=' + utmhn + '&utmr=' + referer + '&utmp=' + utmp + '&utmac=' + utmac + '&utmcc=__utma%3D' + cookie + '.' + random + '.' + today + '.' + today + '.' + today + '.2%3B%2B__utmb%3D' + cookie + '%3B%2B__utmc%3D' + cookie + '%3B%2B__utmz%3D' + cookie + '.' + today + '.2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D' + cookie + '.' + uservar + '%3B';
- document.body.appendChild(jQuerySG('').attr('src', urchinUrl).get(0));
-};
+}).call(this);
/*
The MIT License
diff --git a/lib/js/core/core.js b/lib/js/core/core.js
deleted file mode 100644
index 8041307..0000000
--- a/lib/js/core/core.js
+++ /dev/null
@@ -1,550 +0,0 @@
-/*
- The MIT License
-
- Copyright (c) 2012 Andrew Cantino
- Copyright (c) 2009 Andrew Cantino & Kyle Maxwell
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- */
-
-function SelectorGadget() {
- this.border_width = 5;
- this.border_padding = 2;
- this.b_top = null;
- this.b_left = null;
- this.b_right = null;
- this.b_bottom = null;
- this.selected = [];
- this.rejected = [];
- this.special_mode = null;
- this.path_output_field = null;
- this.sg_div = null;
- this.ignore_class = 'selectorgadget_ignore';
- this.unbound = false;
- this.prediction_helper = new DomPredictionHelper();
- this.restricted_elements = jQuerySG.map(['html', 'body', 'head', 'base'], function(selector) { return jQuerySG(selector).get(0) });
-}
-SelectorGadget.prototype = new Object();
-
-SelectorGadget.prototype.makeBorders = function(orig_elem, makeRed) {
- this.removeBorders();
- this.setupBorders();
-
- if (orig_elem.parentNode)
- var path_to_show = orig_elem.parentNode.tagName.toLowerCase() + ' ' + orig_elem.tagName.toLowerCase();
- else
- var path_to_show = orig_elem.tagName.toLowerCase();
-
- var elem = jQuerySG(orig_elem);
- var p = elem.offset();
-
- var top = p.top;
- var left = p.left;
- var width = elem.outerWidth()
- var height = elem.outerHeight()
-
- this.b_top.css('width', this.px(width + this.border_padding * 2 + this.border_width * 2)).
- css('top', this.px(top - this.border_width - this.border_padding)).
- css('left', this.px(left - this.border_padding - this.border_width));
- this.b_bottom.css('width', this.px(width + this.border_padding * 2 + this.border_width * 2 - 5)).
- css('top', this.px(top + height + this.border_padding)).
- css('left', this.px(left - this.border_padding - this.border_width)).text(path_to_show);
- this.b_left.css('height', this.px(height + this.border_padding * 2)).
- css('top', this.px(top - this.border_padding)).
- css('left', this.px(left - this.border_padding - this.border_width));
- this.b_right.css('height', this.px(height + this.border_padding * 2)).
- css('top', this.px(top - this.border_padding)).
- css('left', this.px(left + width + this.border_padding));
-
- this.b_right.get(0).target_elem = this.b_left.get(0).target_elem = this.b_top.get(0).target_elem = this.b_bottom.get(0).target_elem = orig_elem;
-
- if (makeRed || elem.hasClass("selectorgadget_suggested") || elem.hasClass("selectorgadget_selected")) {
- this.b_top.addClass('selectorgadget_border_red');
- this.b_bottom.addClass('selectorgadget_border_red');
- this.b_left.addClass('selectorgadget_border_red');
- this.b_right.addClass('selectorgadget_border_red');
- } else {
- if (this.b_top.hasClass('selectorgadget_border_red')) {
- this.b_top.removeClass('selectorgadget_border_red');
- this.b_bottom.removeClass('selectorgadget_border_red');
- this.b_left.removeClass('selectorgadget_border_red');
- this.b_right.removeClass('selectorgadget_border_red');
- }
- }
-
- this.showBorders();
-};
-
-SelectorGadget.prototype.px = function(p) {
- return p + 'px';
-};
-
-SelectorGadget.prototype.showBorders = function() {
- this.b_top.show();
- this.b_bottom.show();
- this.b_left.show();
- this.b_right.show();
-};
-
-SelectorGadget.prototype.removeBorders = function() {
- if (this.b_top) {
- this.b_top.hide();
- this.b_bottom.hide();
- this.b_left.hide();
- this.b_right.hide();
- }
-}
-
-SelectorGadget.prototype.setupBorders = function() {
- if (!this.b_top) {
- var width = this.border_width + 'px';
- this.b_top = jQuerySG('